【问题标题】:not getting expected result from python markdown [closed]没有从 python markdown 得到预期的结果[关闭]
【发布时间】:2013-06-22 19:51:58
【问题描述】:

问题可能在于我对应该发生的事情的理解。这是我所做的:

>>> import markdown2
>>> rawtext = "Getting the Gist of Markdown's Formatting Syntax ------------------------------------------------ This page offers a brief "
>>> html = markdown2.markdown(rawtext)
>>> html
u"<p>Getting the Gist of Markdown's Formatting Syntax ------------------------------------------------ This page offers a brief </p>\n"

我尝试使用 markdown 而不是 markdown2,但得到了相同的结果。我原以为许多“-”会导致“Getting the Gist of Markdown's Formatting Syntax”呈现为 H1。我错过了什么?

【问题讨论】:

    标签: python markdown


    【解决方案1】:

    插入一些换行符:

    rawtext = "Getting the Gist of Markdown's Formatting Syntax\n------------------------------------------------\nThis page offers a brief "
    

    如果破折号和文本在单独的行上,Markdown 只会将破折号之前的文本变成&lt;h1&gt;。 (否则Wow - I never knew that 会将Wow 变成&lt;h1&gt;。)

    【讨论】:

      【解决方案2】:

      只有当破折号在自己的行在文本下方时,它才会呈现为&lt;h1&gt;:

      >>> import markdown2
      >>> rawtext = "Getting the Gist of Markdown's Formatting Syntax\n------------------------------------------------\nThis page offers a brief "
      >>> markdown2.markdown(rawtext)
      u"<h2>Getting the Gist of Markdown's Formatting Syntax</h2>\n\n<p>This page offers a brief </p>\n"
      

      【讨论】:

      • 我很傻,你是对的。谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-13
      相关资源
      最近更新 更多