Skip to content

Commit

Permalink
Dealing with div that have not classes
Browse files Browse the repository at this point in the history
  • Loading branch information
chdemko committed Apr 23, 2016
1 parent 7a3d73f commit 0e531d1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pandoc_latex_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
75 changes: 75 additions & 0 deletions tests/test_div.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0e531d1

Please sign in to comment.