├── .npmrc ├── test └── fixtures │ ├── input │ ├── empty.text │ ├── image-with-pipe.text │ ├── escaped-angles.text │ ├── hr.output.rule=-.text │ ├── hr.output.rule=_.text │ ├── deletion.text │ ├── hr.output.norule-spaces.text │ ├── image-empty-alt.text │ ├── hr.output.rule=-asterisk-.text │ ├── not-a-link.text │ ├── blockquote-indented.text │ ├── hr.output.rule-repetition=5.text │ ├── lazy-blockquotes.text │ ├── list-item-empty-with-white-space.text │ ├── list-item-empty-without-white-space-eof.text │ ├── list-item-empty-without-white-space.text │ ├── list-ordered-empty-no-space-single-item.text │ ├── list-unordered-empty-no-space-single-item.text │ ├── blockquote-lazy-code.text │ ├── heading-in-paragraph.text │ ├── ref-paren.text │ ├── case-insensitive-refs.text │ ├── list-interrupt.text │ ├── list-unordered-empty-no-space.text │ ├── same-bullet.nooutput.text │ ├── table-no-end-of-line.text │ ├── fenced-code-lang-unescape.text │ ├── list-item-newline.nooutput.text │ ├── list-ordered-empty-no-space.text │ ├── definition-unclosed.text │ ├── emphasis-internal.text │ ├── html-processing-instruction.text │ ├── nested-blockquotes.text │ ├── reference-image-empty-alt.text │ ├── strong-initial-white-space.text │ ├── list-item-text.text │ ├── ordered-different-types.nooutput.text │ ├── strong-emphasis.text │ ├── bom.text │ ├── fenced-code-trailing-characters-2.nooutput.text │ ├── heading-atx-closed-trailing-white-space.text │ ├── heading-atx-no-space-before-trailing-number-sign.text │ ├── list-and-code.text │ ├── nested-code.text │ ├── nested-em.nooutput.text │ ├── reference-link-not-closed.text │ ├── table-one-column.text │ ├── blockquote-lazy-rule.text │ ├── definition-url-entities.text │ ├── html-cdata.text │ ├── table-one-row.text │ ├── emphasis.output.emphasis=-asterisk-.strong=_.text │ ├── emphasis.output.emphasis=_.strong=-asterisk-.text │ ├── fenced-code-trailing-characters.nooutput.text │ ├── list-ordered.increment-list-marker.output.text │ ├── list-ordered.noincrement-list-marker.output.text │ ├── reference-link-with-angle-brackets.text │ ├── table-empty-initial-cell.text │ ├── list-item-empty.text │ ├── code-blocks.output.text │ ├── emphasis-escaped-final-marker.text │ ├── reference-link-with-multiple-definitions.text │ ├── table-no-body.text │ ├── blockquote-list-item.text │ ├── code-block.output.fence=`.text │ ├── code-block.output.fence=~.text │ ├── links-url-empty.text │ ├── code-blocks.output.fences.text │ ├── isolated-hard-break.text │ ├── paragraphs-empty.text │ ├── table-loose.text │ ├── tidyness.text │ ├── auto-link-lines.text │ ├── blockquotes.text │ ├── emphasis-empty.text │ ├── heading-atx-empty.text │ ├── link-with-spaces.text │ ├── links-url-unclosed.text │ ├── fenced-code-white-space-after-flag.text │ ├── auto-link-invalid.text │ ├── table-loose.output.text │ ├── table-pipe-align.output.notable-pipe-align.text │ ├── html-declaration.text │ ├── table-cell-padding.output.text │ ├── table-pipe-align.output.text │ ├── blockquote-lazy-list.text │ ├── blockquotes-empty-lines.output.text │ ├── table-cell-padding.output.notable-cell-padding.text │ ├── link-spaces.text │ ├── links-text-empty.text │ ├── links-url-white-space.text │ ├── reference-link-escape.nooutput.text │ ├── list.output.bullet=+.text │ ├── list.output.bullet=-.text │ ├── strong-and-em-together-one.text │ ├── nested-square-link.text │ ├── code-inline-whitespace.text │ ├── links-title-empty-double-quotes.text │ ├── links-title-empty-parentheses.text │ ├── links-title-empty-single-quotes.text │ ├── list.output.bullet=-asterisk-.text │ ├── links-url-new-line.text │ ├── task-list-ordered.text │ ├── task-list-unordered-dash.text │ ├── task-list-unordered-plus.text │ ├── task-list-unordered-asterisk.text │ ├── definition-in-list-and-blockquote.text │ ├── table-in-list.text │ ├── heading-setext-with-initial-spacing.text │ ├── list-after-list.text │ ├── strong-and-em-together-two.nooutput.text │ ├── heading.output.setext.text │ ├── heading.output.close-atx.text │ ├── list-continuation.text │ ├── links-url-nested-parentheses.text │ ├── links-text-delimiters.text │ ├── links-title-parentheses.text │ ├── mixed-indentation.text │ ├── html-indented.text │ ├── links-text-mismatched-delimiters.text │ ├── links-title-double-quotes.text │ ├── links-title-single-quotes.text │ ├── blockquotes-with-code-blocks.text │ ├── links-reference-proto.text │ ├── links-url-empty-title-double-quotes.text │ ├── links-url-empty-title-parentheses.text │ ├── links-url-empty-title-single-quotes.text │ ├── tricky-list.text │ ├── links-text-escaped-delimiters.text │ ├── fenced-code-initial-final-newlines.text │ ├── heading-in-blockquote.text │ ├── link-in-link.text │ ├── nested-references.text │ ├── auto-link-url-invalid.text │ ├── def-blocks.text │ ├── definition-newline.text │ ├── html-advanced.text │ ├── double-link.text │ ├── fenced-code-empty.text │ ├── table-escaped-pipes.nooutput.text │ ├── links-title-double-quotes-delimiters.text │ ├── links-title-single-quotes-delimiters.text │ ├── definition-unclosed-attribute.text │ ├── horizontal-rules-adjacent.text │ ├── links-title-double-quotes-mismatched-delimiters.text │ ├── links-title-single-quotes-mismatched-delimiters.text │ ├── links-url-entities.text │ ├── links-title-double-quotes-escaped-delimiters.text │ ├── links-title-single-quotes-escaped-delimiters.text │ ├── auto-link-output.output.text │ ├── code-blocks.text │ ├── table-invalid-alignment.text │ ├── links-title-double-quotes-entity-delimiters.text │ ├── links-title-single-quotes-entity-delimiters.text │ ├── fenced-code.text │ ├── breaks-hard.text │ ├── heading-not-atx.text │ ├── links-shortcut-references.text │ ├── auto-link-url.text │ ├── no-positionals.nooutput.text │ ├── image-in-link.text │ ├── hr-list-break.text │ ├── links-url-mismatched-parentheses.text │ ├── links-inline-style.text │ ├── tabs.text │ ├── blockquote-lazy-fence.text │ ├── links-url-escaped-parentheses.text │ ├── tabs-and-spaces.text │ ├── literal-email.text │ ├── auto-link.text │ ├── tables-with-pipes-and-code.text │ ├── list-item-indent.list-item-indent=1.output.text │ ├── links-title-unclosed.text │ ├── links-text-entity-delimiters.text │ ├── list-indentation.nooutput.text │ ├── list-item-indent.list-item-indent=mixed.output.text │ ├── amps-and-angles-encoding.text │ ├── block-elements.text │ ├── code-block-indentation.nooutput.text │ ├── list-item-indent.list-item-indent=tab.output.text │ ├── fenced-code-info-string.text │ ├── auto-link-syntax.text │ ├── ordered-with-parentheses.text │ ├── html-comments.text │ ├── loose-lists.text │ ├── links.output.noreference-links.text │ ├── toplevel-paragraphs.text │ ├── code-spans.text │ ├── images.output.noreference-images.text │ ├── horizontal-rules.text │ ├── table.text │ ├── code-block-nesting-bug.text │ ├── link-whitespace.text │ ├── hard-wrapped-paragraphs-with-list-like-lines.text │ ├── html-attributes.text │ ├── paragraphs-and-indentation.text │ ├── fenced-code-info-with-marker.text │ ├── entities.text │ ├── lists-with-code-and-rules.text │ ├── html-simple.text │ ├── links-url-entity-parentheses.text │ ├── entities-advanced.text │ ├── html-tags.text │ ├── links-reference-style.text │ ├── list-mixed-indentation.text │ ├── main.text │ ├── task-list.text │ ├── entities.output.noentities.text │ ├── ordered-and-unordered-lists.text │ ├── entities.output.entities.text │ ├── entities.output.entities=escape.text │ ├── entities.output.entities=numbers.text │ ├── stringify-escape.output.commonmark.text │ └── stringify-escape.output.nogfm.commonmark.text │ └── tree │ ├── empty.json │ ├── hr.output.rule=-.json │ ├── hr.output.rule=_.json │ ├── hr.output.norule-spaces.json │ ├── hr.output.rule-repetition=5.json │ ├── hr.output.rule=-asterisk-.json │ ├── html-processing-instruction.json │ ├── fenced-code-lang-unescape.json │ ├── fenced-code-trailing-characters-2.nooutput.json │ ├── definition-url-entities.json │ ├── fenced-code-trailing-characters.nooutput.json │ ├── escaped-angles.json │ ├── image-with-pipe.json │ ├── deletion.nogfm.json │ ├── emphasis-internal.json │ ├── image-empty-alt.json │ ├── isolated-hard-break.json │ ├── blockquote-lazy-code.json │ ├── heading-in-paragraph.commonmark.json │ ├── table-no-end-of-line.nogfm.json │ ├── fenced-code-white-space-after-flag.json │ ├── list-item-empty-with-white-space.json │ ├── list-item-empty-without-white-space.json │ ├── list-ordered-empty-no-space-single-item.json │ ├── list-item-empty-without-white-space-eof.json │ ├── list-unordered-empty-no-space-single-item.json │ ├── list-ordered-empty-no-space-single-item.commonmark.json │ ├── list-unordered-empty-no-space-single-item.commonmark.json │ ├── table-empty-initial-cell.nogfm.json │ ├── not-a-link.json │ ├── code-blocks.output.json │ ├── blockquote-lazy-code.commonmark.json │ ├── code-block.output.fence=`.json │ ├── code-block.output.fence=~.json │ ├── code-blocks.output.fences.json │ ├── reference-image-empty-alt.json │ ├── fenced-code-trailing-characters-2.nooutput.nogfm.json │ ├── blockquote-indented.json │ ├── lazy-blockquotes.json │ └── fenced-code-trailing-characters.nooutput.nogfm.json ├── lerna.json ├── .prettierignore ├── .gitignore ├── changelog.md ├── doc └── products.md ├── packages ├── remark-stringify │ ├── lib │ │ ├── visitors │ │ │ ├── html.js │ │ │ ├── paragraph.js │ │ │ ├── list.js │ │ │ ├── table-cell.js │ │ │ ├── delete.js │ │ │ ├── break.js │ │ │ ├── root.js │ │ │ ├── image-reference.js │ │ │ ├── text.js │ │ │ ├── strong.js │ │ │ ├── blockquote.js │ │ │ ├── link-reference.js │ │ │ ├── thematic-break.js │ │ │ ├── definition.js │ │ │ ├── emphasis.js │ │ │ ├── heading.js │ │ │ ├── table.js │ │ │ ├── image.js │ │ │ └── inline-code.js │ │ ├── util │ │ │ ├── identity.js │ │ │ ├── enclose-title.js │ │ │ ├── pad.js │ │ │ ├── entity-prefix-length.js │ │ │ ├── label.js │ │ │ ├── enclose-uri.js │ │ │ └── enter-link-reference.js │ │ ├── macro │ │ │ ├── compile.js │ │ │ ├── all.js │ │ │ ├── one.js │ │ │ ├── unordered-items.js │ │ │ └── ordered-items.js │ │ └── defaults.js │ ├── types │ │ ├── tsconfig.json │ │ ├── tslint.json │ │ └── index.d.ts │ ├── index.js │ └── package.json ├── remark-parse │ ├── lib │ │ ├── locate │ │ │ ├── tag.js │ │ │ ├── delete.js │ │ │ ├── escape.js │ │ │ ├── code-inline.js │ │ │ ├── break.js │ │ │ ├── link.js │ │ │ ├── emphasis.js │ │ │ ├── strong.js │ │ │ ├── url.js │ │ │ └── email.js │ │ ├── defaults.js │ │ ├── util │ │ │ ├── normalize.js │ │ │ ├── is-markdown-whitespace-character.js │ │ │ ├── interrupt.js │ │ │ ├── get-indentation.js │ │ │ ├── html.js │ │ │ └── remove-indentation.js │ │ ├── tokenize │ │ │ ├── escape.js │ │ │ ├── break.js │ │ │ ├── blank-line.js │ │ │ ├── text.js │ │ │ ├── delete.js │ │ │ ├── html-inline.js │ │ │ └── thematic-break.js │ │ ├── unescape.js │ │ ├── block-elements.js │ │ ├── parse.js │ │ ├── set-options.js │ │ └── decode.js │ ├── types │ │ ├── tsconfig.json │ │ ├── tslint.json │ │ └── test.ts │ └── index.js ├── remark │ ├── types │ │ ├── tsconfig.json │ │ ├── tslint.json │ │ ├── index.d.ts │ │ └── test.ts │ ├── index.js │ ├── test.js │ └── package.json └── remark-cli │ ├── cli.js │ └── package.json ├── .editorconfig ├── .travis.yml ├── .mailmap ├── script ├── list-of-methods.js └── regenerate-fixtures.js └── license /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /test/fixtures/input/empty.text: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/input/image-with-pipe.text: -------------------------------------------------------------------------------- 1 | f| -------------------------------------------------------------------------------- /test/fixtures/input/escaped-angles.text: -------------------------------------------------------------------------------- 1 | \> 2 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "independent" 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/input/hr.output.rule=-.text: -------------------------------------------------------------------------------- 1 | - - - 2 | -------------------------------------------------------------------------------- /test/fixtures/input/hr.output.rule=_.text: -------------------------------------------------------------------------------- 1 | _ _ _ 2 | -------------------------------------------------------------------------------- /test/fixtures/input/deletion.text: -------------------------------------------------------------------------------- 1 | hello ~~hi~~ world 2 | -------------------------------------------------------------------------------- /test/fixtures/input/hr.output.norule-spaces.text: -------------------------------------------------------------------------------- 1 | *** 2 | -------------------------------------------------------------------------------- /test/fixtures/input/image-empty-alt.text: -------------------------------------------------------------------------------- 1 | ![](/xyz.png) 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | coverage/ 2 | remark.js 3 | remark.min.js 4 | -------------------------------------------------------------------------------- /test/fixtures/input/hr.output.rule=-asterisk-.text: -------------------------------------------------------------------------------- 1 | * * * 2 | -------------------------------------------------------------------------------- /test/fixtures/input/not-a-link.text: -------------------------------------------------------------------------------- 1 | \[test](not a link) 2 | -------------------------------------------------------------------------------- /test/fixtures/input/blockquote-indented.text: -------------------------------------------------------------------------------- 1 | > bar 2 | > baz 3 | -------------------------------------------------------------------------------- /test/fixtures/input/hr.output.rule-repetition=5.text: -------------------------------------------------------------------------------- 1 | * * * * * 2 | -------------------------------------------------------------------------------- /test/fixtures/input/lazy-blockquotes.text: -------------------------------------------------------------------------------- 1 | > hi there 2 | bud 3 | -------------------------------------------------------------------------------- /test/fixtures/input/list-item-empty-with-white-space.text: -------------------------------------------------------------------------------- 1 | - 2 | -------------------------------------------------------------------------------- /test/fixtures/input/list-item-empty-without-white-space-eof.text: -------------------------------------------------------------------------------- 1 | - -------------------------------------------------------------------------------- /test/fixtures/input/list-item-empty-without-white-space.text: -------------------------------------------------------------------------------- 1 | - 2 | -------------------------------------------------------------------------------- /test/fixtures/input/list-ordered-empty-no-space-single-item.text: -------------------------------------------------------------------------------- 1 | 1. -------------------------------------------------------------------------------- /test/fixtures/input/list-unordered-empty-no-space-single-item.text: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /test/fixtures/input/blockquote-lazy-code.text: -------------------------------------------------------------------------------- 1 | > foo 2 | bar 3 | -------------------------------------------------------------------------------- /test/fixtures/input/heading-in-paragraph.text: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | === 4 | -------------------------------------------------------------------------------- /test/fixtures/input/ref-paren.text: -------------------------------------------------------------------------------- 1 | [hi] 2 | 3 | [hi]: /url (there) 4 | -------------------------------------------------------------------------------- /test/fixtures/input/case-insensitive-refs.text: -------------------------------------------------------------------------------- 1 | [hi] 2 | 3 | [HI]: /url 4 | -------------------------------------------------------------------------------- /test/fixtures/input/list-interrupt.text: -------------------------------------------------------------------------------- 1 | * Something 2 | ### Some heading 3 | -------------------------------------------------------------------------------- /test/fixtures/input/list-unordered-empty-no-space.text: -------------------------------------------------------------------------------- 1 | * 2 | * 3 | * 4 | * 5 | -------------------------------------------------------------------------------- /test/fixtures/input/same-bullet.nooutput.text: -------------------------------------------------------------------------------- 1 | * test 2 | + test 3 | - test 4 | -------------------------------------------------------------------------------- /test/fixtures/input/table-no-end-of-line.text: -------------------------------------------------------------------------------- 1 | |foo|bar| 2 | |-|-| 3 | |1|2| -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code-lang-unescape.text: -------------------------------------------------------------------------------- 1 | ```\\\[awd 2 | dwa 3 | ``` 4 | -------------------------------------------------------------------------------- /test/fixtures/input/list-item-newline.nooutput.text: -------------------------------------------------------------------------------- 1 | - Foo 2 | - 3 | Bar 4 | -------------------------------------------------------------------------------- /test/fixtures/input/list-ordered-empty-no-space.text: -------------------------------------------------------------------------------- 1 | 1. 2 | 2. 3 | 3. 4 | 4. 5 | -------------------------------------------------------------------------------- /test/fixtures/input/definition-unclosed.text: -------------------------------------------------------------------------------- 1 | [foo]: 2 | 3 | [bar]: '; 3 | ?> 4 | -------------------------------------------------------------------------------- /test/fixtures/input/nested-blockquotes.text: -------------------------------------------------------------------------------- 1 | > foo 2 | > 3 | > > bar 4 | > 5 | > foo 6 | -------------------------------------------------------------------------------- /test/fixtures/input/reference-image-empty-alt.text: -------------------------------------------------------------------------------- 1 | ![][1] 2 | 3 | [1]: /xyz.png 4 | -------------------------------------------------------------------------------- /test/fixtures/input/strong-initial-white-space.text: -------------------------------------------------------------------------------- 1 | ** bar **. 2 | 3 | 4 | __ bar __. -------------------------------------------------------------------------------- /test/fixtures/input/list-item-text.text: -------------------------------------------------------------------------------- 1 | * item1 2 | 3 | * item2 4 | 5 | text 6 | -------------------------------------------------------------------------------- /test/fixtures/input/ordered-different-types.nooutput.text: -------------------------------------------------------------------------------- 1 | 1. foo 2 | 2. bar 3 | 3) baz 4 | -------------------------------------------------------------------------------- /test/fixtures/input/strong-emphasis.text: -------------------------------------------------------------------------------- 1 | Foo **bar** __baz__. 2 | 3 | Foo __bar__ **baz**. -------------------------------------------------------------------------------- /test/fixtures/input/bom.text: -------------------------------------------------------------------------------- 1 | # Hello from a BOM 2 | 3 | Be careful when editing this file! 4 | -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code-trailing-characters-2.nooutput.text: -------------------------------------------------------------------------------- 1 | ``` 2 | ``` aaa 3 | ``` 4 | -------------------------------------------------------------------------------- /test/fixtures/input/heading-atx-closed-trailing-white-space.text: -------------------------------------------------------------------------------- 1 | # Foo # 2 | 3 | ## Bar ## 4 | -------------------------------------------------------------------------------- /test/fixtures/input/heading-atx-no-space-before-trailing-number-sign.text: -------------------------------------------------------------------------------- 1 | # awd# 2 | ## dwa### 3 | -------------------------------------------------------------------------------- /test/fixtures/input/list-and-code.text: -------------------------------------------------------------------------------- 1 | * This is a list item 2 | 3 | 4 | This is code 5 | -------------------------------------------------------------------------------- /test/fixtures/input/nested-code.text: -------------------------------------------------------------------------------- 1 | ````` hi ther `` ok ``` ````` 2 | 3 | `` `hi ther` `` 4 | -------------------------------------------------------------------------------- /test/fixtures/input/nested-em.nooutput.text: -------------------------------------------------------------------------------- 1 | *test **test** test* 2 | 3 | _test __test__ test_ 4 | -------------------------------------------------------------------------------- /test/fixtures/input/reference-link-not-closed.text: -------------------------------------------------------------------------------- 1 | [bar][bar 2 | 3 | [bar][ 4 | 5 | [bar] 6 | -------------------------------------------------------------------------------- /test/fixtures/input/table-one-column.text: -------------------------------------------------------------------------------- 1 | This is a table: 2 | 3 | | a | 4 | | - | 5 | | b | 6 | -------------------------------------------------------------------------------- /test/fixtures/input/blockquote-lazy-rule.text: -------------------------------------------------------------------------------- 1 | > This is a blockquote. Followed by a rule. 2 | * * * 3 | -------------------------------------------------------------------------------- /test/fixtures/input/definition-url-entities.text: -------------------------------------------------------------------------------- 1 | [baz]: http://www.example.com?param=1®ion=here 2 | -------------------------------------------------------------------------------- /test/fixtures/input/html-cdata.text: -------------------------------------------------------------------------------- 1 | 4 | 5 | foo 6 | -------------------------------------------------------------------------------- /test/fixtures/input/table-one-row.text: -------------------------------------------------------------------------------- 1 | This is a table: 2 | 3 | | a | b | c | 4 | | - | - | - | 5 | -------------------------------------------------------------------------------- /test/fixtures/input/emphasis.output.emphasis=-asterisk-.strong=_.text: -------------------------------------------------------------------------------- 1 | *emphasis*. 2 | 3 | __strong__. 4 | -------------------------------------------------------------------------------- /test/fixtures/input/emphasis.output.emphasis=_.strong=-asterisk-.text: -------------------------------------------------------------------------------- 1 | _emphasis_. 2 | 3 | **strong**. 4 | -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code-trailing-characters.nooutput.text: -------------------------------------------------------------------------------- 1 | ```js 2 | foo(); 3 | ```bash 4 | ``` 5 | -------------------------------------------------------------------------------- /test/fixtures/input/list-ordered.increment-list-marker.output.text: -------------------------------------------------------------------------------- 1 | 2. foo; 2 | 3. bar; 3 | 4. baz. 4 | -------------------------------------------------------------------------------- /test/fixtures/input/list-ordered.noincrement-list-marker.output.text: -------------------------------------------------------------------------------- 1 | 2. foo; 2 | 2. bar; 3 | 2. baz. 4 | -------------------------------------------------------------------------------- /test/fixtures/input/reference-link-with-angle-brackets.text: -------------------------------------------------------------------------------- 1 | [foo] 2 | 3 | [foo]: <./url with spaces> 4 | -------------------------------------------------------------------------------- /test/fixtures/input/table-empty-initial-cell.text: -------------------------------------------------------------------------------- 1 | | | a|c| 2 | |--|:----:|:---| 3 | |a|b|c| 4 | |a|b|c| 5 | -------------------------------------------------------------------------------- /test/fixtures/input/list-item-empty.text: -------------------------------------------------------------------------------- 1 | - foo 2 | - 3 | - bar 4 | 5 | - foo 6 | - 7 | - bar 8 | -------------------------------------------------------------------------------- /test/fixtures/input/code-blocks.output.text: -------------------------------------------------------------------------------- 1 | A code block NOT using fences: 2 | 3 | alert('Hello World!'); 4 | -------------------------------------------------------------------------------- /test/fixtures/input/emphasis-escaped-final-marker.text: -------------------------------------------------------------------------------- 1 | *bar\* 2 | 3 | **bar\** 4 | 5 | _bar\_ 6 | 7 | __bar\__ 8 | -------------------------------------------------------------------------------- /test/fixtures/input/reference-link-with-multiple-definitions.text: -------------------------------------------------------------------------------- 1 | [foo] 2 | 3 | [foo]: first 4 | [foo]: second 5 | -------------------------------------------------------------------------------- /test/fixtures/input/table-no-body.text: -------------------------------------------------------------------------------- 1 | # Foo 2 | 3 | | Name | GitHub | Twitter | 4 | | ---- | ------ | ------- | 5 | -------------------------------------------------------------------------------- /test/fixtures/input/blockquote-list-item.text: -------------------------------------------------------------------------------- 1 | This fails in markdown.pl and upskirt: 2 | 3 | * hello 4 | > world 5 | -------------------------------------------------------------------------------- /test/fixtures/input/code-block.output.fence=`.text: -------------------------------------------------------------------------------- 1 | Ticks: 2 | 3 | ```javascript 4 | alert('Hello World!'); 5 | ``` 6 | -------------------------------------------------------------------------------- /test/fixtures/input/code-block.output.fence=~.text: -------------------------------------------------------------------------------- 1 | Tildes: 2 | 3 | ~~~javascript 4 | alert('Hello World!'); 5 | ~~~ 6 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-empty.text: -------------------------------------------------------------------------------- 1 | [Hello](). 2 | 3 | [World](<>). 4 | 5 | ![Hello](). 6 | 7 | ![World](<>). 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .nyc_output 3 | *.log 4 | node_modules 5 | coverage 6 | /remark.js 7 | /remark.min.js 8 | yarn.lock 9 | -------------------------------------------------------------------------------- /test/fixtures/input/code-blocks.output.fences.text: -------------------------------------------------------------------------------- 1 | A code block using fences: 2 | 3 | ``` 4 | alert('Hello World!'); 5 | ``` 6 | -------------------------------------------------------------------------------- /test/fixtures/input/isolated-hard-break.text: -------------------------------------------------------------------------------- 1 | 2 | The previous line, which contains 2 spaces, should be considered to be empty. 3 | -------------------------------------------------------------------------------- /test/fixtures/input/paragraphs-empty.text: -------------------------------------------------------------------------------- 1 | 2 | 3 | aaa 4 | 5 | 6 | # aaa 7 | 8 | 9 | 10 | bbb 11 | 12 | ccc -------------------------------------------------------------------------------- /test/fixtures/input/table-loose.text: -------------------------------------------------------------------------------- 1 | Header 1 | Header 2 2 | -------- | -------- 3 | Cell 1 | Cell 2 4 | Cell 3 | Cell 4 5 | -------------------------------------------------------------------------------- /test/fixtures/input/tidyness.text: -------------------------------------------------------------------------------- 1 | > A list within a blockquote: 2 | > 3 | > * asterisk 1 4 | > * asterisk 2 5 | > * asterisk 3 6 | -------------------------------------------------------------------------------- /test/fixtures/input/auto-link-lines.text: -------------------------------------------------------------------------------- 1 | hello world 2 | 3 | 4 | hello world 5 | 6 | -------------------------------------------------------------------------------- /test/fixtures/input/blockquotes.text: -------------------------------------------------------------------------------- 1 | > This is a blockquote. 2 | 3 | > This is, in commonmark mode and gfm mode, another blockquote. 4 | -------------------------------------------------------------------------------- /test/fixtures/input/emphasis-empty.text: -------------------------------------------------------------------------------- 1 | Hello ** ** world. 2 | 3 | Hello __ __ world. 4 | 5 | Hello * * world. 6 | 7 | Hello _ _ world. 8 | -------------------------------------------------------------------------------- /test/fixtures/input/heading-atx-empty.text: -------------------------------------------------------------------------------- 1 | # # 2 | 3 | ## 4 | 5 | ### ### 6 | 7 | #### 8 | 9 | ##### ##### 10 | 11 | ###### 12 | -------------------------------------------------------------------------------- /test/fixtures/input/link-with-spaces.text: -------------------------------------------------------------------------------- 1 | [Hello](<./world and some spaces.html>) 2 | 3 | [Hello](<./world and some spaces.html> "and a title") -------------------------------------------------------------------------------- /test/fixtures/input/links-url-unclosed.text: -------------------------------------------------------------------------------- 1 | [Hello]( 2 | 3 | 4 | [World](< 5 | 6 | 7 | ![Hello]( 8 | 9 | 10 | ![World](< 11 | -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code-white-space-after-flag.text: -------------------------------------------------------------------------------- 1 | ``` js 2 | foo(); 3 | ``` 4 | 5 | ~~~~~ bash 6 | echo "hello, ${WORLD}" 7 | ~~~~~ 8 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | See [GitHub Releases][releases] for the changelog. 4 | 5 | [releases]: https://github.com/remarkjs/remark/releases 6 | -------------------------------------------------------------------------------- /test/fixtures/input/auto-link-invalid.text: -------------------------------------------------------------------------------- 1 | 6 | 7 | 2 | 3 | foo 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/input/table-cell-padding.output.text: -------------------------------------------------------------------------------- 1 | | Header 1 | Header 2 | 2 | | -------- | -------: | 3 | | Cell 1 | Cell 2 | 4 | | Cell 3 | Cell 4 | 5 | -------------------------------------------------------------------------------- /test/fixtures/input/table-pipe-align.output.text: -------------------------------------------------------------------------------- 1 | | Header 1 | Header 2 | 2 | | -------- | -------- | 3 | | Cell 1 | Cell 2 | 4 | | Cell 3 | Cell 4 | 5 | -------------------------------------------------------------------------------- /test/fixtures/input/blockquote-lazy-list.text: -------------------------------------------------------------------------------- 1 | > This is a blockquote. 2 | - And in normal mode this is an internal list, but in commonmark this is a top level list. 3 | -------------------------------------------------------------------------------- /test/fixtures/input/blockquotes-empty-lines.output.text: -------------------------------------------------------------------------------- 1 | > Note there is no space on the following line. 2 | > 3 | > Note there is no space on the preceding line. 4 | -------------------------------------------------------------------------------- /test/fixtures/input/table-cell-padding.output.notable-cell-padding.text: -------------------------------------------------------------------------------- 1 | |Header 1|Header 2| 2 | |--------|-------:| 3 | |Cell 1 | Cell 2| 4 | |Cell 3 | Cell 4| 5 | -------------------------------------------------------------------------------- /test/fixtures/input/link-spaces.text: -------------------------------------------------------------------------------- 1 | [alpha] (bravo 2 | 3 | ![charlie] (delta 4 | .com) 5 | 6 | [echo] (http://foxtrot.golf) 7 | 8 | ![hotel] (india.com/juliett) 9 | -------------------------------------------------------------------------------- /test/fixtures/input/links-text-empty.text: -------------------------------------------------------------------------------- 1 | [](./hello-world.html). 2 | 3 | [](<./hello-world.html>). 4 | 5 | ![](./hello-world.html). 6 | 7 | ![](<./hello-world.html>). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-white-space.text: -------------------------------------------------------------------------------- 1 | [Hello](./wo rld.html). 2 | 3 | [Hello](<./wo rld.html>). 4 | 5 | ![Hello](./wo rld.png). 6 | 7 | ![Hello](<./wo rld.png>). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/reference-link-escape.nooutput.text: -------------------------------------------------------------------------------- 1 | [b\*r*][b\-r], [b\*r*][], [b\*r*]. 2 | 3 | ![foo][b\*r*], ![b\*r*][], ![b\*r*]. 4 | 5 | [b\*r*]: http://google.com 6 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/tag.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | function locate(value, fromIndex) { 6 | return value.indexOf('<', fromIndex) 7 | } 8 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/paragraph.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = paragraph 4 | 5 | function paragraph(node) { 6 | return this.all(node).join('') 7 | } 8 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/delete.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | function locate(value, fromIndex) { 6 | return value.indexOf('~~', fromIndex) 7 | } 8 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/escape.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | function locate(value, fromIndex) { 6 | return value.indexOf('\\', fromIndex) 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/input/list.output.bullet=+.text: -------------------------------------------------------------------------------- 1 | # List bullets 2 | 3 | + One: 4 | + Nested one; 5 | + Nested two: 6 | + Nested three. 7 | + Two; 8 | + Three. 9 | -------------------------------------------------------------------------------- /test/fixtures/input/list.output.bullet=-.text: -------------------------------------------------------------------------------- 1 | # List bullets 2 | 3 | - One: 4 | - Nested one; 5 | - Nested two: 6 | - Nested three. 7 | - Two; 8 | - Three. 9 | -------------------------------------------------------------------------------- /test/fixtures/input/strong-and-em-together-one.text: -------------------------------------------------------------------------------- 1 | ***This is strong and em.*** 2 | 3 | So is ***this*** word. 4 | 5 | ___This is strong and em.___ 6 | 7 | So is ___this___ word. 8 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/code-inline.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | function locate(value, fromIndex) { 6 | return value.indexOf('`', fromIndex) 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/input/nested-square-link.text: -------------------------------------------------------------------------------- 1 | [the `]` character](/url) 2 | 3 | [the `` [ `` character](/url) 4 | 5 | [the `` [ ``` character](/url) 6 | 7 | [the `` ` `` character](/url) 8 | -------------------------------------------------------------------------------- /test/fixtures/input/code-inline-whitespace.text: -------------------------------------------------------------------------------- 1 | Markdown strips regular whitespaces: ` hello ` 2 | Including tabs: ` hello ` 3 | However it preserves non-breaking whitespaces: `   hello   ` 4 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-empty-double-quotes.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html ""). 2 | 3 | [Hello](<./world.html> ""). 4 | 5 | ![Hello](./world.html ""). 6 | 7 | ![Hello](<./world.html> ""). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-empty-parentheses.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html ()). 2 | 3 | [Hello](<./world.html> ()). 4 | 5 | ![Hello](./world.html ()). 6 | 7 | ![Hello](<./world.html> ()). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-empty-single-quotes.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html ''). 2 | 3 | [Hello](<./world.html> ''). 4 | 5 | ![Hello](./world.html ''). 6 | 7 | ![Hello](<./world.html> ''). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/list.output.bullet=-asterisk-.text: -------------------------------------------------------------------------------- 1 | # List bullets 2 | 3 | * One: 4 | * Nested one; 5 | * Nested two: 6 | * Nested three. 7 | * Two; 8 | * Three. 9 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-new-line.text: -------------------------------------------------------------------------------- 1 | [Hello](./wo 2 | rld.html). 3 | 4 | [Hello](<./wo 5 | rld.html>). 6 | 7 | ![Hello](./wo 8 | rld.png). 9 | 10 | ![Hello](<./wo 11 | rld.png>). 12 | -------------------------------------------------------------------------------- /test/fixtures/input/task-list-ordered.text: -------------------------------------------------------------------------------- 1 | 1. [ ] Mercury; 2 | 2. [] Venus (this one’s invalid); 3 | 3. [x] Earth: 4 | 1. [x] Moon. 5 | 4. [ ] Mars; 6 | 8. [] Neptune (this one’s also invalid). 7 | -------------------------------------------------------------------------------- /test/fixtures/input/task-list-unordered-dash.text: -------------------------------------------------------------------------------- 1 | - [ ] Mercury; 2 | - [] Venus (this one’s invalid); 3 | - [x] Earth: 4 | - [x] Moon. 5 | - [ ] Mars; 6 | - [] Neptune (this one’s also invalid). 7 | -------------------------------------------------------------------------------- /test/fixtures/input/task-list-unordered-plus.text: -------------------------------------------------------------------------------- 1 | + [ ] Mercury; 2 | + [] Venus (this one’s invalid); 3 | + [x] Earth: 4 | + [x] Moon. 5 | + [ ] Mars; 6 | + [] Neptune (this one’s also invalid). 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /test/fixtures/input/task-list-unordered-asterisk.text: -------------------------------------------------------------------------------- 1 | * [ ] Mercury; 2 | * [] Venus (this one’s invalid); 3 | * [x] Earth: 4 | * [x] Moon. 5 | * [ ] Mars; 6 | * [] Neptune (this one’s also invalid). 7 | -------------------------------------------------------------------------------- /test/fixtures/input/definition-in-list-and-blockquote.text: -------------------------------------------------------------------------------- 1 | [alpha][1], [bravo][2]. 2 | 3 | * Definition in list: 4 | 5 | [1]: alpha 6 | 7 | > Definition in blockquote: 8 | > 9 | > [2]: bravo 10 | -------------------------------------------------------------------------------- /test/fixtures/input/table-in-list.text: -------------------------------------------------------------------------------- 1 | * Unordered: 2 | 3 | | A | B | 4 | | - | - | 5 | | 1 | 2 | 6 | 7 | * Ordered: 8 | 9 | | A | B | 10 | | - | - | 11 | | 1 | 2 | 12 | -------------------------------------------------------------------------------- /test/fixtures/input/heading-setext-with-initial-spacing.text: -------------------------------------------------------------------------------- 1 | Heading 1 2 | ========= 3 | 4 | Heading 2 5 | --------- 6 | 7 | Both these headings caused positional problems in on commit daa344c and before. 8 | -------------------------------------------------------------------------------- /test/fixtures/input/list-after-list.text: -------------------------------------------------------------------------------- 1 | - item 2 | - item 3 | - item 4 | 5 | 1. item 6 | 1. item 7 | 1. item 8 | 9 | --- 10 | 11 | - item 12 | - item 13 | - item 14 | 1. item 15 | 1. item 16 | 1. item 17 | -------------------------------------------------------------------------------- /test/fixtures/input/strong-and-em-together-two.nooutput.text: -------------------------------------------------------------------------------- 1 | perform_complicated_task 2 | 3 | do_this_and_do_that_and_another_thing 4 | 5 | perform*complicated*task 6 | 7 | do*this*and*do*that*and*another*thing 8 | -------------------------------------------------------------------------------- /test/fixtures/input/heading.output.setext.text: -------------------------------------------------------------------------------- 1 | Heading 1 2 | ========= 3 | 4 | Heading 2 5 | --------- 6 | 7 | ### Heading 4 8 | 9 | #### Heading 4 10 | 11 | ##### Heading 5 12 | 13 | ###### Heading 6 14 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/defaults.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | position: true, 5 | gfm: true, 6 | commonmark: false, 7 | pedantic: false, 8 | blocks: require('./block-elements') 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/input/heading.output.close-atx.text: -------------------------------------------------------------------------------- 1 | # Heading 1 # 2 | 3 | ## Heading 2 ## 4 | 5 | ### Heading 4 ### 6 | 7 | #### Heading 4 #### 8 | 9 | ##### Heading 5 ##### 10 | 11 | ###### Heading 6 ###### 12 | -------------------------------------------------------------------------------- /test/fixtures/input/list-continuation.text: -------------------------------------------------------------------------------- 1 | 1. foo 2 | --- 3 | 4 | 5 | 1. foo 6 | ```js 7 | code(); 8 | ``` 9 | 10 | 11 | 1. [foo][] 12 | [foo]: http://google.com 13 | 14 | 15 | 1. [^foo] 16 | [^foo]: bar baz. 17 | -------------------------------------------------------------------------------- /packages/remark/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es2015"], 4 | "strict": true, 5 | "baseUrl": ".", 6 | "paths": { 7 | "remark": ["index.d.ts"] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-nested-parentheses.text: -------------------------------------------------------------------------------- 1 | [Hello](./world(and)hello(world)). 2 | 3 | [Hello](<./world(and)hello(world)>). 4 | 5 | ![Hello](./world(and)hello(world)). 6 | 7 | ![Hello](<./world(and)hello(world)>). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-text-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello [world]!](./hello-world.html). 2 | 3 | [Hello [world]!](<./hello-world.html>). 4 | 5 | ![Hello [world]!](./hello-world.html). 6 | 7 | ![Hello [world]!](<./hello-world.html>). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-parentheses.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html (Hello World!)). 2 | 3 | [Hello](<./world.html> (Hello World!)). 4 | 5 | ![Hello](./world.html (Hello World!)). 6 | 7 | ![Hello](<./world.html> (Hello World!)). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/mixed-indentation.text: -------------------------------------------------------------------------------- 1 | # Mixed spaces and tabs 2 | 3 | - Very long 4 | paragraph 5 | 6 | 1. Very long 7 | paragraph 8 | 9 | - Very long 10 | paragraph 11 | 12 | 1. Very long 13 | paragraph 14 | -------------------------------------------------------------------------------- /packages/remark/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var unified = require('unified') 4 | var parse = require('remark-parse') 5 | var stringify = require('remark-stringify') 6 | 7 | module.exports = unified().use(parse).use(stringify).freeze() 8 | -------------------------------------------------------------------------------- /test/fixtures/input/html-indented.text: -------------------------------------------------------------------------------- 1 |
2 | *hello* 3 |
4 | 5 | 6 | 7 | *hello* 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | alpha 18 | -------------------------------------------------------------------------------- /test/fixtures/input/links-text-mismatched-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello [world!](./hello-world.html). 2 | 3 | [Hello [world!](<./hello-world.html>). 4 | 5 | ![Hello [world!](./hello-world.html). 6 | 7 | ![Hello [world!](<./hello-world.html>). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-double-quotes.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html "Hello World!"). 2 | 3 | [Hello](<./world.html> "Hello World!"). 4 | 5 | ![Hello](./world.html "Hello World!"). 6 | 7 | ![Hello](<./world.html> "Hello World!"). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-single-quotes.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html 'Hello World!'). 2 | 3 | [Hello](<./world.html> 'Hello World!'). 4 | 5 | ![Hello](./world.html 'Hello World!'). 6 | 7 | ![Hello](<./world.html> 'Hello World!'). 8 | -------------------------------------------------------------------------------- /packages/remark-parse/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es2015"], 4 | "strict": true, 5 | "baseUrl": ".", 6 | "paths": { 7 | "remark-parse": ["index.d.ts"] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/list.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = list 4 | 5 | function list(node) { 6 | var fn = node.ordered ? this.visitOrderedItems : this.visitUnorderedItems 7 | return fn.call(this, node) 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/input/blockquotes-with-code-blocks.text: -------------------------------------------------------------------------------- 1 | > Example: 2 | > 3 | > sub status { 4 | > print "working"; 5 | > } 6 | > 7 | > Or: 8 | > 9 | > sub status { 10 | > return "working"; 11 | > } 12 | -------------------------------------------------------------------------------- /test/fixtures/input/links-reference-proto.text: -------------------------------------------------------------------------------- 1 | A [primary][toString], [secondary][constructor], and [tertiary][__proto__] link. 2 | 3 | [toString]: http://primary.com 4 | [__proto__]: http://tertiary.com 5 | [constructor]: http://secondary.com 6 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-empty-title-double-quotes.text: -------------------------------------------------------------------------------- 1 | [Hello]("World!"). 2 | 3 | [Hello]( "World!"). 4 | 5 | [World](<> "World!"). 6 | 7 | ![Hello]("World!"). 8 | 9 | ![Hello]( "World!"). 10 | 11 | ![World](<> "World!"). 12 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-empty-title-parentheses.text: -------------------------------------------------------------------------------- 1 | [Hello]((World!)). 2 | 3 | [Hello]( (World!)). 4 | 5 | [World](<> (World!)). 6 | 7 | ![Hello]((World!)). 8 | 9 | ![Hello]( (World!)). 10 | 11 | ![World](<> (World!)). 12 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-empty-title-single-quotes.text: -------------------------------------------------------------------------------- 1 | [Hello]('World!'). 2 | 3 | [Hello]( 'World!'). 4 | 5 | [World](<> 'World!'). 6 | 7 | ![Hello]('World!'). 8 | 9 | ![Hello]( 'World!'). 10 | 11 | ![World](<> 'World!'). 12 | -------------------------------------------------------------------------------- /test/fixtures/input/tricky-list.text: -------------------------------------------------------------------------------- 1 | **hello** _world_ 2 | 3 | * hello world 4 | 5 | **hello** _world_ 6 | 7 | * hello world 8 | 9 | **hello** _world_ 10 | 11 | * Hello world 12 | 13 | **hello** _world_ 14 | 15 | * hello world 16 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/table-cell.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = tableCell 4 | 5 | var lineFeed = /\r?\n/g 6 | 7 | function tableCell(node) { 8 | return this.all(node).join('').replace(lineFeed, ' ') 9 | } 10 | -------------------------------------------------------------------------------- /packages/remark-stringify/types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es2015"], 4 | "strict": true, 5 | "baseUrl": ".", 6 | "paths": { 7 | "remark-stringify": ["index.d.ts"] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/input/links-text-escaped-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello \[world\]!](./hello-world.html). 2 | 3 | [Hello \[world\]!](<./hello-world.html>). 4 | 5 | ![Hello \[world\]!](./hello-world.html). 6 | 7 | ![Hello \[world\]!](<./hello-world.html>). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code-initial-final-newlines.text: -------------------------------------------------------------------------------- 1 | Initial: 2 | 3 | ``` 4 | 5 | 6 | 123 7 | ``` 8 | 9 | Final: 10 | 11 | ``` 12 | 123 13 | 14 | 15 | ``` 16 | 17 | Both: 18 | 19 | ``` 20 | 21 | 22 | 123 23 | 24 | 25 | ``` 26 | -------------------------------------------------------------------------------- /test/fixtures/input/heading-in-blockquote.text: -------------------------------------------------------------------------------- 1 | > A blockquote 2 | with some more text. 3 | 4 | A normal paragraph. 5 | 6 | > A blockquote followed by a horizontal rule (in CommonMark). 7 | --- 8 | 9 | > A heading in a blockquote 10 | > --- 11 | -------------------------------------------------------------------------------- /test/fixtures/input/link-in-link.text: -------------------------------------------------------------------------------- 1 | # [mailto:test@example.com](http://shields.io) 2 | 3 | [https://travis-ci.org/wooorm/mdast](https://travis-ci.org/wooorm/mdast "mdast") 4 | 5 | [[](http://example.com "An example")](http://example.com "An example") 6 | -------------------------------------------------------------------------------- /test/fixtures/input/nested-references.text: -------------------------------------------------------------------------------- 1 | This nested image should work: 2 | 3 | [![Foo][bar]][baz] 4 | 5 | This nested link should not work: 6 | 7 | [[Foo][bar]][baz] 8 | 9 | [bar]: https://bar.com "bar" 10 | [baz]: https://baz.com "baz" 11 | -------------------------------------------------------------------------------- /test/fixtures/input/auto-link-url-invalid.text: -------------------------------------------------------------------------------- 1 | http:// hello 2 | > [1]: hello 3 | 4 | * * * 5 | 6 | > hello 7 | [2]: hello 8 | 9 | 10 | * hello 11 | * [3]: hello 12 | 13 | 14 | * hello 15 | [4]: hello 16 | 17 | 18 | > foo 19 | > bar 20 | [1]: foo 21 | > bar 22 | -------------------------------------------------------------------------------- /test/fixtures/input/definition-newline.text: -------------------------------------------------------------------------------- 1 | [baz]: /url ( 2 | ) 3 | 4 | [foo]: /url " 5 | " 6 | 7 | [bar]: /url ' 8 | ' 9 | [baz]: /url (foo 10 | bar) 11 | 12 | [baz]: /url "foo 13 | bar" 14 | 15 | [baz]: /url 'foo 16 | bar' 17 | 18 | [baz]: /url 'foo -------------------------------------------------------------------------------- /test/fixtures/input/html-advanced.text: -------------------------------------------------------------------------------- 1 | Simple block on one line: 2 | 3 |
foo
4 | 5 | And nested without indentation: 6 | 7 |
8 |
9 |
10 | foo 11 |
12 |
13 |
14 |
bar
15 |
16 | -------------------------------------------------------------------------------- /test/fixtures/input/double-link.text: -------------------------------------------------------------------------------- 1 |

Already linked: http://example.com/.

2 | 3 | Already linked: [http://example.com/](http://example.com/). 4 | 5 | Already linked: **http://example.com/**. 6 | -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code-empty.text: -------------------------------------------------------------------------------- 1 | Normal with language tag: 2 | 3 | ```js 4 | ``` 5 | 6 | With white space: 7 | 8 | ``` bash 9 | ``` 10 | 11 | With very long fences: 12 | 13 | `````` 14 | `````` 15 | 16 | With nothing: 17 | 18 | ``` 19 | ``` 20 | -------------------------------------------------------------------------------- /test/fixtures/input/table-escaped-pipes.nooutput.text: -------------------------------------------------------------------------------- 1 | | First | Second | third | 2 | | ----- | ------ | ----- | 3 | | first | second | third | 4 | | first | second \| second | third \| 5 | | first | second \\| third \\| 6 | | first | second \\\| second | third \\\| 7 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/delete.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = strikethrough 4 | 5 | var tilde = '~' 6 | 7 | var fence = tilde + tilde 8 | 9 | function strikethrough(node) { 10 | return fence + this.all(node).join('') + fence 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-double-quotes-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html "Hello "World" Hello!"). 2 | 3 | [Hello](<./world.html> "Hello "World" Hello!"). 4 | 5 | ![Hello](./world.html "Hello "World" Hello!"). 6 | 7 | ![Hello](<./world.html> "Hello "World" Hello!"). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-single-quotes-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html 'Hello 'World' Hello!'). 2 | 3 | [Hello](<./world.html> 'Hello 'World' Hello!'). 4 | 5 | ![Hello](./world.html 'Hello 'World' Hello!'). 6 | 7 | ![Hello](<./world.html> 'Hello 'World' Hello!'). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/definition-unclosed-attribute.text: -------------------------------------------------------------------------------- 1 | 2 | [baz]: /url (there 3 | 4 | [foo]: /url "there 5 | 6 | [bar]: /url 'there 7 | 8 | [baz]: url ( 9 | 10 | [foo]: url " 11 | 12 | [bar]: /url ' 13 | 14 | [baz]: ( 15 | 16 | [foo]: " 17 | 18 | [bar]: ' -------------------------------------------------------------------------------- /test/fixtures/input/horizontal-rules-adjacent.text: -------------------------------------------------------------------------------- 1 | *** 2 | --- 3 | ___ 4 | 5 | The three asterisks are not a Setext header. 6 | 7 | This is a paragraph. 8 | *** 9 | 10 | This is another paragraph. 11 | ___ 12 | 13 | But this is a secondary heading. 14 | --- 15 | 16 | --- 17 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-double-quotes-mismatched-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html "Hello "World Hello!"). 2 | 3 | [Hello](<./world.html> "Hello "World Hello!"). 4 | 5 | ![Hello](./world.html "Hello "World Hello!"). 6 | 7 | ![Hello](<./world.html> "Hello "World Hello!"). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-single-quotes-mismatched-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html 'Hello 'World Hello!'). 2 | 3 | [Hello](<./world.html> 'Hello 'World Hello!'). 4 | 5 | ![Hello](./world.html 'Hello 'World Hello!'). 6 | 7 | ![Hello](<./world.html> 'Hello 'World Hello!'). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-entities.text: -------------------------------------------------------------------------------- 1 | [Hello](http://www.example.com?param=1®ion=here). 2 | 3 | [World](). 4 | 5 | ![Hello](http://www.example.com?param=1®ion=here). 6 | 7 | ![World](). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-double-quotes-escaped-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html "Hello \"World\" Hello!"). 2 | 3 | [Hello](<./world.html> "Hello \"World\" Hello!"). 4 | 5 | ![Hello](./world.html "Hello \"World\" Hello!"). 6 | 7 | ![Hello](<./world.html> "Hello \"World\" Hello!"). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-single-quotes-escaped-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html 'Hello \'World\' Hello!'). 2 | 3 | [Hello](<./world.html> 'Hello \'World\' Hello!'). 4 | 5 | ![Hello](./world.html 'Hello \'World\' Hello!'). 6 | 7 | ![Hello](<./world.html> 'Hello \'World\' Hello!'). 8 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/macro/compile.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var compact = require('mdast-util-compact') 4 | 5 | module.exports = compile 6 | 7 | // Stringify the given tree. 8 | function compile() { 9 | return this.visit(compact(this.tree, this.options.commonmark)) 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/input/auto-link-output.output.text: -------------------------------------------------------------------------------- 1 | Link: . 2 | 3 | Link to an email: [somename@example.com](mailto:somename@example.com). 4 | 5 | Link without protocol, which should not render as an auto-link 6 | because they are easily mistaken for HTML: [google.com](google.com). 7 | -------------------------------------------------------------------------------- /test/fixtures/input/code-blocks.text: -------------------------------------------------------------------------------- 1 | code block on the first line 2 | 3 | Regular text. 4 | 5 | code block indented by spaces 6 | 7 | Regular text. 8 | 9 | the lines in this block 10 | all contain trailing spaces 11 | 12 | Regular Text. 13 | 14 | code block on the last line 15 | -------------------------------------------------------------------------------- /test/fixtures/input/table-invalid-alignment.text: -------------------------------------------------------------------------------- 1 | Missing alignment characters: 2 | 3 | | a | b | c | 4 | | |---|---| 5 | | d | e | f | 6 | 7 | * * * 8 | 9 | | a | b | c | 10 | |---|---| | 11 | | d | e | f | 12 | 13 | Invalid characters: 14 | 15 | | a | b | c | 16 | |---|-*-|---| 17 | | d | e | f | 18 | -------------------------------------------------------------------------------- /test/fixtures/tree/empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [], 4 | "position": { 5 | "start": { 6 | "line": 1, 7 | "column": 1, 8 | "offset": 0 9 | }, 10 | "end": { 11 | "line": 1, 12 | "column": 1, 13 | "offset": 0 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-double-quotes-entity-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html "Hello "World" Hello!"). 2 | 3 | [Hello](<./world.html> "Hello "World" Hello!"). 4 | 5 | ![Hello](./world.html "Hello "World" Hello!"). 6 | 7 | ![Hello](<./world.html> "Hello "World" Hello!"). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-single-quotes-entity-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html "Hello 'World' Hello!"). 2 | 3 | [Hello](<./world.html> "Hello 'World' Hello!"). 4 | 5 | ![Hello](./world.html "Hello 'World' Hello!"). 6 | 7 | ![Hello](<./world.html> "Hello 'World' Hello!"). 8 | -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code.text: -------------------------------------------------------------------------------- 1 | ``` js 2 | var a = 'hello'; 3 | console.log(a + ' world'); 4 | ``` 5 | 6 | ~~~bash 7 | echo "hello, ${WORLD}" 8 | ~~~ 9 | 10 | ```````longfence 11 | Q: What do you call a tall person who sells stolen goods? 12 | ``````` 13 | 14 | ~~~~~~~~~~ ManyTildes 15 | A longfence! 16 | ~~~~~~~~~~ 17 | -------------------------------------------------------------------------------- /test/fixtures/input/breaks-hard.text: -------------------------------------------------------------------------------- 1 | These are not breaks: 2 | 3 | Look at the 4 | pretty line 5 | breaks. 6 | 7 | These are breaks: 8 | 9 | Look at the 10 | pretty line 11 | breaks. 12 | 13 | In `commonmark: true` mode, an escaped newline character is exposed as a `break` node: 14 | 15 | Look at the\ 16 | pretty line\ 17 | breaks. 18 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/break.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | function locate(value, fromIndex) { 6 | var index = value.indexOf('\n', fromIndex) 7 | 8 | while (index > fromIndex) { 9 | if (value.charAt(index - 1) !== ' ') { 10 | break 11 | } 12 | 13 | index-- 14 | } 15 | 16 | return index 17 | } 18 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/break.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = lineBreak 4 | 5 | var backslash = '\\' 6 | var lineFeed = '\n' 7 | var space = ' ' 8 | 9 | var commonmark = backslash + lineFeed 10 | var normal = space + space + lineFeed 11 | 12 | function lineBreak() { 13 | return this.options.commonmark ? commonmark : normal 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/input/heading-not-atx.text: -------------------------------------------------------------------------------- 1 | #This is not a heading, per CommonMark: 2 | 3 | Kramdown (GitHub) neither supports unspaced ATX-headings. 4 | 5 | ######## h7? 6 | 7 | ######### h8? 8 | 9 | ########## h9? 10 | 11 | More than six # characters is not a heading: 12 | -------------------------------------------------------------------------------- /test/fixtures/input/links-shortcut-references.text: -------------------------------------------------------------------------------- 1 | This is the [simple case]. 2 | 3 | [simple case]: /simple 4 | 5 | 6 | 7 | This one has a [line 8 | break]. 9 | 10 | This one has a [line 11 | break] with a line-ending space. 12 | 13 | [line break]: /foo 14 | 15 | 16 | [this] [that] and the [other] 17 | 18 | [this]: /this 19 | [that]: /that 20 | [other]: /other 21 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/util/normalize.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var collapseWhiteSpace = require('collapse-white-space') 4 | 5 | module.exports = normalize 6 | 7 | // Normalize an identifier. Collapses multiple white space characters into a 8 | // single space, and removes casing. 9 | function normalize(value) { 10 | return collapseWhiteSpace(value).toLowerCase() 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/input/auto-link-url.text: -------------------------------------------------------------------------------- 1 | This should be a link: http://example.com/hello-world. 2 | 3 | Also, subdomain should be a part of the link (http://foo.example.com/(hello[world])). 4 | 5 | So should this: mailto:foo@bar.com. 6 | 7 | And even with underscore http://domain.org/this_is_good. 8 | 9 | All links should work http://a.b, https://c.d, http://e.f, https://g.h. 10 | -------------------------------------------------------------------------------- /test/fixtures/input/no-positionals.nooutput.text: -------------------------------------------------------------------------------- 1 | This document tests for the working of `position: false` as a parse 2 | option. 3 | 4 | > Block-quotes 5 | > 6 | > * With list items. 7 | 8 | Another block-quote: 9 | 10 | > 1. And another list. 11 | 12 | Some [deeply **nested _elements_**](http://example.com) 13 | 14 | An entity: ©, and an warning entity: ©. 15 | -------------------------------------------------------------------------------- /test/fixtures/input/image-in-link.text: -------------------------------------------------------------------------------- 1 | # [![Unicorn approved](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](http://shields.io) 2 | 3 | [![Build Status](https://img.shields.io/travis/wooorm/mdast.svg?style=flat)](https://travis-ci.org/wooorm/mdast) 4 | 5 | [![Be Square](https://img.shields.io/badge/style-flat--squared-green.svg?style=flat-square)](http://example.com "An example") 6 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/root.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = root 4 | 5 | var lineFeed = '\n' 6 | 7 | // Stringify a root. 8 | // Adds a final newline to ensure valid POSIX files. */ 9 | function root(node) { 10 | var doc = this.block(node) 11 | 12 | if (doc.charAt(doc.length - 1) !== lineFeed) { 13 | doc += lineFeed 14 | } 15 | 16 | return doc 17 | } 18 | -------------------------------------------------------------------------------- /test/fixtures/input/hr-list-break.text: -------------------------------------------------------------------------------- 1 | * hello world 2 | * how are 3 | * * * 4 | you today? 5 | 6 | 7 | The above asterisks do split the list, but the below ones do not. 8 | 9 | 10 | - hello world 11 | - how are 12 | - * * * 13 | you today? 14 | 15 | 16 | + Neither do these 17 | + how are 18 | + * * 19 | you today? 20 | 21 | 22 | - But these do 23 | - how are 24 | - - - - 25 | you today? 26 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-mismatched-parentheses.text: -------------------------------------------------------------------------------- 1 | [Hello](./world(and-hello(world)). 2 | 3 | [Hello](<./world(and-hello(world)>). 4 | 5 | [Hello](./world(and)helloworld)). 6 | 7 | [Hello](<./world(and)helloworld)>). 8 | 9 | ![Hello](./world(and-hello(world)). 10 | 11 | ![Hello](<./world(and-hello(world)>). 12 | 13 | ![Hello](./world(and)helloworld)). 14 | 15 | ![Hello](<./world(and)helloworld)>). 16 | -------------------------------------------------------------------------------- /test/fixtures/input/links-inline-style.text: -------------------------------------------------------------------------------- 1 | Just a [URL](/url/). 2 | 3 | [URL and title](/url/ "title"). 4 | 5 | [URL and title](/url/ "title preceded by two spaces"). 6 | 7 | [URL and title](/url/ "title preceded by a tab"). 8 | 9 | [URL and title](/url/ "title has spaces afterward" ). 10 | 11 | [URL and title]( /url/has space ). 12 | 13 | [URL and title]( /url/has space/ "url has space and title"). 14 | 15 | [Empty](). 16 | -------------------------------------------------------------------------------- /test/fixtures/input/tabs.text: -------------------------------------------------------------------------------- 1 | + this is a list item 2 | indented with tabs 3 | 4 | + this is a list item 5 | indented with spaces 6 | 7 | Code: 8 | 9 | this code block is indented by one tab 10 | 11 | And: 12 | 13 | this code block is indented by two tabs 14 | 15 | And: 16 | 17 | + this is an example list item 18 | indented with tabs 19 | 20 | + this is an example list item 21 | indented with spaces 22 | -------------------------------------------------------------------------------- /test/fixtures/input/blockquote-lazy-fence.text: -------------------------------------------------------------------------------- 1 | > ``` 2 | > aNormalCodeBlockInABlockqoute(); 3 | > ``` 4 | 5 | A paragraph. 6 | 7 | > ``` 8 | thisIsAlsoSomeCodeInABlockquote(); 9 | > ``` 10 | 11 | A paragraph. 12 | 13 | > ``` 14 | aNonTerminatedCodeBlockInABlockquote(); 15 | ``` 16 | aNewCodeBlockFollowingTheBlockQuote(); 17 | ``` 18 | 19 | A paragraph. 20 | 21 | > Something in a blockquote. 22 | ``` 23 | aNewCodeBlock(); 24 | ``` 25 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-escaped-parentheses.text: -------------------------------------------------------------------------------- 1 | [Hello](./world\(and-hello\(world\)). 2 | 3 | [Hello](<./world\(and-hello\(world\)>). 4 | 5 | [Hello](./world\(and\)helloworld\)). 6 | 7 | [Hello](<./world\(and\)helloworld\)>). 8 | 9 | ![Hello](./world\(and-hello\(world\)). 10 | 11 | ![Hello](<./world\(and-hello\(world\)>). 12 | 13 | ![Hello](./world\(and\)helloworld\)). 14 | 15 | ![Hello](<./world\(and\)helloworld\)>). 16 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/macro/all.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = all 4 | 5 | // Visit all children of `parent`. 6 | function all(parent) { 7 | var self = this 8 | var children = parent.children 9 | var length = children.length 10 | var results = [] 11 | var index = -1 12 | 13 | while (++index < length) { 14 | results[index] = self.visit(children[index], parent) 15 | } 16 | 17 | return results 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/input/tabs-and-spaces.text: -------------------------------------------------------------------------------- 1 | + this is a list item 2 | indented with tabs 3 | 4 | + this is a list item 5 | indented with spaces 6 | 7 | Code: 8 | 9 | this code block is indented by one tab 10 | 11 | And: 12 | 13 | this code block is indented by two tabs 14 | 15 | And: 16 | 17 | + this is an example list item 18 | indented with tabs 19 | 20 | + this is an example list item 21 | indented with spaces 22 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/link.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | function locate(value, fromIndex) { 6 | var link = value.indexOf('[', fromIndex) 7 | var image = value.indexOf('![', fromIndex) 8 | 9 | if (image === -1) { 10 | return link 11 | } 12 | 13 | // Link can never be `-1` if an image is found, so we don’t need to check 14 | // for that :) 15 | return link < image ? link : image 16 | } 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - lts/dubnium 4 | - node 5 | sudo: false 6 | deploy: 7 | provider: releases 8 | skip_cleanup: true 9 | api_key: 10 | secure: GCfTZxoqpp1tMmslM5MTI13BLv+bvFhZUuhX+dQFbcVYODQKUjnUj9EBF10PJSTpYqm3GnGpxEoQ6RAUVxlH7rBQUFm4czaZPPgCDSZT3B8pszmQkl1aRyvdmXFoKfyNhFUwBUSsoBpM92wp/UrgIZ/CI0jLoIZbCwn4KH02rf8= 11 | file: 12 | - 'remark.js' 13 | - 'remark.min.js' 14 | on: 15 | tags: true 16 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/emphasis.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | function locate(value, fromIndex) { 6 | var asterisk = value.indexOf('*', fromIndex) 7 | var underscore = value.indexOf('_', fromIndex) 8 | 9 | if (underscore === -1) { 10 | return asterisk 11 | } 12 | 13 | if (asterisk === -1) { 14 | return underscore 15 | } 16 | 17 | return underscore < asterisk ? underscore : asterisk 18 | } 19 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/strong.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | function locate(value, fromIndex) { 6 | var asterisk = value.indexOf('**', fromIndex) 7 | var underscore = value.indexOf('__', fromIndex) 8 | 9 | if (underscore === -1) { 10 | return asterisk 11 | } 12 | 13 | if (asterisk === -1) { 14 | return underscore 15 | } 16 | 17 | return underscore < asterisk ? underscore : asterisk 18 | } 19 | -------------------------------------------------------------------------------- /packages/remark-parse/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "max-line-length": false, 5 | "no-redundant-jsdoc": false, 6 | "no-void-expression": false, 7 | "only-arrow-functions": false, 8 | "semicolon": false, 9 | "unified-signatures": false, 10 | "whitespace": false, 11 | "no-unnecessary-generics": false, 12 | "strict-export-declare-modifiers": false 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/remark-stringify/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "max-line-length": false, 5 | "no-redundant-jsdoc": false, 6 | "no-void-expression": false, 7 | "only-arrow-functions": false, 8 | "semicolon": false, 9 | "unified-signatures": false, 10 | "whitespace": false, 11 | "no-unnecessary-generics": false, 12 | "strict-export-declare-modifiers": false 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/input/literal-email.text: -------------------------------------------------------------------------------- 1 | example1 (1234567@example.com) 2 | example1 (mailto:1234567@example.com) 3 | 4 | Lorem foo@bar.baz ipsum. 5 | 6 | alpha@bravo+charlie.delta isn’t valid, but echo+foxtrot@golf.hotel is. 7 | 8 | Valid: a.b-c_d@a.b 9 | 10 | Valid, but the dot is not part of the email: a.b-c_d@a.b. 11 | 12 | Not valid: a.b-c_d@a.b- 13 | 14 | Not valid: a.b-c_d@a.b_ 15 | 16 | Not valid: alpha@bravo. 17 | 18 | <foo@example.com 19 | -------------------------------------------------------------------------------- /packages/remark-parse/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var unherit = require('unherit') 4 | var xtend = require('xtend') 5 | var Parser = require('./lib/parser.js') 6 | 7 | module.exports = parse 8 | parse.Parser = Parser 9 | 10 | function parse(options) { 11 | var settings = this.data('settings') 12 | var Local = unherit(Parser) 13 | 14 | Local.prototype.options = xtend(Local.prototype.options, settings, options) 15 | 16 | this.Parser = Local 17 | } 18 | -------------------------------------------------------------------------------- /test/fixtures/input/auto-link.text: -------------------------------------------------------------------------------- 1 | Link: . 2 | 3 | Link to an email: . 4 | 5 | Link to an email: . 6 | 7 | With an ampersand: 8 | 9 | * In a list? 10 | * 11 | * It should. 12 | 13 | > Blockquoted: 14 | 15 | Auto-links should not occur here: `` 16 | 17 | or here: 18 | -------------------------------------------------------------------------------- /packages/remark-stringify/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var unherit = require('unherit') 4 | var xtend = require('xtend') 5 | var Compiler = require('./lib/compiler.js') 6 | 7 | module.exports = stringify 8 | stringify.Compiler = Compiler 9 | 10 | function stringify(options) { 11 | var Local = unherit(Compiler) 12 | Local.prototype.options = xtend( 13 | Local.prototype.options, 14 | this.data('settings'), 15 | options 16 | ) 17 | this.Compiler = Local 18 | } 19 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/image-reference.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var label = require('../util/label') 4 | 5 | module.exports = imageReference 6 | 7 | var leftSquareBracket = '[' 8 | var rightSquareBracket = ']' 9 | var exclamationMark = '!' 10 | 11 | function imageReference(node) { 12 | return ( 13 | exclamationMark + 14 | leftSquareBracket + 15 | (this.encode(node.alt, node) || '') + 16 | rightSquareBracket + 17 | label(node) 18 | ) 19 | } 20 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/text.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = text 4 | 5 | // Stringify text. 6 | // Supports named entities in `settings.encode: true` mode: 7 | // 8 | // ```markdown 9 | // AT&T 10 | // ``` 11 | // 12 | // Supports numbered entities in `settings.encode: numbers` mode: 13 | // 14 | // ```markdown 15 | // AT&T 16 | // ``` 17 | function text(node, parent) { 18 | return this.encode(this.escape(node.value, node, parent), node) 19 | } 20 | -------------------------------------------------------------------------------- /packages/remark/types/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "dtslint/dtslint.json", 3 | "rules": { 4 | "max-line-length": false, 5 | "no-redundant-jsdoc": false, 6 | "no-void-expression": false, 7 | "only-arrow-functions": false, 8 | "semicolon": false, 9 | "unified-signatures": false, 10 | "whitespace": false, 11 | "interface-over-type-literal": false, 12 | "no-unnecessary-generics": false, 13 | "strict-export-declare-modifiers": false 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/fixtures/input/tables-with-pipes-and-code.text: -------------------------------------------------------------------------------- 1 | Grave accent in cell: 2 | 3 | | A | B | 4 | |--------------|---| 5 | | ` | C | 6 | 7 | Escaped grave accent in inline code in cell (is not an escape): 8 | 9 | | A | 10 | |-----| 11 | | `\` | 12 | 13 | “Empty” inline code: 14 | 15 | | 1 | 2 | 3 | 16 | |---|------|----| 17 | | a | `` | | 18 | | b | `` | `` | 19 | | c | ` | ` | 20 | | d | `|` | 21 | | e | `\|` | | 22 | | f | \| | | 23 | -------------------------------------------------------------------------------- /test/fixtures/input/list-item-indent.list-item-indent=1.output.text: -------------------------------------------------------------------------------- 1 | 1. foo bar baz. 2 | 3 | 4 | 5 | 99. foo bar baz. 6 | 7 | 8 | 9 | 999. foo bar baz. 10 | 11 | 12 | 13 | 1. foo bar baz. 14 | foo bar baz. 15 | 16 | 17 | 18 | 99. foo bar baz. 19 | foo bar baz. 20 | 21 | 22 | 23 | 999. foo bar baz. 24 | foo bar baz. 25 | 26 | 27 | 28 | - foo bar baz. 29 | 30 | 31 | 32 | - foo bar baz. 33 | foo bar baz. 34 | -------------------------------------------------------------------------------- /test/fixtures/input/links-title-unclosed.text: -------------------------------------------------------------------------------- 1 | [Hello](./world.html 'Hello 2 | 3 | [Hello](<./world.html> 'Hello 4 | 5 | ![Hello](./world.html 'Hello 6 | 7 | ![Hello](<./world.html> 'Hello 8 | 9 | [Hello](./world.html "Hello 10 | 11 | [Hello](<./world.html> "Hello 12 | 13 | ![Hello](./world.html "Hello 14 | 15 | ![Hello](<./world.html> "Hello 16 | 17 | [Hello](./world.html (Hello 18 | 19 | [Hello](<./world.html> (Hello 20 | 21 | ![Hello](./world.html (Hello 22 | 23 | ![Hello](<./world.html> (Hello 24 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/strong.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var repeat = require('repeat-string') 4 | 5 | module.exports = strong 6 | 7 | // Stringify a `strong`. 8 | // 9 | // The marker used is configurable by `strong`, which defaults to an asterisk 10 | // (`'*'`) but also accepts an underscore (`'_'`): 11 | // 12 | // ```markdown 13 | // __foo__ 14 | // ``` 15 | function strong(node) { 16 | var marker = repeat(this.options.strong, 2) 17 | return marker + this.all(node).join('') + marker 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/input/links-text-entity-delimiters.text: -------------------------------------------------------------------------------- 1 | [Hello [world]!](./hello-world.html). 2 | 3 | [Hello [world]!](<./hello-world.html>). 4 | 5 | ![Hello [world]!](./hello-world.html). 6 | 7 | ![Hello [world]!](<./hello-world.html>). 8 | 9 | [Hello [world]!](./hello-world.html). 10 | 11 | [Hello [world]!](<./hello-world.html>). 12 | 13 | ![Hello [world]!](./hello-world.html). 14 | 15 | ![Hello [world]!](<./hello-world.html>). 16 | -------------------------------------------------------------------------------- /test/fixtures/input/list-indentation.nooutput.text: -------------------------------------------------------------------------------- 1 | - Hello 1a 2 | 3 | World 1a. 4 | 5 | - Hello 1b 6 | 7 | World 1b. 8 | 9 | - Hello 2a 10 | 11 | World 2a. 12 | 13 | - Hello 2b 14 | 15 | World 2b. 16 | 17 | - Hello 3a 18 | 19 | World 3a. 20 | 21 | - Hello 3b 22 | 23 | World 3b. 24 | 25 | - Hello 4a 26 | 27 | World 4a. 28 | 29 | - Hello 4b 30 | 31 | World 4b. 32 | 33 | - Hello 5a 34 | 35 | World 5a. 36 | 37 | - Hello 5b 38 | 39 | World 5b. 40 | -------------------------------------------------------------------------------- /test/fixtures/input/list-item-indent.list-item-indent=mixed.output.text: -------------------------------------------------------------------------------- 1 | 1. foo bar baz. 2 | 3 | 4 | 5 | 99. foo bar baz. 6 | 7 | 8 | 9 | 999. foo bar baz. 10 | 11 | 12 | 13 | 1. foo bar baz. 14 | foo bar baz. 15 | 16 | 17 | 18 | 99. foo bar baz. 19 | foo bar baz. 20 | 21 | 22 | 23 | 999. foo bar baz. 24 | foo bar baz. 25 | 26 | 27 | 28 | - foo bar baz. 29 | 30 | 31 | 32 | - foo bar baz. 33 | foo bar baz. 34 | -------------------------------------------------------------------------------- /test/fixtures/input/amps-and-angles-encoding.text: -------------------------------------------------------------------------------- 1 | AT&T has an ampersand in their name. 2 | 3 | AT&T is another way to write it. 4 | 5 | This & that. 6 | 7 | 4 < 5. 8 | 9 | 6 > 5. 10 | 11 | Here's a [link] [1] with an ampersand in the URL. 12 | 13 | Here's a link with an amersand in the link text: [AT&T] [2]. 14 | 15 | Here's an inline [link](/script?foo=1&bar=2). 16 | 17 | Here's an inline [link](). 18 | 19 | 20 | [1]: http://example.com/?foo=1&bar=2 21 | [2]: http://att.com/ "AT&T" 22 | -------------------------------------------------------------------------------- /test/fixtures/input/block-elements.text: -------------------------------------------------------------------------------- 1 | * Different lists should receive two newline characters 2 | between them. 3 | 4 | 5 | * This is another list. 6 | 7 | > * The same goes for lists in block quotes. 8 | > 9 | > 10 | > * This is another list. 11 | 12 | * And for lists in lists: 13 | 14 | 1. First sublist. 15 | 16 | 17 | 1. Second sublist. 18 | 19 | And for lists followed by indented code blocks: 20 | 21 | * This is a paragraph in a list 22 | 23 | 24 | And this is code(); 25 | -------------------------------------------------------------------------------- /test/fixtures/input/code-block-indentation.nooutput.text: -------------------------------------------------------------------------------- 1 | Fenced code blocks are normally not exdented, however, 2 | when the initial fence is indented by spaces, the value of 3 | the code is exdented by up to that amount of spaces. 4 | 5 | ``` 6 | This is a code block... 7 | 8 | ...which is not exdented. 9 | ``` 10 | 11 | But... 12 | 13 | ``` 14 | This one... 15 | 16 | ...is. 17 | ``` 18 | 19 | And... 20 | 21 | ``` 22 | So is this... 23 | 24 | ...one. 25 | ``` 26 | -------------------------------------------------------------------------------- /test/fixtures/input/list-item-indent.list-item-indent=tab.output.text: -------------------------------------------------------------------------------- 1 | 1. foo bar baz. 2 | 3 | 4 | 5 | 99. foo bar baz. 6 | 7 | 8 | 9 | 999. foo bar baz. 10 | 11 | 12 | 13 | 1. foo bar baz. 14 | foo bar baz. 15 | 16 | 17 | 18 | 99. foo bar baz. 19 | foo bar baz. 20 | 21 | 22 | 23 | 999. foo bar baz. 24 | foo bar baz. 25 | 26 | 27 | 28 | - foo bar baz. 29 | 30 | 31 | 32 | - foo bar baz. 33 | foo bar baz. 34 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/macro/one.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = one 4 | 5 | function one(node, parent) { 6 | var self = this 7 | var visitors = self.visitors 8 | 9 | // Fail on unknown nodes. 10 | if (typeof visitors[node.type] !== 'function') { 11 | self.file.fail( 12 | new Error( 13 | 'Missing compiler for node of type `' + node.type + '`: `' + node + '`' 14 | ), 15 | node 16 | ) 17 | } 18 | 19 | return visitors[node.type].call(self, node, parent) 20 | } 21 | -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code-info-string.text: -------------------------------------------------------------------------------- 1 | Normal with language tag: 2 | 3 | ```js this is an info string 4 | ``` 5 | 6 | With white space: 7 | 8 | ``` bash info 9 | ``` 10 | 11 | With curly braces: 12 | 13 | ``````lang{info} 14 | `````` 15 | 16 | With nothing: 17 | 18 | ``` 19 | ``` 20 | 21 | With several streaks of white space: 22 | 23 | ``` bash info string 24 | ``` 25 | 26 | With tabs as white space: 27 | 28 | ``` bash info 29 | ``` 30 | 31 | With spaces as white space: 32 | 33 | ``` bash info 34 | ``` 35 | -------------------------------------------------------------------------------- /test/fixtures/input/auto-link-syntax.text: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/fixtures/input/ordered-with-parentheses.text: -------------------------------------------------------------------------------- 1 | ## Ordered 2 | 3 | Tight: 4 | 5 | 1) First 6 | 2) Second 7 | 3) Third 8 | 9 | and: 10 | 11 | 1) One 12 | 2) Two 13 | 3) Three 14 | 15 | Loose using tabs: 16 | 17 | 1) First 18 | 19 | 2) Second 20 | 21 | 3) Third 22 | 23 | and using spaces: 24 | 25 | 1) One 26 | 27 | 2) Two 28 | 29 | 3) Three 30 | 31 | Multiple paragraphs: 32 | 33 | 1) Item 1, graf one. 34 | 35 | Item 2. graf two. The quick brown fox jumped over the lazy dog's 36 | back. 37 | 38 | 2) Item 2. 39 | 40 | 3) Item 3. 41 | -------------------------------------------------------------------------------- /test/fixtures/input/html-comments.text: -------------------------------------------------------------------------------- 1 | Paragraph one. 2 | 3 | 4 | 5 | 8 | 9 | What follows is not an HTML comment because it contains 10 | two consecutive dashes: 11 | . 12 | 13 | 14 | 15 | But this is fine (in commonmark): 16 | 17 | 18 | 19 | And, this is wrong (in commonmark): 20 | 21 | --> 22 | 23 | The end. 24 | -------------------------------------------------------------------------------- /test/fixtures/input/loose-lists.text: -------------------------------------------------------------------------------- 1 | * hello 2 | world 3 | 4 | how 5 | are 6 | * you 7 | 8 | 9 | 10 | better behavior: 11 | 12 | * hello 13 | * world 14 | how 15 | 16 | are 17 | you 18 | 19 | * today 20 | * hi 21 | 22 | 23 | 24 | * hello 25 | 26 | * world 27 | * hi 28 | 29 | 30 | 31 | * hello 32 | * world 33 | 34 | * hi 35 | 36 | 37 | 38 | * hello 39 | * world 40 | 41 | how 42 | * hi 43 | 44 | 45 | 46 | * hello 47 | * world 48 | * how 49 | are 50 | 51 | 52 | 53 | * hello 54 | * world 55 | 56 | * how 57 | are 58 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/blockquote.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = blockquote 4 | 5 | var lineFeed = '\n' 6 | var space = ' ' 7 | var greaterThan = '>' 8 | 9 | function blockquote(node) { 10 | var values = this.block(node).split(lineFeed) 11 | var result = [] 12 | var length = values.length 13 | var index = -1 14 | var value 15 | 16 | while (++index < length) { 17 | value = values[index] 18 | result[index] = (value ? space : '') + value 19 | } 20 | 21 | return greaterThan + result.join(lineFeed + greaterThan) 22 | } 23 | -------------------------------------------------------------------------------- /test/fixtures/input/links.output.noreference-links.text: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit [amet](http://amet.com "Amet"), consectetur adipiscing elit. Praesent dictum purus ullamcorper ligula semper pellentesque. 2 | 3 | Nulla [finibus](http://finibus.com "Finibus") neque et diam rhoncus convallis. Nam dictum sapien nec sem ultrices fermentum. Nulla [facilisi](http://facilisi.com "Facilisi"). In et feugiat massa. 4 | 5 | Donec sed sodales metus, ut aliquet quam. Suspendisse nec ipsum risus. Interdum et malesuada fames ac ante ipsum primis in [faucibus](http://faucibus.com "Faucibus"). 6 | -------------------------------------------------------------------------------- /test/fixtures/input/toplevel-paragraphs.text: -------------------------------------------------------------------------------- 1 | hello world 2 | how are you 3 | how are you 4 | 5 | hello world 6 | ``` 7 | how are you 8 | ``` 9 | 10 | hello world 11 | * * * 12 | 13 | hello world 14 | # how are you 15 | 16 | hello world 17 | how are you 18 | =========== 19 | 20 | hello world 21 | > how are you 22 | 23 | hello world 24 | * how are you 25 | 26 | hello world 27 |
how are you
28 | 29 | hello world 30 | how are you 31 | 32 | hello [world][how] 33 | [how]: /are/you 34 | 35 |
hello
36 | 37 | hello 38 | -------------------------------------------------------------------------------- /packages/remark/types/index.d.ts: -------------------------------------------------------------------------------- 1 | // TypeScript Version: 3.0 2 | 3 | import unified = require('unified') 4 | import remarkParse = require('remark-parse') 5 | import remarkStringify = require('remark-stringify') 6 | 7 | declare namespace remark { 8 | type RemarkOptions = remarkParse.RemarkParseOptions & 9 | remarkStringify.RemarkStringifyOptions 10 | 11 | type PartialRemarkOptions = remarkParse.PartialRemarkParseOptions & 12 | remarkStringify.PartialRemarkStringifyOptions 13 | } 14 | 15 | declare function remark(): unified.Processor 16 | 17 | export = remark 18 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/util/enclose-title.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = enclose 4 | 5 | var quotationMark = '"' 6 | var apostrophe = "'" 7 | 8 | // There is currently no way to support nested delimiters across Markdown.pl, 9 | // CommonMark, and GitHub (RedCarpet). The following code supports Markdown.pl 10 | // and GitHub. 11 | // CommonMark is not supported when mixing double- and single quotes inside a 12 | // title. 13 | function enclose(title) { 14 | var delimiter = 15 | title.indexOf(quotationMark) === -1 ? quotationMark : apostrophe 16 | return delimiter + title + delimiter 17 | } 18 | -------------------------------------------------------------------------------- /test/fixtures/input/code-spans.text: -------------------------------------------------------------------------------- 1 | `` 2 | 3 | Fix for backticks within HTML tag: like this 4 | 5 | Here's how you put `` `backticks` `` in a code span. 6 | 7 | Empty code spans are not supported: ``. 8 | 9 | Here’s an example, `` foo ` bar ``. 10 | 11 | And here, ` `` `. 12 | 13 | `` 14 | // this is also inline code 15 | `` 16 | 17 | So is this `foo bar 18 | baz`. 19 | 20 | And this `foo `` bar` 21 | 22 | And `this\`but this is text`. 23 | 24 | Whitespace only: ` `. 25 | 26 | Whitespace only: ` `. 27 | 28 | Whitespace only: ` 29 | `. 30 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/locate/url.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = locate 4 | 5 | var values = ['www.', 'http://', 'https://'] 6 | 7 | function locate(value, fromIndex) { 8 | var min = -1 9 | var index 10 | var length 11 | var position 12 | 13 | if (!this.options.gfm) { 14 | return min 15 | } 16 | 17 | length = values.length 18 | index = -1 19 | 20 | while (++index < length) { 21 | position = value.indexOf(values[index], fromIndex) 22 | 23 | if (position !== -1 && (min === -1 || position < min)) { 24 | min = position 25 | } 26 | } 27 | 28 | return min 29 | } 30 | -------------------------------------------------------------------------------- /test/fixtures/input/images.output.noreference-images.text: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit ![amet](http://amet.com/amet.jpeg "Amet"), consectetur adipiscing elit. Praesent dictum purus ullamcorper ligula semper pellentesque. 2 | 3 | Nulla ![finibus](http://finibus.com/finibus.png "Finibus") neque et diam rhoncus convallis. Nam dictum sapien nec sem ultrices fermentum. Nulla ![facilisi](http://facilisi.com/facilisi.gif "Facilisi"). In et feugiat massa. 4 | 5 | Donec sed sodales metus, ut aliquet quam. Suspendisse nec ipsum risus. Interdum et malesuada fames ac ante ipsum primis in ![faucibus](http://faucibus.com/faucibus.tiff "Faucibus"). 6 | -------------------------------------------------------------------------------- /test/fixtures/input/horizontal-rules.text: -------------------------------------------------------------------------------- 1 | Dashes: 2 | 3 | --- 4 | 5 | --- 6 | 7 | --- 8 | 9 | --- 10 | 11 | --- 12 | 13 | - - - 14 | 15 | - - - 16 | 17 | - - - 18 | 19 | - - - 20 | 21 | - - - 22 | 23 | 24 | Asterisks: 25 | 26 | *** 27 | 28 | *** 29 | 30 | *** 31 | 32 | *** 33 | 34 | *** 35 | 36 | * * * 37 | 38 | * * * 39 | 40 | * * * 41 | 42 | * * * 43 | 44 | * * * 45 | 46 | 47 | Underscores: 48 | 49 | ___ 50 | 51 | ___ 52 | 53 | ___ 54 | 55 | ___ 56 | 57 | ___ 58 | 59 | _ _ _ 60 | 61 | _ _ _ 62 | 63 | _ _ _ 64 | 65 | _ _ _ 66 | 67 | _ _ _ 68 | -------------------------------------------------------------------------------- /test/fixtures/input/table.text: -------------------------------------------------------------------------------- 1 | | Heading 1 | **H**eading 2 2 | | --------- | --------- 3 | | Cell 1 | Cell 2 4 | | Cell 3 | Cell 4 5 | 6 | | Header 1 | Header 2 | Header 3 | Header 4 | 7 | | :------: | -------: | :------- | -------- | 8 | | Cell 1 | Cell 2 | Cell 3 | Cell 4 | 9 | | Cell 5 | Cell 6 | Cell 7 | Cell 8 | 10 | 11 | Test code 12 | 13 | Header 1 | Header 2 14 | -------- | -------- 15 | Cell 1 | Cell 2 16 | Cell 3 | Cell 4 17 | 18 | Header 1|Header 2|Header 3|Header 4 19 | :-------|:------:|-------:|-------- 20 | Cell 1 |Cell 2 |Cell 3 |Cell 4 21 | *Cell 5*|Cell 6 |Cell 7 |Cell 8 22 | -------------------------------------------------------------------------------- /test/fixtures/input/code-block-nesting-bug.text: -------------------------------------------------------------------------------- 1 | GitHub, thus RedCarpet, has a bug where “nested” fenced code blocks, 2 | even with shorter fences, can exit their actual “parent” block. 3 | 4 | Note: not any more! . 5 | 6 | Note that this bug does not occur on indented code-blocks. 7 | 8 | ````foo 9 | ```bar 10 | baz 11 | ``` 12 | ```` 13 | 14 | Even with a different fence marker: 15 | 16 | ````foo 17 | ~~~bar 18 | baz 19 | ~~~ 20 | ```` 21 | 22 | And reversed: 23 | 24 | ~~~~foo 25 | ~~~bar 26 | baz 27 | ~~~ 28 | ~~~~ 29 | 30 | ~~~~foo 31 | ```bar 32 | baz 33 | ``` 34 | ~~~~ 35 | -------------------------------------------------------------------------------- /test/fixtures/input/link-whitespace.text: -------------------------------------------------------------------------------- 1 | [alpha](https://example.com?bravo charlie). 2 | 3 | [alpha](https://example.com?bravo charlie). 4 | 5 | [alpha](https://example.com?bravo 6 | charlie). 7 | 8 | ![alpha](https://example.com?bravo charlie). 9 | 10 | ![alpha](https://example.com?bravo charlie). 11 | 12 | ![alpha](https://example.com?bravo 13 | charlie). 14 | 15 | . 16 | 17 | . 18 | 19 | . 21 | 22 | https://example.com?bravo charlie. 23 | 24 | https://example.com?bravo charlie. 25 | 26 | https://example.com?bravo 27 | charlie. 28 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/defaults.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = { 4 | gfm: true, 5 | commonmark: false, 6 | pedantic: false, 7 | entities: 'false', 8 | setext: false, 9 | closeAtx: false, 10 | tableCellPadding: true, 11 | tablePipeAlign: true, 12 | stringLength: stringLength, 13 | incrementListMarker: true, 14 | tightDefinitions: false, 15 | fences: false, 16 | fence: '`', 17 | bullet: '-', 18 | listItemIndent: 'tab', 19 | rule: '*', 20 | ruleSpaces: true, 21 | ruleRepetition: 3, 22 | strong: '*', 23 | emphasis: '_' 24 | } 25 | 26 | function stringLength(value) { 27 | return value.length 28 | } 29 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/util/pad.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var repeat = require('repeat-string') 4 | 5 | module.exports = pad 6 | 7 | var lineFeed = '\n' 8 | var space = ' ' 9 | 10 | var tabSize = 4 11 | 12 | // Pad `value` with `level * tabSize` spaces. Respects lines. Ignores empty 13 | // lines. 14 | function pad(value, level) { 15 | var values = value.split(lineFeed) 16 | var index = values.length 17 | var padding = repeat(space, level * tabSize) 18 | 19 | while (index--) { 20 | if (values[index].length !== 0) { 21 | values[index] = padding + values[index] 22 | } 23 | } 24 | 25 | return values.join(lineFeed) 26 | } 27 | -------------------------------------------------------------------------------- /test/fixtures/tree/hr.output.rule=-.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "thematicBreak", 6 | "position": { 7 | "start": { 8 | "line": 1, 9 | "column": 1, 10 | "offset": 0 11 | }, 12 | "end": { 13 | "line": 1, 14 | "column": 6, 15 | "offset": 5 16 | }, 17 | "indent": [] 18 | } 19 | } 20 | ], 21 | "position": { 22 | "start": { 23 | "line": 1, 24 | "column": 1, 25 | "offset": 0 26 | }, 27 | "end": { 28 | "line": 2, 29 | "column": 1, 30 | "offset": 6 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/fixtures/tree/hr.output.rule=_.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "thematicBreak", 6 | "position": { 7 | "start": { 8 | "line": 1, 9 | "column": 1, 10 | "offset": 0 11 | }, 12 | "end": { 13 | "line": 1, 14 | "column": 6, 15 | "offset": 5 16 | }, 17 | "indent": [] 18 | } 19 | } 20 | ], 21 | "position": { 22 | "start": { 23 | "line": 1, 24 | "column": 1, 25 | "offset": 0 26 | }, 27 | "end": { 28 | "line": 2, 29 | "column": 1, 30 | "offset": 6 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/fixtures/input/hard-wrapped-paragraphs-with-list-like-lines.text: -------------------------------------------------------------------------------- 1 | In Markdown 1.0.0 and earlier. Version 2 | 8. This line turns into a list item. 3 | Because a hard-wrapped line in the 4 | 123. middle of a paragraph looked like a 5 | list item. 6 | 7 | Here's one with a bullet. 8 | * criminey. 9 | 10 | Non-GFM does not create a list for either. 11 | GFM does not create a list for `8.`, but does for `*`. 12 | CommonMark creates a list for both. 13 | All versions create lists for the following. 14 | 15 | * Here's one with a bullet. 16 | * criminey. 17 | 18 | ...and the following: 19 | 20 | 1. In Markdown 1.0.0 and earlier. Version 21 | 8. This line turns into a list item. 22 | -------------------------------------------------------------------------------- /test/fixtures/tree/hr.output.norule-spaces.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "thematicBreak", 6 | "position": { 7 | "start": { 8 | "line": 1, 9 | "column": 1, 10 | "offset": 0 11 | }, 12 | "end": { 13 | "line": 1, 14 | "column": 4, 15 | "offset": 3 16 | }, 17 | "indent": [] 18 | } 19 | } 20 | ], 21 | "position": { 22 | "start": { 23 | "line": 1, 24 | "column": 1, 25 | "offset": 0 26 | }, 27 | "end": { 28 | "line": 2, 29 | "column": 1, 30 | "offset": 4 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/remark/types/test.ts: -------------------------------------------------------------------------------- 1 | import remark = require('remark') 2 | 3 | interface PluginOptions { 4 | example: boolean 5 | } 6 | 7 | const plugin = (options?: PluginOptions) => {} 8 | 9 | remark().use(plugin) 10 | remark().use(plugin, {example: true}) 11 | remark().use({settings: {commonmark: true}}) 12 | // $ExpectError 13 | remark().use({settings: {doesNotExist: true}}) 14 | // $ExpectError 15 | remark().use(plugin, {doesNotExist: 'true'}) 16 | 17 | // $ExpectError 18 | const parseOptions: remark.RemarkOptions = { 19 | gfm: true, 20 | pedantic: true 21 | } 22 | 23 | const badParseOptionsInterface: remark.PartialRemarkOptions = { 24 | // $ExpectError 25 | gfm: 'true' 26 | } 27 | -------------------------------------------------------------------------------- /test/fixtures/tree/hr.output.rule-repetition=5.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "thematicBreak", 6 | "position": { 7 | "start": { 8 | "line": 1, 9 | "column": 1, 10 | "offset": 0 11 | }, 12 | "end": { 13 | "line": 1, 14 | "column": 10, 15 | "offset": 9 16 | }, 17 | "indent": [] 18 | } 19 | } 20 | ], 21 | "position": { 22 | "start": { 23 | "line": 1, 24 | "column": 1, 25 | "offset": 0 26 | }, 27 | "end": { 28 | "line": 2, 29 | "column": 1, 30 | "offset": 10 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/fixtures/tree/hr.output.rule=-asterisk-.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "thematicBreak", 6 | "position": { 7 | "start": { 8 | "line": 1, 9 | "column": 1, 10 | "offset": 0 11 | }, 12 | "end": { 13 | "line": 1, 14 | "column": 6, 15 | "offset": 5 16 | }, 17 | "indent": [] 18 | } 19 | } 20 | ], 21 | "position": { 22 | "start": { 23 | "line": 1, 24 | "column": 1, 25 | "offset": 0 26 | }, 27 | "end": { 28 | "line": 2, 29 | "column": 1, 30 | "offset": 6 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/macro/unordered-items.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = unorderedItems 4 | 5 | var lineFeed = '\n' 6 | 7 | var blank = lineFeed + lineFeed 8 | 9 | // Visit unordered list items. Uses `options.bullet` as each item’s bullet. 10 | function unorderedItems(node) { 11 | var self = this 12 | var bullet = self.options.bullet 13 | var fn = self.visitors.listItem 14 | var children = node.children 15 | var length = children.length 16 | var index = -1 17 | var values = [] 18 | 19 | while (++index < length) { 20 | values[index] = fn.call(self, children[index], node, index, bullet) 21 | } 22 | 23 | return values.join(node.spread ? blank : lineFeed) 24 | } 25 | -------------------------------------------------------------------------------- /test/fixtures/input/html-attributes.text: -------------------------------------------------------------------------------- 1 | # Block-level 2 | 3 |
4 | 5 | 6 |
7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 |
22 | 23 | 24 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 2 | Isaac Z. Schlueter 3 | Komatsu Seiji 4 | Cyril Lakech 5 | Zack Bonebrake 6 | Omeid Matten 7 | Patrick Bartsch 8 | Chris Wren 9 | Tsuyusato Kitsune 10 | Masahiro Miyashiro <3846masahiro+git@gmail.com> 11 | Tom MacWright Tom MacWright 12 | Min RK MinRK 13 | Nick Baugh 14 | 15 | # User names only. 16 | anonymous (Niggler) 17 | anonymous (Mithgol) 18 | anonymous (insanehong) 19 | -------------------------------------------------------------------------------- /test/fixtures/tree/html-processing-instruction.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "html", 6 | "value": "';\n?>", 7 | "position": { 8 | "start": { 9 | "line": 1, 10 | "column": 1, 11 | "offset": 0 12 | }, 13 | "end": { 14 | "line": 3, 15 | "column": 3, 16 | "offset": 20 17 | }, 18 | "indent": [ 19 | 1, 20 | 1 21 | ] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 4, 33 | "column": 1, 34 | "offset": 21 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/link-reference.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var copy = require('../util/copy-identifier-encoding') 4 | var label = require('../util/label') 5 | 6 | module.exports = linkReference 7 | 8 | var leftSquareBracket = '[' 9 | var rightSquareBracket = ']' 10 | 11 | var shortcut = 'shortcut' 12 | var collapsed = 'collapsed' 13 | 14 | function linkReference(node) { 15 | var self = this 16 | var type = node.referenceType 17 | var exit = self.enterLinkReference(self, node) 18 | var value = self.all(node).join('') 19 | 20 | exit() 21 | 22 | if (type === shortcut || type === collapsed) { 23 | value = copy(value, node.label || node.identifier) 24 | } 25 | 26 | return leftSquareBracket + value + rightSquareBracket + label(node) 27 | } 28 | -------------------------------------------------------------------------------- /test/fixtures/input/fenced-code-info-with-marker.text: -------------------------------------------------------------------------------- 1 | If the info string comes after a backtick fence, it may not contain any backtick 2 | characters. 3 | The reason for this restriction is that otherwise some inline code would be 4 | incorrectly interpreted as the beginning of a fenced code block. 5 | 6 | Tildes in info strings are fine: 7 | 8 | ```js filename=~/.bashrc 9 | console.log(1) 10 | ``` 11 | 12 | Tildes in info strings are fine after tilde fences: 13 | 14 | ~~~js filename=~/.bashrc 15 | console.log(1) 16 | ~~~ 17 | 18 | Backticks in info strings are fine after tilde fences: 19 | 20 | ~~~js title=`.bashrc` 21 | console.log(1) 22 | ~~~ 23 | 24 | Backticks in info strings are **not** fine after backtick fences: 25 | 26 | ```js title=`.bashrc` 27 | console.log(1) 28 | ``` 29 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/util/label.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = label 4 | 5 | var leftSquareBracket = '[' 6 | var rightSquareBracket = ']' 7 | 8 | var shortcut = 'shortcut' 9 | var collapsed = 'collapsed' 10 | 11 | // Stringify a reference label. 12 | // Because link references are easily, mistakingly, created (for example, 13 | // `[foo]`), reference nodes have an extra property depicting how it looked in 14 | // the original document, so stringification can cause minimal changes. 15 | function label(node) { 16 | var type = node.referenceType 17 | 18 | if (type === shortcut) { 19 | return '' 20 | } 21 | 22 | return ( 23 | leftSquareBracket + 24 | (type === collapsed ? '' : node.label || node.identifier) + 25 | rightSquareBracket 26 | ) 27 | } 28 | -------------------------------------------------------------------------------- /test/fixtures/input/entities.text: -------------------------------------------------------------------------------- 1 | Lots of entities are supported in mdast:  , &, ©, Æ, 2 | Ď, ¾, ℋ, ⅆ, 3 | ∲, &c. Even some entities with a missing 4 | terminal semicolon are parsed correctly (as per the HTML5 spec): 5 | ÿ, á, ©, and &. 6 | 7 | However, &MadeUpEntities; are kept in the document. 8 | 9 | Entities even work in the language flag of fenced code blocks: 10 | 11 | ```some—language 12 | alert('Hello'); 13 | ``` 14 | 15 | Or in [línks](~/some—file "in some plæce") 16 | 17 | Or in ![ímages](~/an–image.png "© Someone") 18 | 19 | But, entities are not interpreted in `inline cöde`, or in 20 | code blocks: 21 | 22 | CÖDE block. 23 | -------------------------------------------------------------------------------- /test/fixtures/tree/fenced-code-lang-unescape.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "code", 6 | "lang": "\\[awd", 7 | "meta": null, 8 | "value": "dwa", 9 | "position": { 10 | "start": { 11 | "line": 1, 12 | "column": 1, 13 | "offset": 0 14 | }, 15 | "end": { 16 | "line": 3, 17 | "column": 4, 18 | "offset": 18 19 | }, 20 | "indent": [ 21 | 1, 22 | 1 23 | ] 24 | } 25 | } 26 | ], 27 | "position": { 28 | "start": { 29 | "line": 1, 30 | "column": 1, 31 | "offset": 0 32 | }, 33 | "end": { 34 | "line": 4, 35 | "column": 1, 36 | "offset": 19 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/thematic-break.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var repeat = require('repeat-string') 4 | 5 | module.exports = thematic 6 | 7 | var space = ' ' 8 | 9 | // Stringify a `thematic-break`. 10 | // The character used is configurable through `rule`: (`'_'`): 11 | // 12 | // ```markdown 13 | // ___ 14 | // ``` 15 | // 16 | // The number of repititions is defined through `ruleRepetition` (`6`): 17 | // 18 | // ```markdown 19 | // ****** 20 | // ``` 21 | // 22 | // Whether spaces delimit each character, is configured through `ruleSpaces` 23 | // (`true`): 24 | // ```markdown 25 | // * * * 26 | // ``` 27 | function thematic() { 28 | var options = this.options 29 | var rule = repeat(options.rule, options.ruleRepetition) 30 | return options.ruleSpaces ? rule.split('').join(space) : rule 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/tree/fenced-code-trailing-characters-2.nooutput.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "code", 6 | "lang": null, 7 | "meta": null, 8 | "value": "``` aaa", 9 | "position": { 10 | "start": { 11 | "line": 1, 12 | "column": 1, 13 | "offset": 0 14 | }, 15 | "end": { 16 | "line": 3, 17 | "column": 4, 18 | "offset": 15 19 | }, 20 | "indent": [ 21 | 1, 22 | 1 23 | ] 24 | } 25 | } 26 | ], 27 | "position": { 28 | "start": { 29 | "line": 1, 30 | "column": 1, 31 | "offset": 0 32 | }, 33 | "end": { 34 | "line": 4, 35 | "column": 1, 36 | "offset": 16 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/fixtures/tree/definition-url-entities.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "definition", 6 | "identifier": "baz", 7 | "label": "baz", 8 | "title": null, 9 | "url": "http://www.example.com?param=1®ion=here", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 50, 19 | "offset": 49 20 | }, 21 | "indent": [] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 2, 33 | "column": 1, 34 | "offset": 50 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/tokenize/escape.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var locate = require('../locate/escape') 4 | 5 | module.exports = escape 6 | escape.locator = locate 7 | 8 | var lineFeed = '\n' 9 | var backslash = '\\' 10 | 11 | function escape(eat, value, silent) { 12 | var self = this 13 | var character 14 | var node 15 | 16 | if (value.charAt(0) === backslash) { 17 | character = value.charAt(1) 18 | 19 | if (self.escape.indexOf(character) !== -1) { 20 | /* istanbul ignore if - never used (yet) */ 21 | if (silent) { 22 | return true 23 | } 24 | 25 | if (character === lineFeed) { 26 | node = {type: 'break'} 27 | } else { 28 | node = {type: 'text', value: character} 29 | } 30 | 31 | return eat(backslash + character)(node) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/fixtures/input/lists-with-code-and-rules.text: -------------------------------------------------------------------------------- 1 | ## foo 2 | 3 | 1. bar: 4 | 5 | > - one 6 | - two 7 | - three 8 | - four 9 | - five 10 | 11 | 1. foo: 12 | 13 | ``` 14 | line 1 15 | line 2 16 | ``` 17 | 18 | 1. foo: 19 | 20 | 1. foo `bar` bar: 21 | 22 | ``` erb 23 | some code here 24 | ``` 25 | 26 | 2. foo `bar` bar: 27 | 28 | ``` erb 29 | foo 30 | --- 31 | bar 32 | --- 33 | foo 34 | bar 35 | ``` 36 | 37 | 3. foo `bar` bar: 38 | 39 | ``` html 40 | --- 41 | foo 42 | foo 43 | --- 44 | bar 45 | ``` 46 | 47 | 4. foo `bar` bar: 48 | 49 | foo 50 | --- 51 | bar 52 | 53 | 5. foo 54 | -------------------------------------------------------------------------------- /test/fixtures/tree/fenced-code-trailing-characters.nooutput.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "code", 6 | "lang": "js", 7 | "meta": null, 8 | "value": "foo();\n```bash", 9 | "position": { 10 | "start": { 11 | "line": 1, 12 | "column": 1, 13 | "offset": 0 14 | }, 15 | "end": { 16 | "line": 4, 17 | "column": 4, 18 | "offset": 24 19 | }, 20 | "indent": [ 21 | 1, 22 | 1, 23 | 1 24 | ] 25 | } 26 | } 27 | ], 28 | "position": { 29 | "start": { 30 | "line": 1, 31 | "column": 1, 32 | "offset": 0 33 | }, 34 | "end": { 35 | "line": 5, 36 | "column": 1, 37 | "offset": 25 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/util/interrupt.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = interrupt 4 | 5 | function interrupt(interruptors, tokenizers, ctx, parameters) { 6 | var length = interruptors.length 7 | var index = -1 8 | var interruptor 9 | var config 10 | 11 | while (++index < length) { 12 | interruptor = interruptors[index] 13 | config = interruptor[1] || {} 14 | 15 | if ( 16 | config.pedantic !== undefined && 17 | config.pedantic !== ctx.options.pedantic 18 | ) { 19 | continue 20 | } 21 | 22 | if ( 23 | config.commonmark !== undefined && 24 | config.commonmark !== ctx.options.commonmark 25 | ) { 26 | continue 27 | } 28 | 29 | if (tokenizers[interruptor[0]].apply(ctx, parameters)) { 30 | return true 31 | } 32 | } 33 | 34 | return false 35 | } 36 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/util/enclose-uri.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var count = require('ccount') 4 | 5 | module.exports = enclose 6 | 7 | var leftParenthesis = '(' 8 | var rightParenthesis = ')' 9 | var lessThan = '<' 10 | var greaterThan = '>' 11 | 12 | var expression = /\s/ 13 | 14 | // Wrap `url` in angle brackets when needed, or when 15 | // forced. 16 | // In links, images, and definitions, the URL part needs 17 | // to be enclosed when it: 18 | // 19 | // - has a length of `0` 20 | // - contains white-space 21 | // - has more or less opening than closing parentheses 22 | function enclose(uri, always) { 23 | if ( 24 | always || 25 | uri.length === 0 || 26 | expression.test(uri) || 27 | count(uri, leftParenthesis) !== count(uri, rightParenthesis) 28 | ) { 29 | return lessThan + uri + greaterThan 30 | } 31 | 32 | return uri 33 | } 34 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/util/get-indentation.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = indentation 4 | 5 | var tab = '\t' 6 | var space = ' ' 7 | 8 | var spaceSize = 1 9 | var tabSize = 4 10 | 11 | // Gets indentation information for a line. 12 | function indentation(value) { 13 | var index = 0 14 | var indent = 0 15 | var character = value.charAt(index) 16 | var stops = {} 17 | var size 18 | var lastIndent = 0 19 | 20 | while (character === tab || character === space) { 21 | size = character === tab ? tabSize : spaceSize 22 | 23 | indent += size 24 | 25 | if (size > 1) { 26 | indent = Math.floor(indent / size) * size 27 | } 28 | 29 | while (lastIndent < indent) { 30 | stops[++lastIndent] = index 31 | } 32 | 33 | character = value.charAt(++index) 34 | } 35 | 36 | return {indent: indent, stops: stops} 37 | } 38 | -------------------------------------------------------------------------------- /script/list-of-methods.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var zone = require('mdast-zone') 4 | var u = require('unist-builder') 5 | var proto = require('../packages/remark-parse').Parser.prototype 6 | 7 | module.exports = listOfMethods 8 | 9 | function listOfMethods() { 10 | return transformer 11 | } 12 | 13 | function transformer(tree) { 14 | zone(tree, 'methods-block', replace('blockMethods')) 15 | zone(tree, 'methods-inline', replace('inlineMethods')) 16 | } 17 | 18 | function replace(name) { 19 | var list = proto[name] 20 | 21 | return replace 22 | 23 | function replace(start, nodes, end) { 24 | return [ 25 | start, 26 | u( 27 | 'list', 28 | {ordered: false}, 29 | list.map(function (name) { 30 | return u('listItem', [u('paragraph', [u('inlineCode', name)])]) 31 | }) 32 | ), 33 | end 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/fixtures/input/html-simple.text: -------------------------------------------------------------------------------- 1 | Here's a simple block: 2 | 3 |
4 | foo 5 |
6 | 7 | This should be a code block, though: 8 | 9 |
10 | foo 11 |
12 | 13 | As should this: 14 | 15 |
foo
16 | 17 | Now, nested: 18 | 19 |
20 |
21 |
22 | foo 23 |
24 |
25 |
26 | 27 | This should just be an HTML comment: 28 | 29 | 30 | 31 | Multiline: 32 | 33 | 37 | 38 | Code block: 39 | 40 | 41 | 42 | Just plain comment, with trailing spaces on the line: 43 | 44 | 45 | 46 | Code: 47 | 48 |
49 | 50 | Hr's: 51 | 52 |
53 | 54 |
55 | 56 |
57 | 58 |
59 | 60 |
61 | 62 |
63 | 64 |
65 | 66 |
67 | 68 |
69 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/definition.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var uri = require('../util/enclose-uri') 4 | var title = require('../util/enclose-title') 5 | 6 | module.exports = definition 7 | 8 | var space = ' ' 9 | var colon = ':' 10 | var leftSquareBracket = '[' 11 | var rightSquareBracket = ']' 12 | 13 | // Stringify an URL definition. 14 | // 15 | // Is smart about enclosing `url` (see `encloseURI()`) and `title` (see 16 | // `encloseTitle()`). 17 | // 18 | // ```markdown 19 | // [foo]: 'An "example" e-mail' 20 | // ``` 21 | function definition(node) { 22 | var content = uri(node.url) 23 | 24 | if (node.title) { 25 | content += space + title(node.title) 26 | } 27 | 28 | return ( 29 | leftSquareBracket + 30 | (node.label || node.identifier) + 31 | rightSquareBracket + 32 | colon + 33 | space + 34 | content 35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/tokenize/break.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var locate = require('../locate/break') 4 | 5 | module.exports = hardBreak 6 | hardBreak.locator = locate 7 | 8 | var space = ' ' 9 | var lineFeed = '\n' 10 | var minBreakLength = 2 11 | 12 | function hardBreak(eat, value, silent) { 13 | var length = value.length 14 | var index = -1 15 | var queue = '' 16 | var character 17 | 18 | while (++index < length) { 19 | character = value.charAt(index) 20 | 21 | if (character === lineFeed) { 22 | if (index < minBreakLength) { 23 | return 24 | } 25 | 26 | /* istanbul ignore if - never used (yet) */ 27 | if (silent) { 28 | return true 29 | } 30 | 31 | queue += character 32 | 33 | return eat(queue)({type: 'break'}) 34 | } 35 | 36 | if (character !== space) { 37 | return 38 | } 39 | 40 | queue += character 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/util/enter-link-reference.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var identity = require('./identity') 4 | 5 | module.exports = enter 6 | 7 | // Shortcut and collapsed link references need no escaping and encoding during 8 | // the processing of child nodes (it must be implied from identifier). 9 | // 10 | // This toggler turns encoding and escaping off for shortcut and collapsed 11 | // references. 12 | // 13 | // Implies `enterLink`. 14 | function enter(compiler, node) { 15 | var encode = compiler.encode 16 | var escape = compiler.escape 17 | var exitLink = compiler.enterLink() 18 | 19 | if (node.referenceType !== 'shortcut' && node.referenceType !== 'collapsed') { 20 | return exitLink 21 | } 22 | 23 | compiler.escape = identity 24 | compiler.encode = identity 25 | 26 | return exit 27 | 28 | function exit() { 29 | compiler.encode = encode 30 | compiler.escape = escape 31 | exitLink() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /script/regenerate-fixtures.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var fs = require('fs') 4 | var path = require('path') 5 | var remark = require('../packages/remark') 6 | var fixtures = require('../test/fixtures') 7 | 8 | fixtures.forEach(function (fixture) { 9 | var input = fixture.input 10 | var name = fixture.name 11 | var mapping = fixture.mapping 12 | 13 | Object.keys(mapping).forEach(function (key) { 14 | var filename = name + (key ? '.' + key : key) + '.json' 15 | var result 16 | 17 | try { 18 | result = remark() 19 | .data('settings', fixture.possibilities[key]) 20 | .parse(input) 21 | } catch (error) { 22 | console.log('Cannot regenerate `' + filename + '`') 23 | throw error 24 | } 25 | 26 | result = JSON.stringify(result, null, 2) + '\n' 27 | 28 | filename = filename.replace(/\*/g, '-asterisk-') 29 | 30 | fs.writeFileSync(path.join('test', 'fixtures', 'tree', filename), result) 31 | }) 32 | }) 33 | -------------------------------------------------------------------------------- /test/fixtures/input/links-url-entity-parentheses.text: -------------------------------------------------------------------------------- 1 | [Hello](./world(and-hello(world)). 2 | 3 | [Hello](<./world(and-hello(world)>). 4 | 5 | [Hello](./world(and)helloworld)). 6 | 7 | [Hello](<./world(and)helloworld)>). 8 | 9 | [Hello](./world(and-hello(world)). 10 | 11 | [Hello](<./world(and-hello(world)>). 12 | 13 | [Hello](./world(and)helloworld)). 14 | 15 | [Hello](<./world(and)helloworld)>). 16 | 17 | ![Hello](./world(and-hello(world)). 18 | 19 | ![Hello](<./world(and-hello(world)>). 20 | 21 | ![Hello](./world(and)helloworld)). 22 | 23 | ![Hello](<./world(and)helloworld)>). 24 | 25 | ![Hello](./world(and-hello(world)). 26 | 27 | ![Hello](<./world(and-hello(world)>). 28 | 29 | ![Hello](./world(and)helloworld)). 30 | 31 | ![Hello](<./world(and)helloworld)>). 32 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/unescape.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = factory 4 | 5 | var backslash = '\\' 6 | 7 | // Factory to de-escape a value, based on a list at `key` in `ctx`. 8 | function factory(ctx, key) { 9 | return unescape 10 | 11 | // De-escape a string using the expression at `key` in `ctx`. 12 | function unescape(value) { 13 | var previous = 0 14 | var index = value.indexOf(backslash) 15 | var escape = ctx[key] 16 | var queue = [] 17 | var character 18 | 19 | while (index !== -1) { 20 | queue.push(value.slice(previous, index)) 21 | previous = index + 1 22 | character = value.charAt(previous) 23 | 24 | // If the following character is not a valid escape, add the slash. 25 | if (!character || escape.indexOf(character) === -1) { 26 | queue.push(backslash) 27 | } 28 | 29 | index = value.indexOf(backslash, previous + 1) 30 | } 31 | 32 | queue.push(value.slice(previous)) 33 | 34 | return queue.join('') 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/emphasis.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = emphasis 4 | 5 | var underscore = '_' 6 | var asterisk = '*' 7 | 8 | // Stringify an `emphasis`. 9 | // 10 | // The marker used is configurable through `emphasis`, which defaults to an 11 | // underscore (`'_'`) but also accepts an asterisk (`'*'`): 12 | // 13 | // ```markdown 14 | // *foo* 15 | // ``` 16 | // 17 | // In `pedantic` mode, text which itself contains an underscore will cause the 18 | // marker to default to an asterisk instead: 19 | // 20 | // ```markdown 21 | // *foo_bar* 22 | // ``` 23 | function emphasis(node) { 24 | var marker = this.options.emphasis 25 | var content = this.all(node).join('') 26 | 27 | // When in pedantic mode, prevent using underscore as the marker when there 28 | // are underscores in the content. 29 | if ( 30 | this.options.pedantic && 31 | marker === underscore && 32 | content.indexOf(marker) !== -1 33 | ) { 34 | marker = asterisk 35 | } 36 | 37 | return marker + content + marker 38 | } 39 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/util/html.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var attributeName = '[a-zA-Z_:][a-zA-Z0-9:._-]*' 4 | var unquoted = '[^"\'=<>`\\u0000-\\u0020]+' 5 | var singleQuoted = "'[^']*'" 6 | var doubleQuoted = '"[^"]*"' 7 | var attributeValue = 8 | '(?:' + unquoted + '|' + singleQuoted + '|' + doubleQuoted + ')' 9 | var attribute = 10 | '(?:\\s+' + attributeName + '(?:\\s*=\\s*' + attributeValue + ')?)' 11 | var openTag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>' 12 | var closeTag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>' 13 | var comment = '|' 14 | var processing = '<[?].*?[?]>' 15 | var declaration = ']*>' 16 | var cdata = '' 17 | 18 | exports.openCloseTag = new RegExp('^(?:' + openTag + '|' + closeTag + ')') 19 | 20 | exports.tag = new RegExp( 21 | '^(?:' + 22 | openTag + 23 | '|' + 24 | closeTag + 25 | '|' + 26 | comment + 27 | '|' + 28 | processing + 29 | '|' + 30 | declaration + 31 | '|' + 32 | cdata + 33 | ')' 34 | ) 35 | -------------------------------------------------------------------------------- /test/fixtures/input/entities-advanced.text: -------------------------------------------------------------------------------- 1 | > However, &MadeUpEntities; are kept in the document. 2 | 3 | > Entities even work in the language flag of fenced code blocks: 4 | 5 | > ```some©language 6 | > alert('Hello'); 7 | > ``` 8 | 9 | > And in an auto-link: 10 | 11 | > Foo and bar and http://example©xample.com and baz. 12 | 13 | > Or in [l©nks]( 14 | > ~/some©file "in some pl©ce") 15 | 16 | > Or in [l©lnks]( 17 | > <~/some©file> 18 | > "in some pl©ce") 19 | 20 | > Or in ![ 21 | > l©nks 22 | > ]( 23 | > ~/some©file "in some pl©ce") 24 | 25 | *** 26 | 27 | > Or in ![l©lnks]( 28 | > <~/some©file> 29 | > "in some pl©ce") 30 | 31 | > Or in ![ 32 | > l©nks 33 | > ][12] 34 | 35 | > [1]: http://example©xample.com "in some 36 | > pl©ce" 37 | 38 | > [ 39 | > 1 40 | > ]: http://example©xample.com "in some 41 | > pl©ce" 42 | 43 | *** 44 | 45 | > But, entities are not interpreted in `inline cöde`, or in 46 | > code blocks: 47 | 48 | > CÖDE block. 49 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/block-elements.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = [ 4 | 'address', 5 | 'article', 6 | 'aside', 7 | 'base', 8 | 'basefont', 9 | 'blockquote', 10 | 'body', 11 | 'caption', 12 | 'center', 13 | 'col', 14 | 'colgroup', 15 | 'dd', 16 | 'details', 17 | 'dialog', 18 | 'dir', 19 | 'div', 20 | 'dl', 21 | 'dt', 22 | 'fieldset', 23 | 'figcaption', 24 | 'figure', 25 | 'footer', 26 | 'form', 27 | 'frame', 28 | 'frameset', 29 | 'h1', 30 | 'h2', 31 | 'h3', 32 | 'h4', 33 | 'h5', 34 | 'h6', 35 | 'head', 36 | 'header', 37 | 'hgroup', 38 | 'hr', 39 | 'html', 40 | 'iframe', 41 | 'legend', 42 | 'li', 43 | 'link', 44 | 'main', 45 | 'menu', 46 | 'menuitem', 47 | 'meta', 48 | 'nav', 49 | 'noframes', 50 | 'ol', 51 | 'optgroup', 52 | 'option', 53 | 'p', 54 | 'param', 55 | 'pre', 56 | 'section', 57 | 'source', 58 | 'title', 59 | 'summary', 60 | 'table', 61 | 'tbody', 62 | 'td', 63 | 'tfoot', 64 | 'th', 65 | 'thead', 66 | 'title', 67 | 'tr', 68 | 'track', 69 | 'ul' 70 | ] 71 | -------------------------------------------------------------------------------- /packages/remark-cli/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "remark-cli", 3 | "version": "8.0.0", 4 | "description": "CLI to process Markdown with remark", 5 | "license": "MIT", 6 | "keywords": [ 7 | "unified", 8 | "remark", 9 | "markdown", 10 | "mdast", 11 | "cli", 12 | "bin" 13 | ], 14 | "homepage": "https://remark.js.org", 15 | "repository": "https://github.com/remarkjs/remark/tree/master/packages/remark-cli", 16 | "bugs": "https://github.com/remarkjs/remark/issues", 17 | "funding": { 18 | "type": "opencollective", 19 | "url": "https://opencollective.com/unified" 20 | }, 21 | "author": "Titus Wormer (https://wooorm.com)", 22 | "contributors": [ 23 | "Titus Wormer (https://wooorm.com)" 24 | ], 25 | "bin": { 26 | "remark": "cli.js" 27 | }, 28 | "files": [ 29 | "cli.js" 30 | ], 31 | "dependencies": { 32 | "markdown-extensions": "^1.1.0", 33 | "remark": "^12.0.0", 34 | "unified-args": "^8.0.0" 35 | }, 36 | "scripts": { 37 | "test": "tape test.js" 38 | }, 39 | "xo": false 40 | } 41 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/parse.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var xtend = require('xtend') 4 | var removePosition = require('unist-util-remove-position') 5 | 6 | module.exports = parse 7 | 8 | var lineFeed = '\n' 9 | var lineBreaksExpression = /\r\n|\r/g 10 | 11 | // Parse the bound file. 12 | function parse() { 13 | var self = this 14 | var value = String(self.file) 15 | var start = {line: 1, column: 1, offset: 0} 16 | var content = xtend(start) 17 | var node 18 | 19 | // Clean non-unix newlines: `\r\n` and `\r` are all changed to `\n`. 20 | // This should not affect positional information. 21 | value = value.replace(lineBreaksExpression, lineFeed) 22 | 23 | // BOM. 24 | if (value.charCodeAt(0) === 0xfeff) { 25 | value = value.slice(1) 26 | 27 | content.column++ 28 | content.offset++ 29 | } 30 | 31 | node = { 32 | type: 'root', 33 | children: self.tokenizeBlock(value, content), 34 | position: {start: start, end: self.eof || xtend(start)} 35 | } 36 | 37 | if (!self.options.position) { 38 | removePosition(node, true) 39 | } 40 | 41 | return node 42 | } 43 | -------------------------------------------------------------------------------- /packages/remark/test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var test = require('tape') 4 | var remark = require('.') 5 | 6 | test('remark().processSync(value)', function (t) { 7 | t.equal( 8 | remark().processSync('*foo*').toString(), 9 | '_foo_\n', 10 | 'should parse and stringify a file' 11 | ) 12 | 13 | t.equal( 14 | remark() 15 | .data('settings', {commonmark: true}) 16 | .processSync('1) foo') 17 | .toString(), 18 | '1. foo\n', 19 | 'should accept parse options' 20 | ) 21 | 22 | t.equal( 23 | remark().data('settings', {closeAtx: true}).processSync('# foo').toString(), 24 | '# foo #\n', 25 | 'should accept stringify options' 26 | ) 27 | 28 | t.throws( 29 | function () { 30 | remark() 31 | .data('settings', {pedantic: true, listItemIndent: '1'}) 32 | .processSync(['* List', '', ' code()'].join('\n')) 33 | }, 34 | /Cannot indent code properly. See https:\/\/git.io\/fxKR8/, 35 | 'should throw when `pedantic` is `true`, `listItemIndent` is not `tab`, and compiling code in a list-item' 36 | ) 37 | 38 | t.end() 39 | }) 40 | -------------------------------------------------------------------------------- /test/fixtures/tree/escaped-angles.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": ">", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 3, 19 | "offset": 2 20 | }, 21 | "indent": [] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 1, 33 | "column": 3, 34 | "offset": 2 35 | }, 36 | "indent": [] 37 | } 38 | } 39 | ], 40 | "position": { 41 | "start": { 42 | "line": 1, 43 | "column": 1, 44 | "offset": 0 45 | }, 46 | "end": { 47 | "line": 2, 48 | "column": 1, 49 | "offset": 3 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/fixtures/tree/image-with-pipe.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "f|", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 3, 19 | "offset": 2 20 | }, 21 | "indent": [] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 1, 33 | "column": 3, 34 | "offset": 2 35 | }, 36 | "indent": [] 37 | } 38 | } 39 | ], 40 | "position": { 41 | "start": { 42 | "line": 1, 43 | "column": 1, 44 | "offset": 0 45 | }, 46 | "end": { 47 | "line": 1, 48 | "column": 3, 49 | "offset": 2 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/set-options.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var xtend = require('xtend') 4 | var escapes = require('markdown-escapes') 5 | var defaults = require('./defaults') 6 | 7 | module.exports = setOptions 8 | 9 | function setOptions(options) { 10 | var self = this 11 | var current = self.options 12 | var key 13 | var value 14 | 15 | if (options == null) { 16 | options = {} 17 | } else if (typeof options === 'object') { 18 | options = xtend(options) 19 | } else { 20 | throw new Error('Invalid value `' + options + '` for setting `options`') 21 | } 22 | 23 | for (key in defaults) { 24 | value = options[key] 25 | 26 | if (value == null) { 27 | value = current[key] 28 | } 29 | 30 | if ( 31 | (key !== 'blocks' && typeof value !== 'boolean') || 32 | (key === 'blocks' && typeof value !== 'object') 33 | ) { 34 | throw new Error( 35 | 'Invalid value `' + value + '` for setting `options.' + key + '`' 36 | ) 37 | } 38 | 39 | options[key] = value 40 | } 41 | 42 | self.options = options 43 | self.escape = escapes(options) 44 | 45 | return self 46 | } 47 | -------------------------------------------------------------------------------- /test/fixtures/input/html-tags.text: -------------------------------------------------------------------------------- 1 | # Block 2 | 3 |
4 | 5 | 6 |
7 | 8 | 9 |
10 | 11 | 12 | <-article> 13 | 14 | 15 |
14 | function locate(value, fromIndex) { 15 | var self = this 16 | var at 17 | var position 18 | 19 | if (!this.options.gfm) { 20 | return -1 21 | } 22 | 23 | at = value.indexOf('@', fromIndex) 24 | 25 | if (at === -1) { 26 | return -1 27 | } 28 | 29 | position = at 30 | 31 | if (position === fromIndex || !isGfmAtext(value.charCodeAt(position - 1))) { 32 | return locate.call(self, value, at + 1) 33 | } 34 | 35 | while (position > fromIndex && isGfmAtext(value.charCodeAt(position - 1))) { 36 | position-- 37 | } 38 | 39 | return position 40 | } 41 | 42 | function isGfmAtext(code) { 43 | return ( 44 | decimal(code) || 45 | alphabetical(code) || 46 | code === plusSign || 47 | code === dash || 48 | code === dot || 49 | code === underscore 50 | ) 51 | } 52 | -------------------------------------------------------------------------------- /test/fixtures/tree/image-empty-alt.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "image", 9 | "title": null, 10 | "url": "/xyz.png", 11 | "alt": null, 12 | "position": { 13 | "start": { 14 | "line": 1, 15 | "column": 1, 16 | "offset": 0 17 | }, 18 | "end": { 19 | "line": 1, 20 | "column": 14, 21 | "offset": 13 22 | }, 23 | "indent": [] 24 | } 25 | } 26 | ], 27 | "position": { 28 | "start": { 29 | "line": 1, 30 | "column": 1, 31 | "offset": 0 32 | }, 33 | "end": { 34 | "line": 1, 35 | "column": 14, 36 | "offset": 13 37 | }, 38 | "indent": [] 39 | } 40 | } 41 | ], 42 | "position": { 43 | "start": { 44 | "line": 1, 45 | "column": 1, 46 | "offset": 0 47 | }, 48 | "end": { 49 | "line": 2, 50 | "column": 1, 51 | "offset": 14 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/heading.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var repeat = require('repeat-string') 4 | 5 | module.exports = heading 6 | 7 | var lineFeed = '\n' 8 | var space = ' ' 9 | var numberSign = '#' 10 | var dash = '-' 11 | var equalsTo = '=' 12 | 13 | // Stringify a heading. 14 | // 15 | // In `setext: true` mode and when `depth` is smaller than three, creates a 16 | // setext header: 17 | // 18 | // ```markdown 19 | // Foo 20 | // === 21 | // ``` 22 | // 23 | // Otherwise, an ATX header is generated: 24 | // 25 | // ```markdown 26 | // ### Foo 27 | // ``` 28 | // 29 | // In `closeAtx: true` mode, the header is closed with hashes: 30 | // 31 | // ```markdown 32 | // ### Foo ### 33 | // ``` 34 | function heading(node) { 35 | var self = this 36 | var depth = node.depth 37 | var setext = self.options.setext 38 | var closeAtx = self.options.closeAtx 39 | var content = self.all(node).join('') 40 | var prefix 41 | 42 | if (setext && depth < 3) { 43 | return ( 44 | content + lineFeed + repeat(depth === 1 ? equalsTo : dash, content.length) 45 | ) 46 | } 47 | 48 | prefix = repeat(numberSign, node.depth) 49 | 50 | return prefix + space + content + (closeAtx ? space + prefix : '') 51 | } 52 | -------------------------------------------------------------------------------- /test/fixtures/tree/isolated-hard-break.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "The previous line, which contains 2 spaces, should be considered to be empty.", 10 | "position": { 11 | "start": { 12 | "line": 2, 13 | "column": 1, 14 | "offset": 3 15 | }, 16 | "end": { 17 | "line": 2, 18 | "column": 78, 19 | "offset": 80 20 | }, 21 | "indent": [] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 2, 28 | "column": 1, 29 | "offset": 3 30 | }, 31 | "end": { 32 | "line": 2, 33 | "column": 78, 34 | "offset": 80 35 | }, 36 | "indent": [] 37 | } 38 | } 39 | ], 40 | "position": { 41 | "start": { 42 | "line": 1, 43 | "column": 1, 44 | "offset": 0 45 | }, 46 | "end": { 47 | "line": 3, 48 | "column": 1, 49 | "offset": 81 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/fixtures/input/list-mixed-indentation.text: -------------------------------------------------------------------------------- 1 | # Mixed spaces and tabs 2 | 3 | - (item 1.) Minimum list, equivalent to two spaces 4 | - (item 2.) indented with 1 space, not enough indentation to be a subitem 5 | - (item 2.1.) indented with tab 6 | 7 | 8 | - (item 1.) Minimum list, equivalent to two spaces 9 | - (item 1.1.) indentend with 2 spaces 10 | - (item 1.2.) indented with tab 11 | 12 | 13 | - (item 1.) List with 1 extra space 14 | - (item 1.1.) indentend with 3 spaces 15 | - (item 1.2.) indented with tab 16 | 17 | 18 | - (item 1.) List with 2 extra space, equivalent to 1 tab indentation 19 | - (item 1.1.) indentend with 4 spaces 20 | - (item 1.2.) indented with tab 21 | 22 | 23 | - (item 1.) List with 1 tab, equivalent to 4 spaces 24 | - (item 1.1.) indentend with 4 spaces 25 | - (item 1.2.) indented with tab 26 | 27 | 28 | - (item 1.) list with double indentation and mixed items 29 | - (item 1.1.) normal indentation with 1 tab 30 | - (item 1.1.1.) item with 4 spaces + 4 spaces 31 | - (item 1.1.2.) item with tab + 4 spaces 32 | - (item 1.1.3.) item with 4 spaces + tab 33 | - (item 1.1.4.) item with tab + tab 34 | - (item 1.1.5.) item with 2 spaces + tab + 2 spaces (nasty!) 35 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/table.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var markdownTable = require('markdown-table') 4 | 5 | module.exports = table 6 | 7 | // Stringify table. 8 | // 9 | // Creates a fenced table. 10 | // The table has aligned delimiters by default, but not in 11 | // `tablePipeAlign: false`: 12 | // 13 | // ```markdown 14 | // | Header 1 | Header 2 | 15 | // | :-: | - | 16 | // | Alpha | Bravo | 17 | // ``` 18 | // 19 | // The table is spaced by default, but not in `tableCellPadding: false`: 20 | // 21 | // ```markdown 22 | // |Foo|Bar| 23 | // |:-:|---| 24 | // |Baz|Qux| 25 | // ``` 26 | function table(node) { 27 | var self = this 28 | var options = self.options 29 | var padding = options.tableCellPadding 30 | var alignDelimiters = options.tablePipeAlign 31 | var stringLength = options.stringLength 32 | var rows = node.children 33 | var index = rows.length 34 | var exit = self.enterTable() 35 | var result = [] 36 | 37 | while (index--) { 38 | result[index] = self.all(rows[index]) 39 | } 40 | 41 | exit() 42 | 43 | return markdownTable(result, { 44 | align: node.align, 45 | alignDelimiters: alignDelimiters, 46 | padding: padding, 47 | stringLength: stringLength 48 | }) 49 | } 50 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/image.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var uri = require('../util/enclose-uri') 4 | var title = require('../util/enclose-title') 5 | 6 | module.exports = image 7 | 8 | var space = ' ' 9 | var leftParenthesis = '(' 10 | var rightParenthesis = ')' 11 | var leftSquareBracket = '[' 12 | var rightSquareBracket = ']' 13 | var exclamationMark = '!' 14 | 15 | // Stringify an image. 16 | // 17 | // Is smart about enclosing `url` (see `encloseURI()`) and `title` (see 18 | // `encloseTitle()`). 19 | // 20 | // ```markdown 21 | // ![foo]( 'My "favourite" icon') 22 | // ``` 23 | // 24 | // Supports named entities in `url`, `alt`, and `title` when in 25 | // `settings.encode` mode. 26 | function image(node) { 27 | var self = this 28 | var content = uri(self.encode(node.url || '', node)) 29 | var exit = self.enterLink() 30 | var alt = self.encode(self.escape(node.alt || '', node)) 31 | 32 | exit() 33 | 34 | if (node.title) { 35 | content += space + title(self.encode(node.title, node)) 36 | } 37 | 38 | return ( 39 | exclamationMark + 40 | leftSquareBracket + 41 | alt + 42 | rightSquareBracket + 43 | leftParenthesis + 44 | content + 45 | rightParenthesis 46 | ) 47 | } 48 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2014-2016 Titus Wormer 4 | Copyright (c) 2011-2014, Christopher Jeffrey (https://github.com/chjj/) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/tokenize/blank-line.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | // A line containing no characters, or a line containing only spaces (U+0020) or 4 | // tabs (U+0009), is called a blank line. 5 | // See . 6 | var reBlankLine = /^[ \t]*(\n|$)/ 7 | 8 | // Note that though blank lines play a special role in lists to determine 9 | // whether the list is tight or loose 10 | // (), it’s done by the list 11 | // tokenizer and this blank line tokenizer does not have to be responsible for 12 | // that. 13 | // Therefore, configs such as `blankLine.notInList` do not have to be set here. 14 | module.exports = blankLine 15 | 16 | function blankLine(eat, value, silent) { 17 | var match 18 | var subvalue = '' 19 | var index = 0 20 | var length = value.length 21 | 22 | while (index < length) { 23 | match = reBlankLine.exec(value.slice(index)) 24 | 25 | if (match == null) { 26 | break 27 | } 28 | 29 | index += match[0].length 30 | subvalue += match[0] 31 | } 32 | 33 | if (subvalue === '') { 34 | return 35 | } 36 | 37 | /* istanbul ignore if - never used (yet) */ 38 | if (silent) { 39 | return true 40 | } 41 | 42 | eat(subvalue) 43 | } 44 | -------------------------------------------------------------------------------- /packages/remark/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "remark", 3 | "version": "12.0.0", 4 | "description": "Markdown processor powered by plugins part of the unified collective", 5 | "license": "MIT", 6 | "keywords": [ 7 | "unified", 8 | "remark", 9 | "markdown", 10 | "mdast", 11 | "abstract", 12 | "syntax", 13 | "tree", 14 | "ast", 15 | "parse", 16 | "stringify", 17 | "serialize", 18 | "compile", 19 | "process" 20 | ], 21 | "homepage": "https://remark.js.org", 22 | "repository": "https://github.com/remarkjs/remark/tree/master/packages/remark", 23 | "bugs": "https://github.com/remarkjs/remark/issues", 24 | "funding": { 25 | "type": "opencollective", 26 | "url": "https://opencollective.com/unified" 27 | }, 28 | "author": "Titus Wormer (https://wooorm.com)", 29 | "contributors": [ 30 | "Titus Wormer (https://wooorm.com)" 31 | ], 32 | "files": [ 33 | "index.js", 34 | "types/index.d.ts" 35 | ], 36 | "types": "types/index.d.ts", 37 | "dependencies": { 38 | "remark-parse": "^8.0.0", 39 | "remark-stringify": "^8.0.0", 40 | "unified": "^9.0.0" 41 | }, 42 | "scripts": { 43 | "test": "tape test.js" 44 | }, 45 | "xo": false 46 | } 47 | -------------------------------------------------------------------------------- /test/fixtures/tree/blockquote-lazy-code.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "blockquote", 6 | "children": [ 7 | { 8 | "type": "code", 9 | "lang": null, 10 | "meta": null, 11 | "value": "foo\nbar", 12 | "position": { 13 | "start": { 14 | "line": 1, 15 | "column": 3, 16 | "offset": 2 17 | }, 18 | "end": { 19 | "line": 2, 20 | "column": 8, 21 | "offset": 17 22 | }, 23 | "indent": [ 24 | 1 25 | ] 26 | } 27 | } 28 | ], 29 | "position": { 30 | "start": { 31 | "line": 1, 32 | "column": 1, 33 | "offset": 0 34 | }, 35 | "end": { 36 | "line": 2, 37 | "column": 8, 38 | "offset": 17 39 | }, 40 | "indent": [ 41 | 1 42 | ] 43 | } 44 | } 45 | ], 46 | "position": { 47 | "start": { 48 | "line": 1, 49 | "column": 1, 50 | "offset": 0 51 | }, 52 | "end": { 53 | "line": 3, 54 | "column": 1, 55 | "offset": 18 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/fixtures/tree/heading-in-paragraph.commonmark.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Hello\nWorld\n===", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 3, 18 | "column": 4, 19 | "offset": 15 20 | }, 21 | "indent": [ 22 | 1, 23 | 1 24 | ] 25 | } 26 | } 27 | ], 28 | "position": { 29 | "start": { 30 | "line": 1, 31 | "column": 1, 32 | "offset": 0 33 | }, 34 | "end": { 35 | "line": 3, 36 | "column": 4, 37 | "offset": 15 38 | }, 39 | "indent": [ 40 | 1, 41 | 1 42 | ] 43 | } 44 | } 45 | ], 46 | "position": { 47 | "start": { 48 | "line": 1, 49 | "column": 1, 50 | "offset": 0 51 | }, 52 | "end": { 53 | "line": 4, 54 | "column": 1, 55 | "offset": 16 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/fixtures/tree/table-no-end-of-line.nogfm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "|foo|bar|\n|-|-|\n|1|2|", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 3, 18 | "column": 6, 19 | "offset": 21 20 | }, 21 | "indent": [ 22 | 1, 23 | 1 24 | ] 25 | } 26 | } 27 | ], 28 | "position": { 29 | "start": { 30 | "line": 1, 31 | "column": 1, 32 | "offset": 0 33 | }, 34 | "end": { 35 | "line": 3, 36 | "column": 6, 37 | "offset": 21 38 | }, 39 | "indent": [ 40 | 1, 41 | 1 42 | ] 43 | } 44 | } 45 | ], 46 | "position": { 47 | "start": { 48 | "line": 1, 49 | "column": 1, 50 | "offset": 0 51 | }, 52 | "end": { 53 | "line": 3, 54 | "column": 6, 55 | "offset": 21 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/tokenize/text.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = text 4 | 5 | function text(eat, value, silent) { 6 | var self = this 7 | var methods 8 | var tokenizers 9 | var index 10 | var length 11 | var subvalue 12 | var position 13 | var tokenizer 14 | var name 15 | var min 16 | var now 17 | 18 | /* istanbul ignore if - never used (yet) */ 19 | if (silent) { 20 | return true 21 | } 22 | 23 | methods = self.inlineMethods 24 | length = methods.length 25 | tokenizers = self.inlineTokenizers 26 | index = -1 27 | min = value.length 28 | 29 | while (++index < length) { 30 | name = methods[index] 31 | 32 | if (name === 'text' || !tokenizers[name]) { 33 | continue 34 | } 35 | 36 | tokenizer = tokenizers[name].locator 37 | 38 | if (!tokenizer) { 39 | eat.file.fail('Missing locator: `' + name + '`') 40 | } 41 | 42 | position = tokenizer.call(self, value, 1) 43 | 44 | if (position !== -1 && position < min) { 45 | min = position 46 | } 47 | } 48 | 49 | subvalue = value.slice(0, min) 50 | now = eat.now() 51 | 52 | self.decode(subvalue, now, handler) 53 | 54 | function handler(content, position, source) { 55 | eat(source || content)({type: 'text', value: content}) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/tree/fenced-code-white-space-after-flag.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "code", 6 | "lang": "js", 7 | "meta": null, 8 | "value": "foo();", 9 | "position": { 10 | "start": { 11 | "line": 1, 12 | "column": 1, 13 | "offset": 0 14 | }, 15 | "end": { 16 | "line": 3, 17 | "column": 4, 18 | "offset": 18 19 | }, 20 | "indent": [ 21 | 1, 22 | 1 23 | ] 24 | } 25 | }, 26 | { 27 | "type": "code", 28 | "lang": "bash", 29 | "meta": null, 30 | "value": "echo \"hello, ${WORLD}\"", 31 | "position": { 32 | "start": { 33 | "line": 5, 34 | "column": 1, 35 | "offset": 20 36 | }, 37 | "end": { 38 | "line": 7, 39 | "column": 6, 40 | "offset": 60 41 | }, 42 | "indent": [ 43 | 1, 44 | 1 45 | ] 46 | } 47 | } 48 | ], 49 | "position": { 50 | "start": { 51 | "line": 1, 52 | "column": 1, 53 | "offset": 0 54 | }, 55 | "end": { 56 | "line": 8, 57 | "column": 1, 58 | "offset": 61 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/fixtures/tree/list-item-empty-with-white-space.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "list", 6 | "ordered": false, 7 | "start": null, 8 | "spread": false, 9 | "children": [ 10 | { 11 | "type": "listItem", 12 | "spread": false, 13 | "checked": null, 14 | "children": [], 15 | "position": { 16 | "start": { 17 | "line": 1, 18 | "column": 1, 19 | "offset": 0 20 | }, 21 | "end": { 22 | "line": 1, 23 | "column": 3, 24 | "offset": 2 25 | }, 26 | "indent": [] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 1, 34 | "offset": 0 35 | }, 36 | "end": { 37 | "line": 1, 38 | "column": 3, 39 | "offset": 2 40 | }, 41 | "indent": [] 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 1, 49 | "offset": 0 50 | }, 51 | "end": { 52 | "line": 2, 53 | "column": 1, 54 | "offset": 3 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/tree/list-item-empty-without-white-space.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "list", 6 | "ordered": false, 7 | "start": null, 8 | "spread": false, 9 | "children": [ 10 | { 11 | "type": "listItem", 12 | "spread": false, 13 | "checked": null, 14 | "children": [], 15 | "position": { 16 | "start": { 17 | "line": 1, 18 | "column": 1, 19 | "offset": 0 20 | }, 21 | "end": { 22 | "line": 1, 23 | "column": 2, 24 | "offset": 1 25 | }, 26 | "indent": [] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 1, 34 | "offset": 0 35 | }, 36 | "end": { 37 | "line": 1, 38 | "column": 2, 39 | "offset": 1 40 | }, 41 | "indent": [] 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 1, 49 | "offset": 0 50 | }, 51 | "end": { 52 | "line": 2, 53 | "column": 1, 54 | "offset": 2 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/tree/list-ordered-empty-no-space-single-item.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "list", 6 | "ordered": true, 7 | "start": 1, 8 | "spread": false, 9 | "children": [ 10 | { 11 | "type": "listItem", 12 | "spread": false, 13 | "checked": null, 14 | "children": [], 15 | "position": { 16 | "start": { 17 | "line": 1, 18 | "column": 1, 19 | "offset": 0 20 | }, 21 | "end": { 22 | "line": 1, 23 | "column": 3, 24 | "offset": 2 25 | }, 26 | "indent": [] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 1, 34 | "offset": 0 35 | }, 36 | "end": { 37 | "line": 1, 38 | "column": 3, 39 | "offset": 2 40 | }, 41 | "indent": [] 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 1, 49 | "offset": 0 50 | }, 51 | "end": { 52 | "line": 1, 53 | "column": 3, 54 | "offset": 2 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/tree/list-item-empty-without-white-space-eof.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "list", 6 | "ordered": false, 7 | "start": null, 8 | "spread": false, 9 | "children": [ 10 | { 11 | "type": "listItem", 12 | "spread": false, 13 | "checked": null, 14 | "children": [], 15 | "position": { 16 | "start": { 17 | "line": 1, 18 | "column": 1, 19 | "offset": 0 20 | }, 21 | "end": { 22 | "line": 1, 23 | "column": 2, 24 | "offset": 1 25 | }, 26 | "indent": [] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 1, 34 | "offset": 0 35 | }, 36 | "end": { 37 | "line": 1, 38 | "column": 2, 39 | "offset": 1 40 | }, 41 | "indent": [] 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 1, 49 | "offset": 0 50 | }, 51 | "end": { 52 | "line": 1, 53 | "column": 2, 54 | "offset": 1 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/tree/list-unordered-empty-no-space-single-item.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "list", 6 | "ordered": false, 7 | "start": null, 8 | "spread": false, 9 | "children": [ 10 | { 11 | "type": "listItem", 12 | "spread": false, 13 | "checked": null, 14 | "children": [], 15 | "position": { 16 | "start": { 17 | "line": 1, 18 | "column": 1, 19 | "offset": 0 20 | }, 21 | "end": { 22 | "line": 1, 23 | "column": 2, 24 | "offset": 1 25 | }, 26 | "indent": [] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 1, 34 | "offset": 0 35 | }, 36 | "end": { 37 | "line": 1, 38 | "column": 2, 39 | "offset": 1 40 | }, 41 | "indent": [] 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 1, 49 | "offset": 0 50 | }, 51 | "end": { 52 | "line": 1, 53 | "column": 2, 54 | "offset": 1 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/tree/list-ordered-empty-no-space-single-item.commonmark.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "list", 6 | "ordered": true, 7 | "start": 1, 8 | "spread": false, 9 | "children": [ 10 | { 11 | "type": "listItem", 12 | "spread": false, 13 | "checked": null, 14 | "children": [], 15 | "position": { 16 | "start": { 17 | "line": 1, 18 | "column": 1, 19 | "offset": 0 20 | }, 21 | "end": { 22 | "line": 1, 23 | "column": 3, 24 | "offset": 2 25 | }, 26 | "indent": [] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 1, 34 | "offset": 0 35 | }, 36 | "end": { 37 | "line": 1, 38 | "column": 3, 39 | "offset": 2 40 | }, 41 | "indent": [] 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 1, 49 | "offset": 0 50 | }, 51 | "end": { 52 | "line": 1, 53 | "column": 3, 54 | "offset": 2 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/tree/list-unordered-empty-no-space-single-item.commonmark.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "list", 6 | "ordered": false, 7 | "start": null, 8 | "spread": false, 9 | "children": [ 10 | { 11 | "type": "listItem", 12 | "spread": false, 13 | "checked": null, 14 | "children": [], 15 | "position": { 16 | "start": { 17 | "line": 1, 18 | "column": 1, 19 | "offset": 0 20 | }, 21 | "end": { 22 | "line": 1, 23 | "column": 2, 24 | "offset": 1 25 | }, 26 | "indent": [] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 1, 34 | "offset": 0 35 | }, 36 | "end": { 37 | "line": 1, 38 | "column": 2, 39 | "offset": 1 40 | }, 41 | "indent": [] 42 | } 43 | } 44 | ], 45 | "position": { 46 | "start": { 47 | "line": 1, 48 | "column": 1, 49 | "offset": 0 50 | }, 51 | "end": { 52 | "line": 1, 53 | "column": 2, 54 | "offset": 1 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/tree/table-empty-initial-cell.nogfm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "| | a|c|\n|--|:----:|:---|\n|a|b|c|\n|a|b|c|", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 4, 18 | "column": 8, 19 | "offset": 41 20 | }, 21 | "indent": [ 22 | 1, 23 | 1, 24 | 1 25 | ] 26 | } 27 | } 28 | ], 29 | "position": { 30 | "start": { 31 | "line": 1, 32 | "column": 1, 33 | "offset": 0 34 | }, 35 | "end": { 36 | "line": 4, 37 | "column": 8, 38 | "offset": 41 39 | }, 40 | "indent": [ 41 | 1, 42 | 1, 43 | 1 44 | ] 45 | } 46 | } 47 | ], 48 | "position": { 49 | "start": { 50 | "line": 1, 51 | "column": 1, 52 | "offset": 0 53 | }, 54 | "end": { 55 | "line": 5, 56 | "column": 1, 57 | "offset": 42 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/fixtures/input/main.text: -------------------------------------------------------------------------------- 1 | [test]: http://google.com/ "Google" 2 | 3 | # A heading 4 | 5 | Just a note, I've found that I can't test my markdown parser vs others. 6 | For example, both markdown.js and showdown code blocks in lists wrong. They're 7 | also completely [inconsistent][test] with regards to paragraphs in list items. 8 | 9 | A link. Not anymore. 10 | 11 | 13 | 14 | * List Item 1 15 | 16 | * List Item 2 17 | * New List Item 1 18 | Hi, this is a list item. 19 | * New List Item 2 20 | Another item 21 | Code goes here. 22 | Lots of it... 23 | * New List Item 3 24 | The last item 25 | 26 | * List Item 3 27 | The final item. 28 | 29 | * List Item 4 30 | The real final item. 31 | 32 | Paragraph. 33 | 34 | > * bq Item 1 35 | > * bq Item 2 36 | > * New bq Item 1 37 | > * New bq Item 2 38 | > Text here 39 | 40 | * * * 41 | 42 | > Another blockquote! 43 | > I really need to get 44 | > more creative with 45 | > mockup text.. 46 | > markdown.js breaks here again 47 | 48 | Another Heading 49 | ------------- 50 | 51 | Hello *world*. Here is a [link](//hello). 52 | And an image ![alt](src "a title"). 53 | And an image with an empty alt attribute ![](src). 54 | 55 | Code goes here. 56 | Lots of it... 57 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/tokenize/delete.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var whitespace = require('is-whitespace-character') 4 | var locate = require('../locate/delete') 5 | 6 | module.exports = strikethrough 7 | strikethrough.locator = locate 8 | 9 | var tilde = '~' 10 | var fence = '~~' 11 | 12 | function strikethrough(eat, value, silent) { 13 | var self = this 14 | var character = '' 15 | var previous = '' 16 | var preceding = '' 17 | var subvalue = '' 18 | var index 19 | var length 20 | var now 21 | 22 | if ( 23 | !self.options.gfm || 24 | value.charAt(0) !== tilde || 25 | value.charAt(1) !== tilde || 26 | whitespace(value.charAt(2)) 27 | ) { 28 | return 29 | } 30 | 31 | index = 1 32 | length = value.length 33 | now = eat.now() 34 | now.column += 2 35 | now.offset += 2 36 | 37 | while (++index < length) { 38 | character = value.charAt(index) 39 | 40 | if ( 41 | character === tilde && 42 | previous === tilde && 43 | (!preceding || !whitespace(preceding)) 44 | ) { 45 | /* istanbul ignore if - never used (yet) */ 46 | if (silent) { 47 | return true 48 | } 49 | 50 | return eat(fence + subvalue + fence)({ 51 | type: 'delete', 52 | children: self.tokenizeInline(subvalue, now) 53 | }) 54 | } 55 | 56 | subvalue += previous 57 | preceding = previous 58 | previous = character 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/tokenize/html-inline.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var alphabetical = require('is-alphabetical') 4 | var locate = require('../locate/tag') 5 | var tag = require('../util/html').tag 6 | 7 | module.exports = inlineHTML 8 | inlineHTML.locator = locate 9 | 10 | var lessThan = '<' 11 | var questionMark = '?' 12 | var exclamationMark = '!' 13 | var slash = '/' 14 | 15 | var htmlLinkOpenExpression = /^/i 17 | 18 | function inlineHTML(eat, value, silent) { 19 | var self = this 20 | var length = value.length 21 | var character 22 | var subvalue 23 | 24 | if (value.charAt(0) !== lessThan || length < 3) { 25 | return 26 | } 27 | 28 | character = value.charAt(1) 29 | 30 | if ( 31 | !alphabetical(character) && 32 | character !== questionMark && 33 | character !== exclamationMark && 34 | character !== slash 35 | ) { 36 | return 37 | } 38 | 39 | subvalue = value.match(tag) 40 | 41 | if (!subvalue) { 42 | return 43 | } 44 | 45 | /* istanbul ignore if - not used yet. */ 46 | if (silent) { 47 | return true 48 | } 49 | 50 | subvalue = subvalue[0] 51 | 52 | if (!self.inLink && htmlLinkOpenExpression.test(subvalue)) { 53 | self.inLink = true 54 | } else if (self.inLink && htmlLinkCloseExpression.test(subvalue)) { 55 | self.inLink = false 56 | } 57 | 58 | return eat(subvalue)({type: 'html', value: subvalue}) 59 | } 60 | -------------------------------------------------------------------------------- /packages/remark-stringify/types/index.d.ts: -------------------------------------------------------------------------------- 1 | // TypeScript Version: 3.0 2 | 3 | import {Compiler, Processor, Plugin} from 'unified' 4 | import {Node, Parent} from 'unist' 5 | 6 | declare class RemarkCompiler implements Compiler { 7 | compile(): string 8 | visitors: { 9 | [key: string]: remarkStringify.Visitor 10 | } 11 | } 12 | 13 | declare namespace remarkStringify { 14 | interface Stringify extends Plugin<[PartialRemarkStringifyOptions?]> { 15 | Compiler: typeof RemarkCompiler 16 | (this: Processor, options?: PartialRemarkStringifyOptions): void 17 | } 18 | 19 | type Compiler = RemarkCompiler 20 | 21 | interface RemarkStringifyOptions { 22 | gfm: boolean 23 | commonmark: boolean 24 | entities: boolean | 'numbers' | 'escape' 25 | setext: boolean 26 | closeAtx: boolean 27 | tableCellPadding: boolean 28 | tablePipeAlign: boolean 29 | stringLength: (s: string) => number 30 | fence: '~' | '`' 31 | fences: boolean 32 | bullet: '-' | '*' | '+' 33 | listItemIndent: 'tab' | '1' | 'mixed' 34 | incrementListMarker: boolean 35 | tightDefinitions: boolean 36 | rule: '-' | '_' | '*' 37 | ruleRepetition: number 38 | ruleSpaces: boolean 39 | strong: '_' | '*' 40 | emphasis: '_' | '*' 41 | } 42 | 43 | type PartialRemarkStringifyOptions = Partial 44 | 45 | type Visitor = (node: Node, parent?: Parent) => string 46 | } 47 | 48 | declare const remarkStringify: remarkStringify.Stringify 49 | 50 | export = remarkStringify 51 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/tokenize/thematic-break.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = thematicBreak 4 | 5 | var tab = '\t' 6 | var lineFeed = '\n' 7 | var space = ' ' 8 | var asterisk = '*' 9 | var dash = '-' 10 | var underscore = '_' 11 | 12 | var maxCount = 3 13 | 14 | function thematicBreak(eat, value, silent) { 15 | var index = -1 16 | var length = value.length + 1 17 | var subvalue = '' 18 | var character 19 | var marker 20 | var markerCount 21 | var queue 22 | 23 | while (++index < length) { 24 | character = value.charAt(index) 25 | 26 | if (character !== tab && character !== space) { 27 | break 28 | } 29 | 30 | subvalue += character 31 | } 32 | 33 | if ( 34 | character !== asterisk && 35 | character !== dash && 36 | character !== underscore 37 | ) { 38 | return 39 | } 40 | 41 | marker = character 42 | subvalue += character 43 | markerCount = 1 44 | queue = '' 45 | 46 | while (++index < length) { 47 | character = value.charAt(index) 48 | 49 | if (character === marker) { 50 | markerCount++ 51 | subvalue += queue + marker 52 | queue = '' 53 | } else if (character === space) { 54 | queue += character 55 | } else if ( 56 | markerCount >= maxCount && 57 | (!character || character === lineFeed) 58 | ) { 59 | subvalue += queue 60 | 61 | if (silent) { 62 | return true 63 | } 64 | 65 | return eat(subvalue)({type: 'thematicBreak'}) 66 | } else { 67 | return 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/decode.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var xtend = require('xtend') 4 | var entities = require('parse-entities') 5 | 6 | module.exports = factory 7 | 8 | // Factory to create an entity decoder. 9 | function factory(ctx) { 10 | decoder.raw = decodeRaw 11 | 12 | return decoder 13 | 14 | // Normalize `position` to add an `indent`. 15 | function normalize(position) { 16 | var offsets = ctx.offset 17 | var line = position.line 18 | var result = [] 19 | 20 | while (++line) { 21 | if (!(line in offsets)) { 22 | break 23 | } 24 | 25 | result.push((offsets[line] || 0) + 1) 26 | } 27 | 28 | return {start: position, indent: result} 29 | } 30 | 31 | // Decode `value` (at `position`) into text-nodes. 32 | function decoder(value, position, handler) { 33 | entities(value, { 34 | position: normalize(position), 35 | warning: handleWarning, 36 | text: handler, 37 | reference: handler, 38 | textContext: ctx, 39 | referenceContext: ctx 40 | }) 41 | } 42 | 43 | // Decode `value` (at `position`) into a string. 44 | function decodeRaw(value, position, options) { 45 | return entities( 46 | value, 47 | xtend(options, {position: normalize(position), warning: handleWarning}) 48 | ) 49 | } 50 | 51 | // Handle a warning. 52 | // See for the warnings. 53 | function handleWarning(reason, position, code) { 54 | if (code !== 3) { 55 | ctx.file.message(reason, position) 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /packages/remark-stringify/lib/visitors/inline-code.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var streak = require('longest-streak') 4 | var repeat = require('repeat-string') 5 | 6 | module.exports = inlineCode 7 | 8 | var graveAccentChar = '`' 9 | var lineFeed = 10 // '\n' 10 | var space = 32 // ' ' 11 | var graveAccent = 96 // '`' 12 | 13 | // Stringify inline code. 14 | // 15 | // Knows about internal ticks (`\``), and ensures one more tick is used to 16 | // enclose the inline code: 17 | // 18 | // ````markdown 19 | // ```foo ``bar`` baz``` 20 | // ```` 21 | // 22 | // Even knows about inital and final ticks: 23 | // 24 | // ``markdown 25 | // `` `foo `` 26 | // `` foo` `` 27 | // ``` 28 | function inlineCode(node) { 29 | var value = node.value 30 | var ticks = repeat(graveAccentChar, streak(value, graveAccentChar) + 1) 31 | var start = ticks 32 | var end = ticks 33 | var head = value.charCodeAt(0) 34 | var tail = value.charCodeAt(value.length - 1) 35 | var wrap = false 36 | var index 37 | var length 38 | 39 | if (head === graveAccent || tail === graveAccent) { 40 | wrap = true 41 | } else if (value.length > 2 && ws(head) && ws(tail)) { 42 | index = 1 43 | length = value.length - 1 44 | 45 | while (++index < length) { 46 | if (!ws(value.charCodeAt(index))) { 47 | wrap = true 48 | break 49 | } 50 | } 51 | } 52 | 53 | if (wrap) { 54 | start += ' ' 55 | end = ' ' + end 56 | } 57 | 58 | return start + value + end 59 | } 60 | 61 | function ws(code) { 62 | return code === lineFeed || code === space 63 | } 64 | -------------------------------------------------------------------------------- /test/fixtures/tree/not-a-link.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "[", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 3, 19 | "offset": 2 20 | }, 21 | "indent": [] 22 | } 23 | }, 24 | { 25 | "type": "text", 26 | "value": "test](not a link)", 27 | "position": { 28 | "start": { 29 | "line": 1, 30 | "column": 3, 31 | "offset": 2 32 | }, 33 | "end": { 34 | "line": 1, 35 | "column": 20, 36 | "offset": 19 37 | }, 38 | "indent": [] 39 | } 40 | } 41 | ], 42 | "position": { 43 | "start": { 44 | "line": 1, 45 | "column": 1, 46 | "offset": 0 47 | }, 48 | "end": { 49 | "line": 1, 50 | "column": 20, 51 | "offset": 19 52 | }, 53 | "indent": [] 54 | } 55 | } 56 | ], 57 | "position": { 58 | "start": { 59 | "line": 1, 60 | "column": 1, 61 | "offset": 0 62 | }, 63 | "end": { 64 | "line": 2, 65 | "column": 1, 66 | "offset": 20 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /test/fixtures/input/task-list.text: -------------------------------------------------------------------------------- 1 | Empty items 2 | =========== 3 | 4 | * [ ] 5 | * [ ] 6 | 7 | 1. [x] 8 | 2. [X] 9 | 10 | Single space 11 | ============ 12 | 13 | * [ ] 14 | * [ ] 15 | 16 | 1. [x] 17 | 2. [X] 18 | 19 | Tab 20 | === 21 | 22 | * [ ] 23 | * [ ] 24 | 25 | 1. [x] 26 | 2. [X] 27 | 28 | No white space with content 29 | =========================== 30 | 31 | * [ ]Hello; 32 | * [ ]World; 33 | 34 | 1. [x]Foo. 35 | 2. [X]Bar 36 | 37 | Single space with content 38 | ========================= 39 | 40 | * [ ] Hello; 41 | * [ ] World; 42 | 43 | 1. [x] Foo. 44 | 2. [X] World :D 45 | 46 | Single tab with content 47 | ======================= 48 | 49 | * [ ] Hello; 50 | * [ ] World; 51 | 52 | 1. [x] Foo. 53 | 2. [X] Hello. 54 | 55 | Multiple spaces with content 56 | ============================ 57 | 58 | * [ ] Hello; 59 | * [ ] World; 60 | 61 | 1. [x] Foo. 62 | 3. [X] Bar. 63 | 64 | Multiple tabs with content 65 | ========================== 66 | 67 | * [ ] Hello; 68 | * [ ] World; 69 | 70 | 1. [x] Foo. 71 | 2. [X] Bar. 72 | 73 | Mixed tabs and spaces 74 | ===================== 75 | 76 | * [ ] Hello; 77 | 78 | 1. [x] World; 79 | 80 | * [ ] Hello; 81 | * [ ] World. 82 | 83 | 2. [X] Bar. 84 | 85 | Line breaks 86 | =========== 87 | 88 | * [ 89 | ] Hello; 90 | 91 | 1. [ 92 | ] Hello; 93 | 94 | Multiple unfinished characters 95 | ============================== 96 | 97 | * [ ] Hello; 98 | 99 | 1. [ 100 | ] World; 101 | 2. [ ] Hello; 102 | 3. [ ] World. 103 | -------------------------------------------------------------------------------- /test/fixtures/input/entities.output.noentities.text: -------------------------------------------------------------------------------- 1 | # Entities 2 | 3 | Plain text: 4 | 5 | AT&T with entity, AT&T with numeric entity, AT&T without entity. 6 | 7 | Fenced code language flags: 8 | 9 | ```AT&T 10 | Something in the AT&T language 11 | ``` 12 | 13 | ```AT&T 14 | Something in the AT&T language 15 | ``` 16 | 17 | Automatic links: 18 | 19 | , , and . 20 | 21 | Link `href`: 22 | 23 | [With entity](http://at&t.com), [numeric entity](http://at&t.com), [without entity](http://at&t.com). 24 | 25 | Link `title`: 26 | 27 | [With entity](http://att.com "AT&T"), [numeric entity](http://att.com "AT&T"), [without entity](http://example.com "AT&T"). 28 | 29 | Image `src`: 30 | 31 | ![With entity](http://at&t.com/fav.ico), ![numeric entity](http://at&t.com/fav.ico), ![without entity](http://at&t.com/fav.ico). 32 | 33 | Image `alt`: 34 | 35 | ![AT&T with entity](http://att.com/fav.ico), ![AT&T with numeric entity](http://att.com/fav.ico), ![AT&T without entity](http://att.com/fav.ico). 36 | 37 | Image `title`: 38 | 39 | ![With entity](http://att.com/fav.ico "AT&T"), ![numeric entity](http://att.com/fav.ico "AT&T"), ![without entity](http://att.com/fav.ico "AT&T"). 40 | 41 | Image Reference `alt`: 42 | 43 | ![AT&T with entity][favicon], ![AT&T with numeric entity][favicon], ![AT&T without entity][favicon]. 44 | 45 | [favicon]: http://att.com/fav.ico "ATT favicon" 46 | 47 | Shortcut and collapsed references: 48 | 49 | [foo&bar], [foo&bar][], [foo&bar], [foo&bar][]. 50 | 51 | [foo&bar]: http://example.com 52 | 53 | [foo&bar]: http://example.com 54 | -------------------------------------------------------------------------------- /test/fixtures/tree/code-blocks.output.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "A code block NOT using fences:", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 31, 19 | "offset": 30 20 | }, 21 | "indent": [] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 1, 33 | "column": 31, 34 | "offset": 30 35 | }, 36 | "indent": [] 37 | } 38 | }, 39 | { 40 | "type": "code", 41 | "lang": null, 42 | "meta": null, 43 | "value": "alert('Hello World!');", 44 | "position": { 45 | "start": { 46 | "line": 3, 47 | "column": 1, 48 | "offset": 32 49 | }, 50 | "end": { 51 | "line": 3, 52 | "column": 27, 53 | "offset": 58 54 | }, 55 | "indent": [] 56 | } 57 | } 58 | ], 59 | "position": { 60 | "start": { 61 | "line": 1, 62 | "column": 1, 63 | "offset": 0 64 | }, 65 | "end": { 66 | "line": 4, 67 | "column": 1, 68 | "offset": 59 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/fixtures/tree/blockquote-lazy-code.commonmark.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "blockquote", 6 | "children": [ 7 | { 8 | "type": "code", 9 | "lang": null, 10 | "meta": null, 11 | "value": "foo", 12 | "position": { 13 | "start": { 14 | "line": 1, 15 | "column": 3, 16 | "offset": 2 17 | }, 18 | "end": { 19 | "line": 1, 20 | "column": 10, 21 | "offset": 9 22 | }, 23 | "indent": [] 24 | } 25 | } 26 | ], 27 | "position": { 28 | "start": { 29 | "line": 1, 30 | "column": 1, 31 | "offset": 0 32 | }, 33 | "end": { 34 | "line": 1, 35 | "column": 10, 36 | "offset": 9 37 | }, 38 | "indent": [] 39 | } 40 | }, 41 | { 42 | "type": "code", 43 | "lang": null, 44 | "meta": null, 45 | "value": "bar", 46 | "position": { 47 | "start": { 48 | "line": 2, 49 | "column": 1, 50 | "offset": 10 51 | }, 52 | "end": { 53 | "line": 2, 54 | "column": 8, 55 | "offset": 17 56 | }, 57 | "indent": [] 58 | } 59 | } 60 | ], 61 | "position": { 62 | "start": { 63 | "line": 1, 64 | "column": 1, 65 | "offset": 0 66 | }, 67 | "end": { 68 | "line": 3, 69 | "column": 1, 70 | "offset": 18 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /test/fixtures/tree/code-block.output.fence=`.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Ticks:", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 7, 19 | "offset": 6 20 | }, 21 | "indent": [] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 1, 33 | "column": 7, 34 | "offset": 6 35 | }, 36 | "indent": [] 37 | } 38 | }, 39 | { 40 | "type": "code", 41 | "lang": "javascript", 42 | "meta": null, 43 | "value": "alert('Hello World!');", 44 | "position": { 45 | "start": { 46 | "line": 3, 47 | "column": 1, 48 | "offset": 8 49 | }, 50 | "end": { 51 | "line": 5, 52 | "column": 4, 53 | "offset": 48 54 | }, 55 | "indent": [ 56 | 1, 57 | 1 58 | ] 59 | } 60 | } 61 | ], 62 | "position": { 63 | "start": { 64 | "line": 1, 65 | "column": 1, 66 | "offset": 0 67 | }, 68 | "end": { 69 | "line": 6, 70 | "column": 1, 71 | "offset": 49 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/fixtures/tree/code-block.output.fence=~.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "Tildes:", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 8, 19 | "offset": 7 20 | }, 21 | "indent": [] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 1, 33 | "column": 8, 34 | "offset": 7 35 | }, 36 | "indent": [] 37 | } 38 | }, 39 | { 40 | "type": "code", 41 | "lang": "javascript", 42 | "meta": null, 43 | "value": "alert('Hello World!');", 44 | "position": { 45 | "start": { 46 | "line": 3, 47 | "column": 1, 48 | "offset": 9 49 | }, 50 | "end": { 51 | "line": 5, 52 | "column": 4, 53 | "offset": 49 54 | }, 55 | "indent": [ 56 | 1, 57 | 1 58 | ] 59 | } 60 | } 61 | ], 62 | "position": { 63 | "start": { 64 | "line": 1, 65 | "column": 1, 66 | "offset": 0 67 | }, 68 | "end": { 69 | "line": 6, 70 | "column": 1, 71 | "offset": 50 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /packages/remark-parse/lib/util/remove-indentation.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var trim = require('trim') 4 | var repeat = require('repeat-string') 5 | var getIndent = require('./get-indentation') 6 | 7 | module.exports = indentation 8 | 9 | var lineFeed = '\n' 10 | var space = ' ' 11 | var exclamationMark = '!' 12 | 13 | // Remove the minimum indent from every line in `value`. Supports both tab, 14 | // spaced, and mixed indentation (as well as possible). 15 | function indentation(value, maximum) { 16 | var values = value.split(lineFeed) 17 | var position = values.length + 1 18 | var minIndent = Infinity 19 | var matrix = [] 20 | var index 21 | var indentation 22 | var stops 23 | 24 | values.unshift(repeat(space, maximum) + exclamationMark) 25 | 26 | while (position--) { 27 | indentation = getIndent(values[position]) 28 | 29 | matrix[position] = indentation.stops 30 | 31 | if (trim(values[position]).length === 0) { 32 | continue 33 | } 34 | 35 | if (indentation.indent) { 36 | if (indentation.indent > 0 && indentation.indent < minIndent) { 37 | minIndent = indentation.indent 38 | } 39 | } else { 40 | minIndent = Infinity 41 | 42 | break 43 | } 44 | } 45 | 46 | if (minIndent !== Infinity) { 47 | position = values.length 48 | 49 | while (position--) { 50 | stops = matrix[position] 51 | index = minIndent 52 | 53 | while (index && !(index in stops)) { 54 | index-- 55 | } 56 | 57 | values[position] = values[position].slice(stops[index] + 1) 58 | } 59 | } 60 | 61 | values.shift() 62 | 63 | return values.join(lineFeed) 64 | } 65 | -------------------------------------------------------------------------------- /test/fixtures/tree/code-blocks.output.fences.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "text", 9 | "value": "A code block using fences:", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 1, 18 | "column": 27, 19 | "offset": 26 20 | }, 21 | "indent": [] 22 | } 23 | } 24 | ], 25 | "position": { 26 | "start": { 27 | "line": 1, 28 | "column": 1, 29 | "offset": 0 30 | }, 31 | "end": { 32 | "line": 1, 33 | "column": 27, 34 | "offset": 26 35 | }, 36 | "indent": [] 37 | } 38 | }, 39 | { 40 | "type": "code", 41 | "lang": null, 42 | "meta": null, 43 | "value": "alert('Hello World!');", 44 | "position": { 45 | "start": { 46 | "line": 3, 47 | "column": 1, 48 | "offset": 28 49 | }, 50 | "end": { 51 | "line": 5, 52 | "column": 4, 53 | "offset": 58 54 | }, 55 | "indent": [ 56 | 1, 57 | 1 58 | ] 59 | } 60 | } 61 | ], 62 | "position": { 63 | "start": { 64 | "line": 1, 65 | "column": 1, 66 | "offset": 0 67 | }, 68 | "end": { 69 | "line": 6, 70 | "column": 1, 71 | "offset": 59 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/fixtures/input/ordered-and-unordered-lists.text: -------------------------------------------------------------------------------- 1 | ## Unordered 2 | 3 | Asterisks tight: 4 | 5 | * asterisk 1 6 | * asterisk 2 7 | * asterisk 3 8 | 9 | 10 | Asterisks loose: 11 | 12 | * asterisk 1 13 | 14 | * asterisk 2 15 | 16 | * asterisk 3 17 | 18 | * * * 19 | 20 | Pluses tight: 21 | 22 | + Plus 1 23 | + Plus 2 24 | + Plus 3 25 | 26 | 27 | Pluses loose: 28 | 29 | + Plus 1 30 | 31 | + Plus 2 32 | 33 | + Plus 3 34 | 35 | * * * 36 | 37 | 38 | Minuses tight: 39 | 40 | - Minus 1 41 | - Minus 2 42 | - Minus 3 43 | 44 | 45 | Minuses loose: 46 | 47 | - Minus 1 48 | 49 | - Minus 2 50 | 51 | - Minus 3 52 | 53 | 54 | ## Ordered 55 | 56 | Tight: 57 | 58 | 1. First 59 | 2. Second 60 | 3. Third 61 | 62 | and: 63 | 64 | 1. One 65 | 2. Two 66 | 3. Three 67 | 68 | 69 | Loose using tabs: 70 | 71 | 1. First 72 | 73 | 2. Second 74 | 75 | 3. Third 76 | 77 | and using spaces: 78 | 79 | 1. One 80 | 81 | 2. Two 82 | 83 | 3. Three 84 | 85 | Multiple paragraphs: 86 | 87 | 1. Item 1, graf one. 88 | 89 | Item 2. graf two. The quick brown fox jumped over the lazy dog's 90 | back. 91 | 92 | 2. Item 2. 93 | 94 | 3. Item 3. 95 | 96 | 97 | 98 | ## Nested 99 | 100 | * Tab 101 | * Tab 102 | * Tab 103 | 104 | Here's another: 105 | 106 | 1. First 107 | 2. Second: 108 | * Fee 109 | * Fie 110 | * Foe 111 | 3. Third 112 | 113 | Same thing but with paragraphs: 114 | 115 | 1. First 116 | 117 | 2. Second: 118 | * Fee 119 | * Fie 120 | * Foe 121 | 122 | 3. Third 123 | 124 | 125 | This was an error in Markdown 1.0.1: 126 | 127 | * this 128 | 129 | * sub 130 | 131 | that 132 | -------------------------------------------------------------------------------- /test/fixtures/tree/reference-image-empty-alt.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "imageReference", 9 | "identifier": "1", 10 | "label": "1", 11 | "referenceType": "full", 12 | "alt": null, 13 | "position": { 14 | "start": { 15 | "line": 1, 16 | "column": 1, 17 | "offset": 0 18 | }, 19 | "end": { 20 | "line": 1, 21 | "column": 7, 22 | "offset": 6 23 | }, 24 | "indent": [] 25 | } 26 | } 27 | ], 28 | "position": { 29 | "start": { 30 | "line": 1, 31 | "column": 1, 32 | "offset": 0 33 | }, 34 | "end": { 35 | "line": 1, 36 | "column": 7, 37 | "offset": 6 38 | }, 39 | "indent": [] 40 | } 41 | }, 42 | { 43 | "type": "definition", 44 | "identifier": "1", 45 | "label": "1", 46 | "title": null, 47 | "url": "/xyz.png", 48 | "position": { 49 | "start": { 50 | "line": 3, 51 | "column": 1, 52 | "offset": 8 53 | }, 54 | "end": { 55 | "line": 3, 56 | "column": 14, 57 | "offset": 21 58 | }, 59 | "indent": [] 60 | } 61 | } 62 | ], 63 | "position": { 64 | "start": { 65 | "line": 1, 66 | "column": 1, 67 | "offset": 0 68 | }, 69 | "end": { 70 | "line": 4, 71 | "column": 1, 72 | "offset": 22 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test/fixtures/input/entities.output.entities.text: -------------------------------------------------------------------------------- 1 | # Entities 2 | 3 | Plain text: 4 | 5 | AT&T with entity, AT&T with numeric entity, AT&T without entity. 6 | 7 | Fenced code language flags: 8 | 9 | ```AT&T 10 | Something in the AT&T language 11 | ``` 12 | 13 | ```AT&T 14 | Something in the AT&T language 15 | ``` 16 | 17 | Automatic links: 18 | 19 | , , and . 20 | 21 | Link `href`: 22 | 23 | [With entity](http://at&t.com), [numeric entity](http://at&t.com), [without entity](http://at&t.com). 24 | 25 | Link `title`: 26 | 27 | [With entity](http://att.com "AT&T"), [numeric entity](http://att.com "AT&T"), [without entity](http://example.com "AT&T"). 28 | 29 | Image `src`: 30 | 31 | ![With entity](http://at&t.com/fav.ico), ![numeric entity](http://at&t.com/fav.ico), ![without entity](http://at&t.com/fav.ico). 32 | 33 | Image `alt`: 34 | 35 | ![AT&T with entity](http://att.com/fav.ico), ![AT&T with numeric entity](http://att.com/fav.ico), ![AT&T without entity](http://att.com/fav.ico). 36 | 37 | Image `title`: 38 | 39 | ![With entity](http://att.com/fav.ico "AT&T"), ![numeric entity](http://att.com/fav.ico "AT&T"), ![without entity](http://att.com/fav.ico "AT&T"). 40 | 41 | Image Reference `alt`: 42 | 43 | ![AT&T with entity][favicon], ![AT&T with numeric entity][favicon], ![AT&T without entity][favicon]. 44 | 45 | [favicon]: http://att.com/fav.ico "ATT favicon" 46 | 47 | Shortcut and collapsed references: 48 | 49 | [foo&bar], [foo&bar][], [foo&bar], [foo&bar][]. 50 | 51 | [foo&bar]: http://example.com 52 | 53 | [foo&bar]: http://example.com 54 | -------------------------------------------------------------------------------- /test/fixtures/input/entities.output.entities=escape.text: -------------------------------------------------------------------------------- 1 | # Entities 2 | 3 | Plain text: 4 | 5 | AT&T with entity, AT&T with numeric entity, AT&T without entity. 6 | 7 | Fenced code language flags: 8 | 9 | ```AT&T 10 | Something in the AT&T language 11 | ``` 12 | 13 | ```AT&T 14 | Something in the AT&T language 15 | ``` 16 | 17 | Automatic links: 18 | 19 | , , and . 20 | 21 | Link `href`: 22 | 23 | [With entity](http://at&t.com), [numeric entity](http://at&t.com), [without entity](http://at&t.com). 24 | 25 | Link `title`: 26 | 27 | [With entity](http://att.com "AT&T"), [numeric entity](http://att.com "AT&T"), [without entity](http://example.com "AT&T"). 28 | 29 | Image `src`: 30 | 31 | ![With entity](http://at&t.com/fav.ico), ![numeric entity](http://at&t.com/fav.ico), ![without entity](http://at&t.com/fav.ico). 32 | 33 | Image `alt`: 34 | 35 | ![AT&T with entity](http://att.com/fav.ico), ![AT&T with numeric entity](http://att.com/fav.ico), ![AT&T without entity](http://att.com/fav.ico). 36 | 37 | Image `title`: 38 | 39 | ![With entity](http://att.com/fav.ico "AT&T"), ![numeric entity](http://att.com/fav.ico "AT&T"), ![without entity](http://att.com/fav.ico "AT&T"). 40 | 41 | Image Reference `alt`: 42 | 43 | ![AT&T with entity][favicon], ![AT&T with numeric entity][favicon], ![AT&T without entity][favicon]. 44 | 45 | [favicon]: http://att.com/fav.ico "ATT favicon" 46 | 47 | Shortcut and collapsed references: 48 | 49 | [foo&bar], [foo&bar][], [foo&bar], [foo&bar][]. 50 | 51 | [foo&bar]: http://example.com 52 | 53 | [foo&bar]: http://example.com 54 | -------------------------------------------------------------------------------- /test/fixtures/tree/fenced-code-trailing-characters-2.nooutput.nogfm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "inlineCode", 9 | "value": "\n", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 2, 18 | "column": 4, 19 | "offset": 7 20 | }, 21 | "indent": [ 22 | 1 23 | ] 24 | } 25 | }, 26 | { 27 | "type": "text", 28 | "value": " aaa\n```", 29 | "position": { 30 | "start": { 31 | "line": 2, 32 | "column": 4, 33 | "offset": 7 34 | }, 35 | "end": { 36 | "line": 3, 37 | "column": 4, 38 | "offset": 15 39 | }, 40 | "indent": [ 41 | 1 42 | ] 43 | } 44 | } 45 | ], 46 | "position": { 47 | "start": { 48 | "line": 1, 49 | "column": 1, 50 | "offset": 0 51 | }, 52 | "end": { 53 | "line": 3, 54 | "column": 4, 55 | "offset": 15 56 | }, 57 | "indent": [ 58 | 1, 59 | 1 60 | ] 61 | } 62 | } 63 | ], 64 | "position": { 65 | "start": { 66 | "line": 1, 67 | "column": 1, 68 | "offset": 0 69 | }, 70 | "end": { 71 | "line": 4, 72 | "column": 1, 73 | "offset": 16 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /packages/remark-stringify/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "remark-stringify", 3 | "version": "8.1.0", 4 | "description": "remark plugin to compile Markdown", 5 | "license": "MIT", 6 | "keywords": [ 7 | "unified", 8 | "remark", 9 | "remark-plugin", 10 | "plugin", 11 | "markdown", 12 | "mdast", 13 | "markdown", 14 | "abstract", 15 | "syntax", 16 | "tree", 17 | "ast", 18 | "stringify", 19 | "serialize", 20 | "compile" 21 | ], 22 | "homepage": "https://remark.js.org", 23 | "repository": "https://github.com/remarkjs/remark/tree/master/packages/remark-stringify", 24 | "bugs": "https://github.com/remarkjs/remark/issues", 25 | "funding": { 26 | "type": "opencollective", 27 | "url": "https://opencollective.com/unified" 28 | }, 29 | "author": "Titus Wormer (https://wooorm.com)", 30 | "contributors": [ 31 | "Titus Wormer (https://wooorm.com)", 32 | "Eugene Sharygin " 33 | ], 34 | "files": [ 35 | "index.js", 36 | "lib", 37 | "types/index.d.ts" 38 | ], 39 | "types": "types/index.d.ts", 40 | "dependencies": { 41 | "ccount": "^1.0.0", 42 | "is-alphanumeric": "^1.0.0", 43 | "is-decimal": "^1.0.0", 44 | "is-whitespace-character": "^1.0.0", 45 | "longest-streak": "^2.0.1", 46 | "markdown-escapes": "^1.0.0", 47 | "markdown-table": "^2.0.0", 48 | "mdast-util-compact": "^2.0.0", 49 | "parse-entities": "^2.0.0", 50 | "repeat-string": "^1.5.4", 51 | "state-toggle": "^1.0.0", 52 | "stringify-entities": "^3.0.0", 53 | "unherit": "^1.0.4", 54 | "xtend": "^4.0.1" 55 | }, 56 | "scripts": { 57 | "test": "tape test.js" 58 | }, 59 | "xo": false 60 | } 61 | -------------------------------------------------------------------------------- /test/fixtures/input/entities.output.entities=numbers.text: -------------------------------------------------------------------------------- 1 | # Entities 2 | 3 | Plain text: 4 | 5 | AT&T with entity, AT&T with numeric entity, AT&T without entity. 6 | 7 | Fenced code language flags: 8 | 9 | ```AT&T 10 | Something in the AT&T language 11 | ``` 12 | 13 | ```AT&T 14 | Something in the AT&T language 15 | ``` 16 | 17 | Automatic links: 18 | 19 | , , and . 20 | 21 | Link `href`: 22 | 23 | [With entity](http://at&t.com), [numeric entity](http://at&t.com), [without entity](http://at&t.com). 24 | 25 | Link `title`: 26 | 27 | [With entity](http://att.com "AT&T"), [numeric entity](http://att.com "AT&T"), [without entity](http://example.com "AT&T"). 28 | 29 | Image `src`: 30 | 31 | ![With entity](http://at&t.com/fav.ico), ![numeric entity](http://at&t.com/fav.ico), ![without entity](http://at&t.com/fav.ico). 32 | 33 | Image `alt`: 34 | 35 | ![AT&T with entity](http://att.com/fav.ico), ![AT&T with numeric entity](http://att.com/fav.ico), ![AT&T without entity](http://att.com/fav.ico). 36 | 37 | Image `title`: 38 | 39 | ![With entity](http://att.com/fav.ico "AT&T"), ![numeric entity](http://att.com/fav.ico "AT&T"), ![without entity](http://att.com/fav.ico "AT&T"). 40 | 41 | Image Reference `alt`: 42 | 43 | ![AT&T with entity][favicon], ![AT&T with numeric entity][favicon], ![AT&T without entity][favicon]. 44 | 45 | [favicon]: http://att.com/fav.ico "ATT favicon" 46 | 47 | Shortcut and collapsed references: 48 | 49 | [foo&bar], [foo&bar][], [foo&bar], [foo&bar][]. 50 | 51 | [foo&bar]: http://example.com 52 | 53 | [foo&bar]: http://example.com 54 | -------------------------------------------------------------------------------- /test/fixtures/tree/blockquote-indented.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "blockquote", 6 | "children": [ 7 | { 8 | "type": "paragraph", 9 | "children": [ 10 | { 11 | "type": "text", 12 | "value": "bar\nbaz", 13 | "position": { 14 | "start": { 15 | "line": 1, 16 | "column": 6, 17 | "offset": 5 18 | }, 19 | "end": { 20 | "line": 2, 21 | "column": 7, 22 | "offset": 15 23 | }, 24 | "indent": [ 25 | 4 26 | ] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 6, 34 | "offset": 5 35 | }, 36 | "end": { 37 | "line": 2, 38 | "column": 7, 39 | "offset": 15 40 | }, 41 | "indent": [ 42 | 4 43 | ] 44 | } 45 | } 46 | ], 47 | "position": { 48 | "start": { 49 | "line": 1, 50 | "column": 1, 51 | "offset": 0 52 | }, 53 | "end": { 54 | "line": 2, 55 | "column": 7, 56 | "offset": 15 57 | }, 58 | "indent": [ 59 | 1 60 | ] 61 | } 62 | } 63 | ], 64 | "position": { 65 | "start": { 66 | "line": 1, 67 | "column": 1, 68 | "offset": 0 69 | }, 70 | "end": { 71 | "line": 3, 72 | "column": 1, 73 | "offset": 16 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /test/fixtures/tree/lazy-blockquotes.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "blockquote", 6 | "children": [ 7 | { 8 | "type": "paragraph", 9 | "children": [ 10 | { 11 | "type": "text", 12 | "value": "hi there\nbud", 13 | "position": { 14 | "start": { 15 | "line": 1, 16 | "column": 3, 17 | "offset": 2 18 | }, 19 | "end": { 20 | "line": 2, 21 | "column": 4, 22 | "offset": 14 23 | }, 24 | "indent": [ 25 | 1 26 | ] 27 | } 28 | } 29 | ], 30 | "position": { 31 | "start": { 32 | "line": 1, 33 | "column": 3, 34 | "offset": 2 35 | }, 36 | "end": { 37 | "line": 2, 38 | "column": 4, 39 | "offset": 14 40 | }, 41 | "indent": [ 42 | 1 43 | ] 44 | } 45 | } 46 | ], 47 | "position": { 48 | "start": { 49 | "line": 1, 50 | "column": 1, 51 | "offset": 0 52 | }, 53 | "end": { 54 | "line": 2, 55 | "column": 4, 56 | "offset": 14 57 | }, 58 | "indent": [ 59 | 1 60 | ] 61 | } 62 | } 63 | ], 64 | "position": { 65 | "start": { 66 | "line": 1, 67 | "column": 1, 68 | "offset": 0 69 | }, 70 | "end": { 71 | "line": 3, 72 | "column": 1, 73 | "offset": 15 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /test/fixtures/tree/fenced-code-trailing-characters.nooutput.nogfm.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "root", 3 | "children": [ 4 | { 5 | "type": "paragraph", 6 | "children": [ 7 | { 8 | "type": "inlineCode", 9 | "value": "js\nfoo();\n", 10 | "position": { 11 | "start": { 12 | "line": 1, 13 | "column": 1, 14 | "offset": 0 15 | }, 16 | "end": { 17 | "line": 3, 18 | "column": 4, 19 | "offset": 16 20 | }, 21 | "indent": [ 22 | 1, 23 | 1 24 | ] 25 | } 26 | }, 27 | { 28 | "type": "text", 29 | "value": "bash\n```", 30 | "position": { 31 | "start": { 32 | "line": 3, 33 | "column": 4, 34 | "offset": 16 35 | }, 36 | "end": { 37 | "line": 4, 38 | "column": 4, 39 | "offset": 24 40 | }, 41 | "indent": [ 42 | 1 43 | ] 44 | } 45 | } 46 | ], 47 | "position": { 48 | "start": { 49 | "line": 1, 50 | "column": 1, 51 | "offset": 0 52 | }, 53 | "end": { 54 | "line": 4, 55 | "column": 4, 56 | "offset": 24 57 | }, 58 | "indent": [ 59 | 1, 60 | 1, 61 | 1 62 | ] 63 | } 64 | } 65 | ], 66 | "position": { 67 | "start": { 68 | "line": 1, 69 | "column": 1, 70 | "offset": 0 71 | }, 72 | "end": { 73 | "line": 5, 74 | "column": 1, 75 | "offset": 25 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /test/fixtures/input/stringify-escape.output.commonmark.text: -------------------------------------------------------------------------------- 1 | Characters that should be escaped in general: 2 | 3 | \\ \` \* \[ 4 | 5 | Characters that shouldn't: 6 | 7 | {}]()#+-.!>"$%',/:;=?@^~ 8 | 9 | Underscores are \_escaped\_ unless they appear in_the_middle_of_a_word. 10 | 11 | Ampersands are escaped only when they would otherwise start an entity: 12 | 13 | - \©cat \& \& 14 | - But: ©cat; `≬` &foo; & AT&T &c 15 | 16 | Open parenthesis should be escaped after a shortcut reference: 17 | 18 | [ref]\(text) 19 | 20 | And after a shortcut reference and a space (for GitHub): 21 | 22 | [ref] \(text) 23 | 24 | Hyphen should be escaped at the beginning of a line: 25 | 26 | \- not a list item 27 | \- not a list item 28 | \+ not a list item 29 | 30 | Same for angle brackets: 31 | 32 | \> not a block quote 33 | 34 | And hash signs: 35 | 36 | \# not a heading 37 | \## not a subheading 38 | 39 | Text under a shortcut reference should be preserved verbatim: 40 | 41 | - [two*three] 42 | - [two\*three] 43 | - [a\a] 44 | - [a\\a] 45 | - [a\\\a] 46 | - [a_a\_a] 47 | 48 | **GFM:** 49 | 50 | Colon should be escaped in URLs: 51 | 52 | - http\://user:password@host:port/path?key=value#fragment 53 | - https\://user:password@host:port/path?key=value#fragment 54 | 55 | Double tildes should be \~~escaped\~~. 56 | And here: foo\~~. 57 | 58 | Pipes should not be escaped here: | 59 | 60 | | here | they | 61 | | ------ | -------- | 62 | | should | tho\|ugh | 63 | 64 | And here: 65 | 66 | | here | they | 67 | \| ---- \| ----- \| 68 | | should | though | 69 | 70 | And here: 71 | 72 | here | they 73 | \---- \| ------ 74 | should | though 75 | 76 | **Commonmark:** 77 | 78 | Open angle bracket should be escaped: 79 | 80 | - \
\
81 | - \ 82 | -------------------------------------------------------------------------------- /test/fixtures/input/stringify-escape.output.nogfm.commonmark.text: -------------------------------------------------------------------------------- 1 | Characters that should be escaped in general: 2 | 3 | \\ \` \* \[ 4 | 5 | Characters that shouldn't: 6 | 7 | {}]()#+-.!>"$%',/:;=?@^~ 8 | 9 | Underscores are \_escaped\_ unless they appear in_the_middle_of_a_word. 10 | 11 | Ampersands are escaped only when they would otherwise start an entity: 12 | 13 | - \©cat \& \& 14 | - But: ©cat; `≬` &foo; & AT&T &c 15 | 16 | Open parenthesis should be escaped after a shortcut reference: 17 | 18 | [ref]\(text) 19 | 20 | And after a shortcut reference and a space (for GitHub): 21 | 22 | [ref] \(text) 23 | 24 | Hyphen should be escaped at the beginning of a line: 25 | 26 | \- not a list item 27 | \- not a list item 28 | \+ not a list item 29 | 30 | Same for angle brackets: 31 | 32 | \> not a block quote 33 | 34 | And hash signs: 35 | 36 | \# not a heading 37 | \## not a subheading 38 | 39 | Text under a shortcut reference should be preserved verbatim: 40 | 41 | - [two*three] 42 | - [two\*three] 43 | - [a\a] 44 | - [a\\a] 45 | - [a\\\a] 46 | - [a_a\_a] 47 | 48 | **GFM:** 49 | 50 | Colon should not be escaped in URLs: 51 | 52 | - http://user:password@host:port/path?key=value#fragment 53 | - https://user:password@host:port/path?key=value#fragment 54 | 55 | Double tildes should not be ~~escaped~~. 56 | Nor here: foo~~. 57 | 58 | Pipes should not be escaped here: | 59 | 60 | | here | they | 61 | | ------ | -------- | 62 | | should | nei|ther | 63 | 64 | Nor here: 65 | 66 | | here | they | 67 | | ------ | ------ | 68 | | should | though | 69 | 70 | Nor here: 71 | 72 | here | they 73 | \----- | ------ 74 | should | though 75 | 76 | **Commonmark:** 77 | 78 | Open angle bracket should be escaped: 79 | 80 | - \
\
81 | - \ 82 | --------------------------------------------------------------------------------