Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def listing_latex(meta, color, tab, space):
init()
src = Para(createListStr(u'Exercise #'))
pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
src = Para(createListStr(u'Exercise (test) #'))
pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
doc = [[{'unMeta': meta}], []]
pandoc_numbering.addListings(doc, 'latex', meta)
dest = [
Header(1, ['', ['unnumbered'], []], createListStr(u'Listings of exercises')),
RawBlock(
'tex',
''.join([
'\\hypersetup{linkcolor=' + color + '}',
'\\makeatletter',
'\\newcommand*\\l@exercise{\\@dottedtocline{1}{' + tab + 'em}{' + space + 'em}}',
'\\@starttoc{exercise}',
'\\makeatother'
])
)
]
assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
src = Para(createListStr(u'Exercise -.#'))
dest = Para([
Span(
[u'exercise:1.2', ['pandoc-numbering-text', 'exercise'], []],
[Strong(createListStr(u'Exercise 2'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
src = Header(1, [u'second-chapter', [], []], createListStr(u'Second chapter'))
pandoc_numbering.numbering(src['t'], src['c'], '', {})
src = Para(createListStr(u'Exercise -.#'))
dest = Para([
Span(
[u'exercise:2.1', ['pandoc-numbering-text', 'exercise'], []],
[Strong(createListStr(u'Exercise 1'))]
)
])
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
src = Para(createListStr(u'Exercise +.#'))
dest = Para([
Span(
[u'exercise:2.2', ['pandoc-numbering-text', 'exercise'], []],
def buttonize(key, value, format, meta):
if key == 'Link':
inlines, (href, title) = value
linktext = stringify(inlines).strip()
if (format == "html" or format == "html5") and linktext[-1] == ">":
html = "<a href="%s" title="%s" class="button">%s</a>" % (title, href, linktext[:-1])
newlink = RawInline("html", html)
return newlink
elif key == 'Header':
level, (identifier, classes, kv), inlines = value
identifier = identifier.replace("_","-")
return Header(level, (identifier, classes, kv), inlines)
def dec_header_1(key, value, format, _):
if key == 'Header':
[level, attr, inline] = value
if level > LEVELS:
level -= LEVELS
return Header(level, attr, inline)
def inc_header(key, value, format, _):
if key == 'Header':
[level, attr, inline] = value
if level+LEVELS <= MAX_LEVEL:
level += LEVELS
return Header(level, attr, inline)
def promote_and_capitalize_sections(key, value, format, meta):
if key == 'Header':
header_contents = value[2]
header_text = ' '.join([ x['c'] for x in header_contents if x['t'] == 'Str']).lower()
if header_text in ['name', 'synopsis', 'description', 'options', 'examples', 'environment variables']:
# capitalize
for element in header_contents:
if element['t'] == 'Str':
element['c'] = element['c'].upper()
# promote
value = Header(1, value[1], header_contents)
return value
return None
if len(classes) == 1 and classes[0] in SPECIAL_CLASSES:
panel_kind, glyphicon_kind = SPECIAL_CLASSES[classes[0]]
h_level, h_attr, h_inlines = blockquote[0]['c']
# insert an icon as the first sub-item of the header
span = pf.Span(["", ["glyphicon", glyphicon_kind], []], [])
h_inlines.insert(0, span)
# only the header goes into panel-heading
# WARNING: pandoc doesn't preserve header attributes when the
# header is nested under blockquote. This makes it
# impossible to alter header's "class" attribute, for
# example.
header = pf.Header(h_level, h_attr, h_inlines)
panel_header = pf.Div(("", ["panel-heading"], []), [header])
# the rest of the blockquote goes into panel-body
panel_body = pf.Div(("", ["panel-body"], []), blockquote[1:])
# apply Bootstrap panel classes to the div
classes.append("panel")
classes.append(panel_kind)
# a blockquote is just a list of blocks, so it can be
# passed directly to Div, which expects Div(attr, blocks)
return pf.Div((id, classes, kvs), [panel_header, panel_body])
if len(classes) == 1 and classes[0] in SPECIAL_CLASSES:
panel_kind, glyphicon_kind = SPECIAL_CLASSES[classes[0]]
h_level, h_attr, h_inlines = blockquote[0]['c']
# insert an icon as the first sub-item of the header
span = pf.Span(["", ["glyphicon", glyphicon_kind], []], [])
h_inlines.insert(0, span)
# only the header goes into panel-heading
# WARNING: pandoc doesn't preserve header attributes when the
# header is nested under blockquote. This makes it
# impossible to alter header's "class" attribute, for
# example.
header = pf.Header(h_level, h_attr, h_inlines)
panel_header = pf.Div(("", ["panel-heading"], []), [header])
# the rest of the blockquote goes into panel-body
panel_body = pf.Div(("", ["panel-body"], []), blockquote[1:])
# apply Bootstrap panel classes to the div
classes.append("panel")
classes.append(panel_kind)
# a blockquote is just a list of blocks, so it can be
# passed directly to Div, which expects Div(attr, blocks)
return pf.Div((id, classes, kvs), [panel_header, panel_body])
def dec_header(key, value, format, _):
if key == 'Header':
[level, attr, inline] = value
if level > LEVELS:
level -= LEVELS
return Header(level, attr, inline)