Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added {.hl} to the list of ssupported classes #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion data/filters/wg21.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def init_code_elems(elem, doc):

# Mark code elements within colored divspan as default.
if any(isinstance(elem, cls) for cls in [pf.Div, pf.Span]) and \
any(cls in elem.classes for cls in ['add', 'rm', 'ednote']):
any(cls in elem.classes for cls in ['add', 'rm', 'ednote', 'hl']):
elem.walk(lambda elem, doc:
elem.classes.insert(0, 'default')
if any(isinstance(elem, cls) for cls in [pf.Code, pf.CodeBlock])
Expand Down Expand Up @@ -187,19 +187,22 @@ def repl(match_obj):

uc = command.format('NormalTok', doc.get_metadata('uccolor'))
add = command.format('VariableTok', doc.get_metadata('addcolor'))
hl = command.format('VariableTok', doc.get_metadata('hlcolor'))
rm = command.format('StringTok', doc.get_metadata('rmcolor'))

if isinstance(elem, pf.Code):
return pf.Span(
pf.RawInline(uc, 'latex'),
pf.RawInline(add, 'latex'),
pf.RawInline(hl, 'latex'),
pf.RawInline(rm, 'latex'),
result)
elif isinstance(elem, pf.CodeBlock):
return pf.Div(
pf.RawBlock('{', 'latex'),
pf.RawBlock(uc, 'latex'),
pf.RawBlock(add, 'latex'),
pf.RawBlock(hl, 'latex'),
pf.RawBlock(rm, 'latex'),
result,
pf.RawBlock('}', 'latex'))
Expand Down Expand Up @@ -276,6 +279,11 @@ def _color(html_color):
pf.RawInline('}', 'latex'))
elem.attributes['style'] = 'color: #{}'.format(html_color)

def _bgcolor(html_color):
_wrap(pf.RawInline('\\hl{\\mbox{', 'latex'),
pf.RawInline('}}', 'latex'))
elem.attributes['style'] = 'background-color: #{}'.format(html_color)

def _nonnormative(name):
_wrap(pf.Span(pf.Str('[ '), pf.Emph(pf.Str('{}:'.format(name.title()))), pf.Space),
pf.Span(pf.Str(' — '), pf.Emph(pf.Str('end {}'.format(name.lower()))), pf.Str(' ]')))
Expand Down Expand Up @@ -336,6 +344,9 @@ def rm(): _diff('rmcolor', 'sout', 'del')
pf.debug('mpark/wg21: stable name', target, 'not found')
return link

if 'hl' in elem.classes and isinstance(elem, pf.Span):
_bgcolor('')

note_cls = next(iter(cls for cls in elem.classes if cls in {'example', 'note', 'ednote'}), None)
if note_cls == 'example': example()
elif note_cls == 'note': note()
Expand Down
1 change: 1 addition & 0 deletions data/templates/wg21.latex
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ $if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$
\usepackage{xcolor}
\usepackage{soul}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
Expand Down