在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):miyuchina/mistletoe开源软件地址(OpenSource Url):https://github.com/miyuchina/mistletoe开源编程语言(OpenSource Language):Python 98.9%开源软件介绍(OpenSource Introduction):mistletoemistletoe is a Markdown parser in pure Python, designed to be fast, spec-compliant and fully customizable. Apart from being the fastest CommonMark-compliant Markdown parser implementation in pure Python, mistletoe also supports easy definitions of custom tokens. Parsing Markdown into an abstract syntax tree also allows us to swap out renderers for different output formats, without touching any of the core components. Remember to spell mistletoe in lowercase! Features
Output formatsRenderers for the following "core" output formats exist within the mistletoe module itself:
Renderers for the following output formats are placed in the contrib folder:
Installationmistletoe is tested for Python 3.5 and above. Install mistletoe with pip: pip3 install mistletoe Alternatively, clone the repo: git clone https://github.com/miyuchina/mistletoe.git
cd mistletoe
pip3 install -e . This installs mistletoe in "editable" mode (because of the See the contributing doc for how to contribute to mistletoe. UsageUsage from PythonHere's how you can use mistletoe in a Python script: import mistletoe
with open('foo.md', 'r') as fin:
rendered = mistletoe.markdown(fin)
import mistletoe
from mistletoe.latex_renderer import LaTeXRenderer
with open('foo.md', 'r') as fin:
rendered = mistletoe.markdown(fin, LaTeXRenderer) Finally, here's how you would manually specify extra tokens via a renderer.
In the following example, we use from mistletoe import Document, HTMLRenderer
with open('foo.md', 'r') as fin:
with HTMLRenderer() as renderer: # or: `with HTMLRenderer(AnotherToken1, AnotherToken2) as renderer:`
doc = Document(fin) # parse the lines into AST
rendered = renderer.render(doc) # render the AST
# internal lists of tokens to be parsed are automatically reset when exiting this `with` block Important: As can be seen from the example above,
the parsing phase is currently tightly connected with initiation
and closing of a renderer. Therefore, you should never call Usage from command-linepip installation enables mistletoe's command-line utility. Type the following directly into your shell: mistletoe foo.md This will transpile mistletoe foo.md > out.html You can use a different renderer by including the full path to the renderer
class after a mistletoe foo.md --renderer mistletoe.latex_renderer.LaTeXRenderer Note: The renderers inside the mistletoe interactive modeRunning mistletoe [version 0.7.2] (interactive)
Type Ctrl-D to complete input, or Ctrl-C to exit.
>>> some **bold** text
... and some *italics*
...
<p>some <strong>bold</strong> text
and some <em>italics</em></p>
>>> The interactive mode also accepts the mistletoe [version 0.7.2] (interactive)
Type Ctrl-D to complete input, or Ctrl-C to exit.
Using renderer: LaTeXRenderer
>>> some **bold** text
... and some *italics*
...
\documentclass{article}
\begin{document}
some \textbf{bold} text
and some \textit{italics}
\end{document}
>>> Who uses mistletoe?mistletoe is used by projects of various target audience. You can find some concrete projects in the "Used by" section on Libraries.io, but this is definitely not a complete list. Also a list of Dependents is tracked by GitHub directly. Run mistletoe from CopyQOne notable example is running mistletoe as a Markdown converter from the advanced clipboard manager called CopyQ. One just needs to install the Convert Markdown to ... custom script command and then run this command on any selected Markdown text. Why mistletoe?"For fun," says David Beazley. Further readingCopyright & License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论