Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. # mdast-util-to-markdown
  2. [![Build][build-badge]][build]
  3. [![Coverage][coverage-badge]][coverage]
  4. [![Downloads][downloads-badge]][downloads]
  5. [![Size][size-badge]][size]
  6. [![Sponsors][sponsors-badge]][collective]
  7. [![Backers][backers-badge]][collective]
  8. [![Chat][chat-badge]][chat]
  9. **[mdast][]** utility to parse markdown.
  10. ## Install
  11. [npm][]:
  12. ```sh
  13. npm install mdast-util-to-markdown
  14. ```
  15. ## Use
  16. Say we have the following script, `example.js`:
  17. ```js
  18. var toMarkdown = require('mdast-util-to-markdown')
  19. var tree = {
  20. type: 'root',
  21. children: [
  22. {
  23. type: 'blockquote',
  24. children: [
  25. {type: 'thematicBreak'},
  26. {
  27. type: 'paragraph',
  28. children: [
  29. {type: 'text', value: '- a\nb !'},
  30. {
  31. type: 'link',
  32. url: 'example.com',
  33. children: [{type: 'text', value: 'd'}]
  34. }
  35. ]
  36. }
  37. ]
  38. }
  39. ]
  40. }
  41. console.log(toMarkdown(tree))
  42. ```
  43. Now, running `node example` yields (note the properly escaped characters which
  44. would otherwise turn into a list and image respectively):
  45. ```markdown
  46. > ***
  47. >
  48. > \- a
  49. > b \![d](example.com)
  50. ```
  51. ## API
  52. ### `toMarkdown(tree[, options])`
  53. Serialize **[mdast][]** to markdown.
  54. ##### Formatting options
  55. ###### `options.bullet`
  56. Marker to use to for bullets of items in unordered lists (`'*'`, `'+'`, or `'-'`,
  57. default: `'*'`).
  58. ###### `options.closeAtx`
  59. Whether to add the same number of number signs (`#`) at the end of an ATX
  60. heading as the opening sequence (`boolean`, default: `false`).
  61. ###### `options.emphasis`
  62. Marker to use to serialize emphasis (`'*'` or `'_'`, default: `'*'`).
  63. ###### `options.fence`
  64. Marker to use to serialize fenced code (``'`'`` or `'~'`, default: ``'`'``).
  65. ###### `options.fences`
  66. Whether to use fenced code always (`boolean`, default: `false`).
  67. The default is to fenced code if there is a language defined, if the code is
  68. empty, or if it starts or ends in empty lines.
  69. ###### `options.incrementListMarker`
  70. Whether to increment the value of bullets of items in ordered lists (`boolean`,
  71. default: `true`).
  72. ###### `options.listItemIndent`
  73. Whether to indent the content of list items with the size of the bullet plus one
  74. space (when `'one'`) or a tab stop (`'tab'`), or depending on the item and its
  75. parent list (`'mixed'`, uses `'one'` if the item and list are tight and `'tab'`
  76. otherwise) (`'one'`, `'tab'`, or `'mixed'`, default: `'tab'`).
  77. ###### `options.quote`
  78. Marker to use to serialize titles (`'"'` or `"'"`, default: `'"'`).
  79. ###### `options.resourceLink`
  80. Whether to use reference links always (`boolean`, default: `false`).
  81. The default is to use autolinks (`<https://example.com>`) when possible.
  82. ###### `options.rule`
  83. Marker to use for thematic breaks (`'*'`, `'-'`, or `'_'`, default: `'*'`).
  84. ###### `options.ruleRepetition`
  85. Number of markers to use for thematic breaks (`number`, default:
  86. `3`, min: `3`).
  87. ###### `options.ruleSpaces`
  88. Whether to add spaces between markers in thematic breaks (`boolean`, default:
  89. `false`).
  90. ###### `options.setext`
  91. Whether to use setext headings when possible (`boolean`, default: `false`).
  92. Setext headings are not possible for headings with a rank more than 2 or when
  93. they’re empty.
  94. ###### `options.strong`
  95. Marker to use to serialize strong (`'*'` or `'_'`, default: `'*'`).
  96. ###### `options.tightDefinitions`
  97. Whether to join definitions w/o a blank line (`boolean`, default: `false`).
  98. Shortcut for a join function like so:
  99. ```js
  100. function (left, right) {
  101. if (left.type === 'definition' && right.type === 'definition') {
  102. return 0
  103. }
  104. }
  105. ```
  106. ###### `options.handlers`
  107. Object mapping node types to custom handlers.
  108. Useful for syntax extensions.
  109. Take a look at [`lib/handle`][handlers] for examples.
  110. ###### `options.join`
  111. List of functions used to determine what to place between two flow nodes.
  112. Often, they are joined by one blank line.
  113. In certain cases, it’s nicer to have them next to each other.
  114. Or, they can’t occur together.
  115. These functions receive two adjacent nodes and their parent and can return
  116. `number` or `boolean`, referring to how many blank lines to use between them.
  117. A return value of `true` is as passing `1`.
  118. A return value of `false` means the nodes cannot be joined by a blank line, such
  119. as two adjacent block quotes or indented code after a list, in which case a
  120. comment will be injected to break them up:
  121. ```markdown
  122. > Quote 1
  123. <!---->
  124. > Quote 2
  125. ```
  126. ###### `options.unsafe`
  127. List of patterns to escape.
  128. Useful for syntax extensions.
  129. Take a look at [`lib/unsafe.js`][unsafe] for examples.
  130. ##### Extension options
  131. ###### `options.extensions`
  132. List of extensions (`Array.<ToMarkdownExtension>`).
  133. Each `ToMarkdownExtension` is an object with the same interface as `options`
  134. here.
  135. ##### Returns
  136. `string` — Serialized markdown.
  137. ## List of extensions
  138. * [`syntax-tree/mdast-util-directive`](https://github.com/syntax-tree/mdast-util-directive)
  139. — serialize directives
  140. * [`syntax-tree/mdast-util-footnote`](https://github.com/syntax-tree/mdast-util-footnote)
  141. — serialize footnotes
  142. * [`syntax-tree/mdast-util-frontmatter`](https://github.com/syntax-tree/mdast-util-frontmatter)
  143. — serialize frontmatter (YAML, TOML, more)
  144. * [`syntax-tree/mdast-util-gfm`](https://github.com/syntax-tree/mdast-util-gfm)
  145. — serialize GFM
  146. * [`syntax-tree/mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal)
  147. — serialize GFM autolink literals
  148. * [`syntax-tree/mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough)
  149. — serialize GFM strikethrough
  150. * [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table)
  151. — serialize GFM tables
  152. * [`syntax-tree/mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item)
  153. — serialize GFM task list items
  154. * [`syntax-tree/mdast-util-math`](https://github.com/syntax-tree/mdast-util-math)
  155. — serialize math
  156. * [`syntax-tree/mdast-util-mdx`](https://github.com/syntax-tree/mdast-util-mdx)
  157. — serialize MDX or MDX.js
  158. * [`syntax-tree/mdast-util-mdx-expression`](https://github.com/syntax-tree/mdast-util-mdx-expression)
  159. — serialize MDX or MDX.js expressions
  160. * [`syntax-tree/mdast-util-mdx-jsx`](https://github.com/syntax-tree/mdast-util-mdx-jsx)
  161. — serialize MDX or MDX.js JSX
  162. * [`syntax-tree/mdast-util-mdxjs-esm`](https://github.com/syntax-tree/mdast-util-mdxjs-esm)
  163. — serialize MDX.js ESM
  164. ## Security
  165. `mdast-util-to-markdown` will do its best to serialize markdown to match the
  166. syntax tree, but there are several cases where that is impossible.
  167. It’ll do its best, but complete roundtripping is impossible given that any value
  168. could be injected into the tree.
  169. As Markdown is sometimes used for HTML, and improper use of HTML can open you up
  170. to a [cross-site scripting (XSS)][xss] attack, use of `mdast-util-to-markdown`
  171. and parsing it again later could potentially be unsafe.
  172. When parsing markdown afterwards and then going to HTML, use something like
  173. [`hast-util-sanitize`][sanitize] to make the tree safe.
  174. ## Related
  175. * [`micromark/micromark`](https://github.com/micromark/micromark)
  176. — the smallest commonmark-compliant markdown parser that exists
  177. * [`remarkjs/remark`](https://github.com/remarkjs/remark)
  178. — markdown processor powered by plugins
  179. * [`syntax-tree/mdast-util-from-markdown`](https://github.com/syntax-tree/mdast-util-from-markdown)
  180. — parse markdown to mdast
  181. ## Contribute
  182. See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
  183. started.
  184. See [`support.md`][support] for ways to get help.
  185. This project has a [code of conduct][coc].
  186. By interacting with this repository, organization, or community you agree to
  187. abide by its terms.
  188. ## License
  189. [MIT][license] © [Titus Wormer][author]
  190. <!-- Definitions -->
  191. [build-badge]: https://github.com/syntax-tree/mdast-util-to-markdown/workflows/main/badge.svg
  192. [build]: https://github.com/syntax-tree/mdast-util-to-markdown/actions
  193. [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-to-markdown.svg
  194. [coverage]: https://codecov.io/github/syntax-tree/mdast-util-to-markdown
  195. [downloads-badge]: https://img.shields.io/npm/dm/mdast-util-to-markdown.svg
  196. [downloads]: https://www.npmjs.com/package/mdast-util-to-markdown
  197. [size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-to-markdown.svg
  198. [size]: https://bundlephobia.com/result?p=mdast-util-to-markdown
  199. [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
  200. [backers-badge]: https://opencollective.com/unified/backers/badge.svg
  201. [collective]: https://opencollective.com/unified
  202. [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
  203. [chat]: https://github.com/syntax-tree/unist/discussions
  204. [npm]: https://docs.npmjs.com/cli/install
  205. [license]: license
  206. [author]: https://wooorm.com
  207. [contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
  208. [support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
  209. [coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
  210. [mdast]: https://github.com/syntax-tree/mdast
  211. [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
  212. [sanitize]: https://github.com/syntax-tree/hast-util-sanitize
  213. [handlers]: lib/handle
  214. [unsafe]: lib/unsafe.js