|
@ -73,7 +73,7 @@ import re |
|
|
import sys |
|
|
import sys |
|
|
|
|
|
|
|
|
from patacrep import files |
|
|
from patacrep import files |
|
|
from patacrep.errors import SongbookError |
|
|
from patacrep.errors import SharedError |
|
|
|
|
|
|
|
|
LOGGER = logging.getLogger(__name__) |
|
|
LOGGER = logging.getLogger(__name__) |
|
|
EOL = '\n' |
|
|
EOL = '\n' |
|
@ -120,7 +120,7 @@ class ContentItem: |
|
|
"""Return the string to end a block.""" |
|
|
"""Return the string to end a block.""" |
|
|
return "" |
|
|
return "" |
|
|
|
|
|
|
|
|
class ContentError(SongbookError): |
|
|
class ContentError(SharedError): |
|
|
"""Error in a content plugin.""" |
|
|
"""Error in a content plugin.""" |
|
|
def __init__(self, keyword=None, message=None): |
|
|
def __init__(self, keyword=None, message=None): |
|
|
super(ContentError, self).__init__() |
|
|
super(ContentError, self).__init__() |
|
@ -140,13 +140,15 @@ class ContentList: |
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
def __init__(self, *args, **kwargs): |
|
|
self._content = list(*args, **kwargs) |
|
|
self._content = list(*args, **kwargs) |
|
|
self.errors = [] |
|
|
self._errors = [] |
|
|
|
|
|
|
|
|
def __iter__(self): |
|
|
def __iter__(self): |
|
|
yield from self._content |
|
|
yield from self._content |
|
|
|
|
|
|
|
|
def extend(self, iterator): |
|
|
def extend(self, iterator): |
|
|
return self._content.extend(iterator) |
|
|
self._content.extend(iterator) |
|
|
|
|
|
if isinstance(iterator, self.__class__): |
|
|
|
|
|
self._errors.extend(iterator._errors) |
|
|
|
|
|
|
|
|
def append(self, item): |
|
|
def append(self, item): |
|
|
return self._content.append(item) |
|
|
return self._content.append(item) |
|
@ -154,6 +156,23 @@ class ContentList: |
|
|
def __len__(self): |
|
|
def __len__(self): |
|
|
return len(self._content) |
|
|
return len(self._content) |
|
|
|
|
|
|
|
|
|
|
|
def append_error(self, error): |
|
|
|
|
|
LOGGER.warning(error) |
|
|
|
|
|
self._errors.append(error) |
|
|
|
|
|
|
|
|
|
|
|
def extend_error(self, errors): |
|
|
|
|
|
for error in errors: |
|
|
|
|
|
self.append_error(error) |
|
|
|
|
|
|
|
|
|
|
|
def iter_errors(self): |
|
|
|
|
|
yield from self._errors |
|
|
|
|
|
|
|
|
|
|
|
class EmptyContentList(ContentList): |
|
|
|
|
|
def __init__(self, *, errors): |
|
|
|
|
|
super().__init__() |
|
|
|
|
|
for error in errors: |
|
|
|
|
|
self.append_error(error) |
|
|
|
|
|
|
|
|
@jinja2.contextfunction |
|
|
@jinja2.contextfunction |
|
|
def render(context, content): |
|
|
def render(context, content): |
|
|
"""Render the content of the songbook as a LaTeX code. |
|
|
"""Render the content of the songbook as a LaTeX code. |
|
@ -209,11 +228,11 @@ def process_content(content, config=None): |
|
|
try: |
|
|
try: |
|
|
match = keyword_re.match(elem[0]).groupdict() |
|
|
match = keyword_re.match(elem[0]).groupdict() |
|
|
except AttributeError: |
|
|
except AttributeError: |
|
|
contentlist.errors.append(ContentError(elem[0], "Cannot parse content type.")) |
|
|
contentlist.append_error(ContentError(elem[0], "Cannot parse content type.")) |
|
|
continue |
|
|
continue |
|
|
(keyword, argument) = (match['keyword'], match['argument']) |
|
|
(keyword, argument) = (match['keyword'], match['argument']) |
|
|
if keyword not in plugins: |
|
|
if keyword not in plugins: |
|
|
contentlist.errors.append(ContentError(keyword, "Unknown content type.")) |
|
|
contentlist.append_error(ContentError(keyword, "Unknown content type.")) |
|
|
continue |
|
|
continue |
|
|
contentlist.extend(plugins[keyword]( |
|
|
contentlist.extend(plugins[keyword]( |
|
|
keyword, |
|
|
keyword, |
|
|