Engine for LaTeX songbooks http://www.patacrep.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
1.1 KiB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from songbook_core.content import Content
KEYWORDS = [
"part",
"chapter",
"section",
"subsection",
"subsubsection",
"paragraph",
"subparagraph",
]
FULL_KEYWORDS = KEYWORDS + [ "{}*".format(keyword) for keyword in KEYWORDS]
class Section(Content):
def __init__(self, keyword, name, short = None):
self.keyword = keyword
self.name = name
self.short = short
def render(self):
if (short is None):
return r'\{}{{{}}}'.format(self.keyword, self.name)
else:
return r'\{}[{}]{{{}}}'.format(self.keyword, self.short, self.name)
def parse(keyword, arguments):
if (keyword not in KEYWORDS) and (len(arguments) != 1):
raise ContentError(keyword, "Starred section names must have exactly one argument.")
if (len(arguments) not in [1, 2]):
raise ContentError(keyword, "Section can have one or two arguments.")
return [Section(keyword, *arguments)]
CONTENT_PLUGINS = dict([(keyword, parse) for keyword in FULL_KEYWORDS])