在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jgm/cheapskate开源软件地址(OpenSource Url):https://github.com/jgm/cheapskate开源编程语言(OpenSource Language):HTML 50.9%开源软件介绍(OpenSource Introduction):CheapskateNote: This library is unmaintained (by me anyway). I recommend using commonmark. This is an experimental Markdown processor in pure Haskell. (A cheapskate is
always in search of the best markdown.) It aims to process Markdown efficiently
and in the most forgiving possible way. It is about seven times faster than
There is no such thing as an invalid Markdown document. Any string of
characters is valid Markdown. So the processor should finish efficiently no
matter what input it gets. Garbage in should not cause an error or exponential
slowdowns. This processor has been tested on many large inputs consisting of
random strings of characters, with performance that is consistently linear with
the input size. (Try InstallingTo build, get the Haskell Platform, then:
This will install both the UsageAs an executable:
As a library: import Cheapskate
import Text.Blaze.Html
toMarkdown :: Text -> Html
toMarkdown = toHtml . markdown def If the markdown input you are converting comes from an untrusted source
(e.g. a web form), you should always set You may also wish to disallow users from entering raw HTML for aesthetic,
rather than security reasons. In that case, set Manipulating the parsed documentYou can manipulate the parsed document before rendering using the import Data.Text as T
import Data.Text.Lazy as TL
import Cheapskate
import Text.Blaze.Html
import Text.Blaze.Html.Renderer.Text
import Text.Highlighting.Kate
markdownWithHighlighting :: Text -> Html
markdownWithHighlighting = toHtml . walk addHighlighting . markdown def
addHighlighting :: Block -> Block
addHighlighting (CodeBlock (CodeAttr lang _) t) =
HtmlBlock (T.concat $ TL.toChunks
$ renderHtml $ toHtml
$ formatHtmlBlock defaultFormatOpts
$ highlightAs (T.unpack lang) (T.unpack t))
addHighlighting x = x ExtensionsThis processor adds the following Markdown extensions: Hyperlinked URLsAll absolute URLs are automatically made into hyperlinks, where
inside Fenced code blocksFenced code blocks with attributes are allowed. These begin with a line of three or more backticks or tildes, followed by an optional language name and possibly other metadata. They end with a line of backticks or tildes (the same character as started the code block) of at least the length of the starting line. Explicit hard line breaksA hard line break can be indicated with a backslash before a newline. The standard method of two spaces before a newline also works, but this gives a more "visible" alternative. Backslash escapesAll ASCII symbols and punctuation marks can be backslash-escaped, not just those with a use in Markdown. RevisionsIn departs from the markdown syntax document in the following ways: Intraword emphasisUnderscores cannot be used for word-internal emphasis. This prevents common mistakes with filenames, usernames, and indentifiers. Asterisks can still be used if word internal emphasis is needed. The exact rule is this: an underscore that appears directly after an alphanumeric character does not begin an emphasized span. (However, an underscore directly before an alphanumeric can end an emphasized span.) Ordered listsThe starting number of an ordered list is now significant.
Other numbers are ignored, so you can still use In addition to the
Bullet listsA new bullet lists starts if you change the bullet marker. So, the following is two consecutive bullet lists:
List separationTwo blank lines breaks out of a list. This allows you to have consecutive lists:
The blank lines break out of a list no matter how deeply it is nested:
Indentation of list continuationsBlock elements inside list items need not be indented four spaces. If they are indented beyond the bullet or numerical list marker, they will be considered additional blocks inside the list item. So, the following is a list item with two paragraphs:
The amount of indentation required for an indented code block inside a list item depends on the first line of the list item. Generally speaking, code must be indented four spaces past the first non-space character after the list marker. Thus:
The following diagram shows how the first line of a list item divides the following lines into three regions:
Content to the left of the marked region will not be part of the list item. Content to the right of the marked region will be indented code under the list item. Regular blocks that belong under the list item should start inside the marked region. When the first line itself contains indented code, this code and subsequent indented code blocks should be indented five spaces past the list marker:
Raw HTML blocksRaw HTML blocks work a bit differently than in
while in the following, the asterisks are interpreted as markdown emphasis:
In the first example, we have a single raw HTML block; in the second, we have two raw HTML blocks with an intervening paragraph. This system provides flexibility to authors to use enclose markdown sections in html block-level tags if they wish, while also allowing them to include verbatim HTML blocks (taking care that the don't include any blank lines). As a consequence of this rule, HTML blocks may not contain blank lines. ClarificationsThis implementation resolves the following issues left vague in the markdown syntax document: Tight vs. loose listsA list is considered "tight" if (a) it has only one item or
there is no blank space between any two consecutive items, and
(b) no item has blank lines as its immediate children.
If a list is "tight," then list items consisting of a single
paragraph or a paragraph followed by a sublist will be rendered
without SublistsSublists work like other block elements inside list items; they must be indented past the bullet or numerical list marker (but no more than three spaces past, or they will be interpreted as indented code). ATX headersATX headers must have a space after the initial Separation of block quotesA blank line will end a blockquote. So, the following is a single blockquote:
But this is two blockquotes:
Blank lines are not required before horizontal rules, blockquotes, lists, code blocks, or headers. They are not required after, either, though in many cases "laziness" will effectively require a blank line after. For example, in
the "Still a quote." is part of the block quote, because of laziness (the ability to leave off the > from the beginning of subsequent lines). Laziness also affects lists. However, we can have a code block, ATX header, or horizontal rule between two paragraphs without any blank lines. Link referencesLink references may occur anywhere in the document, even in nested list contexts. They need not be at the outer level. TestsThe To run the test suite, do
To run only tests that match a regex pattern, do
Setting the environment variable
BenchmarksTo run a crude benchmark comparing LicenseCopyright © 2012, 2013, 2014 John MacFarlane. The library is released under the BSD license; see LICENSE for terms. Some of the test cases are borrowed from Michel Fortin's mdtest suite and John Gruber's original markdown test suite. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论