Skip to content

Commit

Permalink
Implemented embedded Markdown for inline code.
Browse files Browse the repository at this point in the history
This is not committed due to jgm/pandoc#5574.
  • Loading branch information
mpark committed Jun 13, 2019
1 parent dcdcc8a commit 274dba9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions data/filter/wg21.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def build_row(elems):
return pf.Table(*rows, **kwargs)

def codeblock(elem, doc):
if not isinstance(elem, pf.CodeBlock):
if not isinstance(elem, pf.Code) and not isinstance(elem, pf.CodeBlock):
return None

if not elem.classes:
Expand All @@ -271,7 +271,7 @@ def codeblock(elem, doc):
syntaxdir = os.path.join(datadir, 'syntax')

text = pf.convert_text(
elem,
pf.Plain(elem) if isinstance(elem, pf.Code) else elem,
input_format='panflute',
output_format=doc.format,
extra_args=[
Expand All @@ -289,25 +289,33 @@ def repl(match_obj):
# Undo `escapeLaTeX` from https://github.com/jgm/skylighting
match = match.replace('\\textbackslash{}', '\\') \
.replace('\\{', '{') \
.replace('\\}', '}')
.replace('\\}', '}') \
.replace('\\VerbBar{}', '|')

plain = pf.Plain(*pf.convert_text(match)[0].content)
return pf.convert_text(
plain.walk(divspan, doc),
input_format='panflute',
output_format=doc.format)

result = pf.RawBlock(escape_span.sub(repl, text), doc.format)
if isinstance(elem, pf.Code):
result = pf.RawInline(escape_span.sub(repl, text), doc.format)
elif isinstance(elem, pf.CodeBlock):
result = pf.RawBlock(escape_span.sub(repl, text), doc.format)

if 'diff' not in elem.classes:
return result

# For HTML, this is handled via CSS in `data/template/wg21.html`.
command = '\\renewcommand{{\\{}}}[1]{{\\textcolor[HTML]{{{}}}{{#1}}}}'
return pf.Div(
pf.RawBlock(command.format('VariableTok', doc.get_metadata('addcolor')), 'latex'),
pf.RawBlock(command.format('StringTok', doc.get_metadata('rmcolor')), 'latex'),
result)

add = command.format('VariableTok', doc.get_metadata('addcolor'))
rm = command.format('StringTok', doc.get_metadata('rmcolor'))

if isinstance(elem, pf.Code):
return pf.Span(pf.RawInline(add, 'latex'), pf.RawInline(rm, 'latex'), result)
elif isinstance(elem, pf.CodeBlock):
return pf.Div(pf.RawBlock(add, 'latex'), pf.RawBlock(rm, 'latex'), result)

def bibliography(elem, doc):
if not isinstance(elem, pf.Div) or elem.identifier != 'bibliography':
Expand Down

0 comments on commit 274dba9

Please sign in to comment.