当前位置: 首页>>代码示例>>Python>>正文


Python CommonMark.Parser方法代码示例

本文整理汇总了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) 
开发者ID:mypebble,项目名称:rest-framework-latex,代码行数:25,代码来源:test_markdown.py

示例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)) 
开发者ID:govtrack,项目名称:phonecongress.com,代码行数:41,代码来源:actions.py

示例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) 
开发者ID:kylef,项目名称:maintain,代码行数:7,代码来源:changelog.py

示例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' 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:7,代码来源:views.py

示例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 
开发者ID:noirbizarre,项目名称:pelican-frontmark,代码行数:9,代码来源:reader.py

示例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) 
开发者ID:mypebble,项目名称:rest-framework-latex,代码行数:12,代码来源:rest_framework_latex.py

示例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'
        )) 
开发者ID:mypebble,项目名称:rest-framework-latex,代码行数:16,代码来源:test_markdown.py

示例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'
        )) 
开发者ID:mypebble,项目名称:rest-framework-latex,代码行数:14,代码来源:test_markdown.py

示例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) 
开发者ID:mypebble,项目名称:rest-framework-latex,代码行数:49,代码来源:test_markdown.py


注:本文中的CommonMark.Parser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。