本文整理匯總了Python中CommonMark.Parser方法的典型用法代碼示例。如果您正苦於以下問題:Python CommonMark.Parser方法的具體用法?Python CommonMark.Parser怎麽用?Python CommonMark.Parser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CommonMark
的用法示例。
在下文中一共展示了CommonMark.Parser方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_headings
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def test_headings(self):
case = """
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
##### Heading 6
"""
parser = Parser()
ast = parser.parse(case)
lr = LatexRenderer()
latex = lr.render(ast)
self.assertEquals(latex.count('\huge'), 2)
self.assertEquals(latex.count('\LARGE'), 1)
self.assertEquals(latex.count('\Large'), 1)
self.assertEquals(latex.count('\large'), 2)
示例2: render_commonmark_template
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def render_commonmark_template(template, context):
# Render a CommonMark template to HTML.
# Replace template tags with Unicode sentinels so that
# the template tags do not impact CommonMark rendering.
substitutions = []
import re
def replace(m):
# Record the substitution.
index = len(substitutions)
substitutions.append(m.group(0))
return "\uE000%d\uE001" % index # use Unicode private use area code points
template = re.sub("{%.*?%}|{{.*?}}", replace, template)
# Render the CommonMark.
# Prevent CommonMark from mucking with our sentinels
# in URLs though - it would otherwise add escaping.
from CommonMark import inlines
def urlencode_special(uri):
import urllib.parse
return "".join(
urllib.parse.quote(c, safe="/@:+?=&()%#*,") # this is what CommonMark does
if c not in "\uE000\uE001" else c # but keep our special codes
for c in uri)
inlines.normalize_uri = urlencode_special
# Render.
import CommonMark
template = CommonMark.HtmlRenderer().render(CommonMark.Parser().parse(template))
# Put the template tags back that we removed prior to running
# the CommonMark renderer.
def replace(m):
return substitutions[int(m.group(1))]
template = re.sub("\uE000(\d+)\uE001", replace, template)
# And finally render the Django template.
return Template(template).render(Context(context))
示例3: parse_changelog
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def parse_changelog():
with open('CHANGELOG.md', 'r') as fp:
parser = CommonMark.Parser()
ast = parser.parse(fp.read())
return ast_to_changelog(ast)
示例4: __init__
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def __init__(self):
self.path = os.path.join(settings.BASE_DIR, 'NEWS.md')
self.parser = CommonMark.Parser()
self.renderer = CommonMark.HtmlRenderer()
self.cookie_name = 'news_current'
示例5: _render
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def _render(self, text):
'''Render CommonMark with ettings taken in account'''
parser = CommonMark.Parser()
ast = parser.parse(text)
renderer = HtmlRenderer(self)
html = renderer.render(ast)
return html
示例6: latex_markdown
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def latex_markdown(value):
"""Turns markdown into LaTeX and returns it
"""
if not has_markdown:
raise ImproperlyConfigured('CommonMark needs to be installed')
parser = Parser()
ast = parser.parse(value)
lr = LatexRenderer()
latex = lr.render(ast)
return mark_safe(latex)
示例7: test_escape
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def test_escape(self):
case = """
\\begin{parahrah}
\\textt{NO}
\\end{paragraph}
"""
parser = Parser()
ast = parser.parse(case)
lr = LatexRenderer()
latex = lr.render(ast)
self.assertEquals(latex, (
'\\textbackslash{}begin\{parahrah\}\\textbackslash'
'{}textt\{NO\}\\textbackslash{}end\{paragraph\}\n\n'
))
示例8: test_inline_formatting
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def test_inline_formatting(self):
case = """
The **quick** brown _fox_ jumped over the __lazy__ cow.
"""
parser = Parser()
ast = parser.parse(case)
lr = LatexRenderer()
latex = lr.render(ast)
self.assertEquals(latex, (
'The \\textbf{quick} brown \\emph{fox} jumped over'
' the \\textbf{lazy} cow.\n\n'
))
示例9: test_paragraphs
# 需要導入模塊: import CommonMark [as 別名]
# 或者: from CommonMark import Parser [as 別名]
def test_paragraphs(self):
case = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nullam augue felis, eleifend at quam id, molestie placerat felis.
Nunc laoreet sapien tellus, ac blandit arcu lobortis eu. Etiam sit amet ex commodo, condimentum felis quis, suscipit nunc. Duis eu egestas diam, sed placerat arcu. Aliquam vestibulum consectetur ipsum a ullamcorper. Integer pretium eros a nisl cursus tristique. Cras in molestie nisi, nec dictum
nunc. Phasellus ultrices euismod tortor, vel molestie mi cursus
eu. Integer blandit et urna vel molestie. Pellentesque et est
et arcu tincidunt maximus.
Morbi dignissim, risus ac ornare accumsan, ex magna accumsam
diam, ac interdum nisl enim nec justo. Donec efficitur, tortor
non ornare sagittis, sapien tellus rutrum neque, quis lobortis sapien
urna vitae magna. Pellentesque dictum magna eu urna commodo,
a vulputate massa fringilla. Sed egestas sodales libero, sed blandit
dui gravida sit amet. Mauris egestas consectetur leo in tincidunt.
Vivamus bibendum sodales risus. Maecenas bibendum justo non auctor
ullamcorper. Sed felis ipsum,
viverra non justo id, congue fringilla neque. Proin a facilisis lectus.
Suspendisse potenti. Proin vitae diam sem. Nam accumsan nisi vel
diam accumsan, at porta dui tempus. In in nunc pellentesque ligula
porta iaculis. Aenean ultricies ante ex, nec fringilla felis
sollicitudin non. Ut diam est, varius a mi id, commodo tincidunt dui.
Donec et ante consequat, consequat elit vitae, rutrum justo. Ut mattis
ex porta nibh porta mattis. Suspendisse sit amet est turpis. Donec a
fermentum diam, semper dapibus ipsum. Duis volutpat libero et quam
rutrum porta.
Nulla nec suscipit nunc. Duis ut ligula ac neque condimentum commodo.
Donec eu ullamcorper felis. Ut rhoncus lectus vel sapien blandit varius.
Ut aliquet odio ligula, sit amet viverra augue interdum nec. Donec
sodales, turpis sed suscipit euismod, ex erat venenatis neque, ut
dictum ipsum ante ac urna. Vestibulum at magna id lacus luctus
fermentum. Pellentesque nisi purus, tempus eu faucibus sed, fringilla
sit amet justo. In laoreet, nisl sed posuere vulputate, lorem augue
placerat ipsum, at facilisis quam odio ut est. Proin eget enim dui.
Morbi id feugiat mauris, in faucibus odio. Nam quis venenatis quam.
Fusce leo velit, ullamcorper in leo vestibulum, ultricies pulvinar
neque. Suspendisse semper eros sit amet diam bibendum fringilla.
Vestibulum consectetur venenatis erat a faucibus. Integer tristique
eleifend mauris.
"""
parser = Parser()
ast = parser.parse(case)
lr = LatexRenderer()
latex = lr.render(ast)
self.assertEquals(latex.count('\n\n'), 4)