diff --git a/liara/nodes.py b/liara/nodes.py index 1611137..b5a4d1d 100644 --- a/liara/nodes.py +++ b/liara/nodes.py @@ -421,7 +421,6 @@ class MarkdownDocumentNode(DocumentNode): def __init__(self, configuration, **kwargs): super().__init__(**kwargs) self.__md = self._create_markdown_processor(configuration) - self.__mdext = None def _create_markdown_processor(self, configuration): from markdown import Markdown @@ -445,7 +444,6 @@ def process(self, cache: Cache, **kwargs): from .md import ShortcodeException if '$data' in kwargs: - assert self.__mdext self.__mdext.set_data(kwargs['$data']) byte_content = self._raw_content.encode('utf-8') diff --git a/test/test_shortcode.py b/test/test_shortcode.py new file mode 100644 index 0000000..11935bb --- /dev/null +++ b/test/test_shortcode.py @@ -0,0 +1,44 @@ +from liara import cmdline +from liara.signals import register_markdown_shortcodes +import liara +from click.testing import CliRunner + +_TEST_DATA = {} + + +def test_shortcode_with_data(tmp_path): + global _TEST_DATA + runner = CliRunner() + with runner.isolated_filesystem(temp_dir=tmp_path): + result = runner.invoke(cmdline.cli, ['quickstart']) + assert result.exit_code == 0 + + # Add a data file to content + data = { + 'root': 'some data' + } + + open('content/_index.md', 'w').write(""" +--- +title: Hello world +--- + +Invoke a shortcode: <% test /%>""") + + liara.yaml.dump_yaml(data, open('content/_data.yaml', 'w')) + + register_markdown_shortcodes.connect(_register_test_shortcode) + + s = liara.Liara() + s.build() + + assert _TEST_DATA['root'] == 'some data' + + +def _test_shortcode(**kwargs): + global _TEST_DATA + _TEST_DATA = kwargs['$data'] + + +def _register_test_shortcode(sender, preprocessor): + preprocessor.register('test', _test_shortcode)