From 0e531d1b87fe77878cdf04ba2a31dee2342f43aa Mon Sep 17 00:00:00 2001 From: Christophe Demko Date: Sat, 23 Apr 2016 14:58:41 +0200 Subject: [PATCH] Dealing with div that have not classes --- pandoc_latex_environment.py | 4 +- setup.py | 2 +- tests/test_div.py | 75 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/pandoc_latex_environment.py b/pandoc_latex_environment.py index e42d797..75e0145 100644 --- a/pandoc_latex_environment.py +++ b/pandoc_latex_environment.py @@ -10,7 +10,7 @@ def environment(key, value, format, meta): # Is it a div and the right format? - if key == 'Div':# and format == 'latex': + if key == 'Div' and format == 'latex': # Get the attributes [[id, classes, properties], content] = value @@ -19,7 +19,7 @@ def environment(key, value, format, meta): for environment, definedClasses in getDefined(meta).items(): # Is the classes correct? - if currentClasses <= definedClasses: + if currentClasses <= definedClasses and bool(currentClasses): value[1] = [RawBlock('tex', '\\begin{' + environment + '}')] + content + [RawBlock('tex', '\\end{' + environment + '}')] break diff --git a/setup.py b/setup.py index 093182f..c3a4bfb 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='0.0.2', + version='0.0.3', # The project's description description='A pandoc filter for adding LaTeX environement on specific div', diff --git a/tests/test_div.py b/tests/test_div.py index 548a088..5e257e0 100644 --- a/tests/test_div.py +++ b/tests/test_div.py @@ -105,3 +105,78 @@ def test_div(): assert json.loads(json.dumps(src)) == dest +def test_empty(): + init() + + meta = { + 'latex-environment': { + 'c': { + 'test': { + 'c': [ + { + 'c': [ + { + 'c': 'class1', + 't': 'Str' + } + ], + 't': 'MetaInlines' + }, + { + 'c': [ + { + 'c': 'class2', + 't': 'Str' + } + ], + 't': 'MetaInlines' + } + ], + 't': 'MetaList' + } + }, + 't': 'MetaMap' + } + } + + src = json.loads(json.dumps(Div( + [ + '', + [], + [] + ], + [ + { + 'c': [ + { + 'c': 'content', + 't': 'Str' + } + ], + 't': 'Plain' + } + ] + ))) + dest = json.loads(json.dumps(Div( + [ + '', + [], + [] + ], + [ + { + 'c': [ + { + 'c': 'content', + 't': 'Str' + } + ], + 't': 'Plain' + } + ] + ))) + + pandoc_latex_environment.environment(src['t'], src['c'], 'latex', meta) + + assert json.loads(json.dumps(src)) == dest +