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.

47 lines
1.2 KiB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Allow 'songchapter' and 'songsection' as content of a songbook."""
from songbook_core.content import Content, ContentError
KEYWORDS = [
"songchapter",
"songsection",
]
class SongSection(Content):
"""A songsection or songchapter."""
def __init__(self, keyword, name):
self.keyword = keyword
self.name = name
def render(self, __context):
"""Render this section or chapter."""
return r'\{}{{{}}}'.format(self.keyword, self.name)
#pylint: disable=unused-argument
def parse(keyword, argument, contentlist, config):
"""Parse the contentlist.
Arguments:
- keyword ("songsection" or "songchapter"): the section to use;
- argument: unused;
- contentlist: a list of one string, which is the name of the section;
- config: configuration dictionary of the current songbook.
"""
if (keyword not in KEYWORDS) and (len(contentlist) != 1):
raise ContentError(
keyword,
"Starred section names must have exactly one argument.",
)
return [SongSection(keyword, contentlist[0])]
CONTENT_PLUGINS = dict([
(word, parse)
for word
in KEYWORDS
])