From 42c1ff3fcfa3f9aa2ef1e00763ee471da8d4479b Mon Sep 17 00:00:00 2001 From: Ara Adkins Date: Thu, 8 Oct 2020 14:51:01 +0100 Subject: [PATCH] Add support for [[wiki-style]] links in markdown (#9275) * Add support for [[wiki-style]] links in markdown 1. Support for [[wiki-style]] links ensures that they do not get broken by the prettier formatting by being wrapped over multiple lines. 2. The contents of the link (between the `[[]]` brackets) are treated as raw text. This is because the various tools that rely on the `[[]]` syntax do not agree on what is allowable between them. * Add a changelog document * Update pr-9275.md * Add additional tests as requested * Add a fix for AST tests * Fix issues with prose-wrap: "preserve" * Lint * Add a clean action for wikiLinks Co-authored-by: fisker Cheung --- changelog_unreleased/markdown/pr-9275.md | 21 + src/language-markdown/parser-markdown.js | 27 + src/language-markdown/printer-markdown.js | 16 +- src/language-markdown/utils.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 776 ++++++++++++++++++ .../markdown/wiki-link/additional-spacing.md | 1 + tests/markdown/wiki-link/end-of-line.md | 2 + .../exceeds-line-length-in-prose-broken.md | 2 + .../wiki-link/exceeds-line-length-in-prose.md | 1 + .../markdown/wiki-link/exceeds-line-length.md | 1 + .../wiki-link/extra-brackets-leading.md | 2 + .../wiki-link/extra-brackets-trailing.md | 2 + tests/markdown/wiki-link/extra-brackets.md | 2 + tests/markdown/wiki-link/jsfmt.spec.js | 4 + tests/markdown/wiki-link/multi-line.md | 2 + tests/markdown/wiki-link/nested-link.md | 1 + tests/markdown/wiki-link/simple.md | 1 + tests/markdown/wiki-link/with-whitespace.md | 1 + 18 files changed, 862 insertions(+), 1 deletion(-) create mode 100644 changelog_unreleased/markdown/pr-9275.md create mode 100644 tests/markdown/wiki-link/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/markdown/wiki-link/additional-spacing.md create mode 100644 tests/markdown/wiki-link/end-of-line.md create mode 100644 tests/markdown/wiki-link/exceeds-line-length-in-prose-broken.md create mode 100644 tests/markdown/wiki-link/exceeds-line-length-in-prose.md create mode 100644 tests/markdown/wiki-link/exceeds-line-length.md create mode 100644 tests/markdown/wiki-link/extra-brackets-leading.md create mode 100644 tests/markdown/wiki-link/extra-brackets-trailing.md create mode 100644 tests/markdown/wiki-link/extra-brackets.md create mode 100644 tests/markdown/wiki-link/jsfmt.spec.js create mode 100644 tests/markdown/wiki-link/multi-line.md create mode 100644 tests/markdown/wiki-link/nested-link.md create mode 100644 tests/markdown/wiki-link/simple.md create mode 100644 tests/markdown/wiki-link/with-whitespace.md diff --git a/changelog_unreleased/markdown/pr-9275.md b/changelog_unreleased/markdown/pr-9275.md new file mode 100644 index 000000000..bd1105186 --- /dev/null +++ b/changelog_unreleased/markdown/pr-9275.md @@ -0,0 +1,21 @@ +#### Add support for [[wiki-style]] links in markdown (#9275 by @iamrecursion) + +1. Support for `[[wiki-style]]` links ensures that they do not get broken by + the prettier formatting by being wrapped over multiple lines. +2. The contents of the link (between the `[[]]` brackets) are treated as raw + text. This is because the various tools that rely on the `[[]]` syntax do not + agree on what is allowable between them. + + +```markdown + +If I have a prose that forces a wiki link to end up crossing the [[line width limit]] like this. It's wrapped into an invalid state. + + +If I have a prose that forces a wiki link to end up crossing the [[line width +limit]] like this. It's wrapped into an invalid state. + + +If I have a prose that forces a wiki link to end up crossing the +[[line width limit]] like this. It's wrapped into an invalid state. +``` diff --git a/src/language-markdown/parser-markdown.js b/src/language-markdown/parser-markdown.js index b48c8bdf3..bb961f103 100644 --- a/src/language-markdown/parser-markdown.js +++ b/src/language-markdown/parser-markdown.js @@ -36,6 +36,7 @@ function createParse({ isMDX }) { .use(isMDX ? mdx.esSyntax : identity) .use(liquid) .use(isMDX ? htmlToJsx : identity) + .use(wikiLink) .use(looseItems); return processor.runSync(processor.parse(text)); }; @@ -96,6 +97,32 @@ function liquid() { }; } +function wikiLink() { + const entityType = "wikiLink"; + const wikiLinkRegex = /^\[\[(?.+?)]]/s; + const proto = this.Parser.prototype; + const methods = proto.inlineMethods; + methods.splice(methods.indexOf("link"), 0, entityType); + proto.inlineTokenizers.wikiLink = tokenizer; + + function tokenizer(eat, value) { + const match = wikiLinkRegex.exec(value); + + if (match) { + const linkContents = match.groups.linkContents.trim(); + + return eat(match[0])({ + type: entityType, + value: linkContents, + }); + } + } + + tokenizer.locator = function (value, fromIndex) { + return value.indexOf("[", fromIndex); + }; +} + function looseItems() { const proto = this.Parser.prototype; const originalList = proto.blockTokenizers.list; diff --git a/src/language-markdown/printer-markdown.js b/src/language-markdown/printer-markdown.js index 1ced1c0a9..c370b67a3 100644 --- a/src/language-markdown/printer-markdown.js +++ b/src/language-markdown/printer-markdown.js @@ -40,7 +40,7 @@ const { } = require("./utils"); const TRAILING_HARDLINE_NODES = new Set(["importExport"]); -const SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"]; +const SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link", "wikiLink"]; const SIBLING_NODE_TYPES = new Set([ "listItem", "definition", @@ -179,6 +179,16 @@ function genericPrint(path, options, print) { const gap = backtickCount && !/^\s/.test(node.value) ? " " : ""; return concat([style, gap, node.value, gap, style]); } + case "wikiLink": { + let contents = ""; + if (options.proseWrap === "preserve") { + contents = node.value; + } else { + contents = node.value.replace(/[\t\n]+/g, " "); + } + + return concat(["[[", contents, "]]"]); + } case "link": switch (options.originalText[node.position.start.offset]) { case "<": { @@ -962,6 +972,10 @@ function clean(ast, newObj, parent) { newObj.value = ast.value.replace(/[\t\n ]+/g, " "); } + if (ast.type === "wikiLink") { + newObj.value = ast.value.trim().replace(/[\t\n]+/g, " "); + } + if (ast.type === "definition" || ast.type === "linkReference") { newObj.label = ast.label .trim() diff --git a/src/language-markdown/utils.js b/src/language-markdown/utils.js index eee9aa8a2..7782614ae 100644 --- a/src/language-markdown/utils.js +++ b/src/language-markdown/utils.js @@ -13,6 +13,7 @@ const INLINE_NODE_TYPES = [ "emphasis", "strong", "delete", + "wikiLink", "link", "linkReference", "image", diff --git a/tests/markdown/wiki-link/__snapshots__/jsfmt.spec.js.snap b/tests/markdown/wiki-link/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..e5fcc9142 --- /dev/null +++ b/tests/markdown/wiki-link/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,776 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`additional-spacing.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +[[Additional spacing within the link should be preserved]] + +=====================================output===================================== +[[Additional spacing within the link should be preserved]] + +================================================================================ +`; + +exports[`additional-spacing.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +[[Additional spacing within the link should be preserved]] + +=====================================output===================================== +[[Additional spacing within the link should be preserved]] + +================================================================================ +`; + +exports[`additional-spacing.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +[[Additional spacing within the link should be preserved]] + +=====================================output===================================== +[[Additional spacing within the link should be preserved]] + +================================================================================ +`; + +exports[`additional-spacing.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +[[Additional spacing within the link should be preserved]] + +=====================================output===================================== +[[Additional spacing within the link should be preserved]] + +================================================================================ +`; + +exports[`end-of-line.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +If I have some markdown text, it should be wrapped properly at the character limit for markdown. +However, if I have a link that overflows the end of line it should be [[wrapped as a single entity]] like this. + +=====================================output===================================== +If I have some markdown text, it should be wrapped properly at the character +limit for markdown. However, if I have a link that overflows the end of line it +should be [[wrapped as a single entity]] like this. + +================================================================================ +`; + +exports[`end-of-line.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +If I have some markdown text, it should be wrapped properly at the character limit for markdown. +However, if I have a link that overflows the end of line it should be [[wrapped as a single entity]] like this. + +=====================================output===================================== +If I have some markdown text, it should be wrapped properly at the character +limit for markdown. However, if I have a link that overflows the end of line it +should be [[wrapped as a single entity]] like this. + +================================================================================ +`; + +exports[`end-of-line.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +If I have some markdown text, it should be wrapped properly at the character limit for markdown. +However, if I have a link that overflows the end of line it should be [[wrapped as a single entity]] like this. + +=====================================output===================================== +If I have some markdown text, it should be wrapped properly at the character limit for markdown. However, if I have a link that overflows the end of line it should be [[wrapped as a single entity]] like this. + +================================================================================ +`; + +exports[`end-of-line.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +If I have some markdown text, it should be wrapped properly at the character limit for markdown. +However, if I have a link that overflows the end of line it should be [[wrapped as a single entity]] like this. + +=====================================output===================================== +If I have some markdown text, it should be wrapped properly at the character limit for markdown. +However, if I have a link that overflows the end of line it should be [[wrapped as a single entity]] like this. + +================================================================================ +`; + +exports[`exceeds-line-length.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. + +=====================================output===================================== +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. + +================================================================================ +`; + +exports[`exceeds-line-length.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. + +=====================================output===================================== +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. + +================================================================================ +`; + +exports[`exceeds-line-length.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. + +=====================================output===================================== +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. + +================================================================================ +`; + +exports[`exceeds-line-length.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. + +=====================================output===================================== +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. + +================================================================================ +`; + +exports[`exceeds-line-length-in-prose.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +=====================================output===================================== +I have some markdown prose here, with a horrible run-on sentence that +[[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +================================================================================ +`; + +exports[`exceeds-line-length-in-prose.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +=====================================output===================================== +I have some markdown prose here, with a horrible run-on sentence that +[[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +================================================================================ +`; + +exports[`exceeds-line-length-in-prose.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +=====================================output===================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +================================================================================ +`; + +exports[`exceeds-line-length-in-prose.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +=====================================output===================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +================================================================================ +`; + +exports[`exceeds-line-length-in-prose-broken.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I +continue it into an obscenely long wiki-style link thingy]]. + +=====================================output===================================== +I have some markdown prose here, with a horrible run-on sentence that +[[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +================================================================================ +`; + +exports[`exceeds-line-length-in-prose-broken.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I +continue it into an obscenely long wiki-style link thingy]]. + +=====================================output===================================== +I have some markdown prose here, with a horrible run-on sentence that +[[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +================================================================================ +`; + +exports[`exceeds-line-length-in-prose-broken.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I +continue it into an obscenely long wiki-style link thingy]]. + +=====================================output===================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. + +================================================================================ +`; + +exports[`exceeds-line-length-in-prose-broken.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I +continue it into an obscenely long wiki-style link thingy]]. + +=====================================output===================================== +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I +continue it into an obscenely long wiki-style link thingy]]. + +================================================================================ +`; + +exports[`extra-brackets.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over the +[[[end like this]]]. + +================================================================================ +`; + +exports[`extra-brackets.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over the +[[[end like this]]]. + +================================================================================ +`; + +exports[`extra-brackets.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. + +================================================================================ +`; + +exports[`extra-brackets.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. + +================================================================================ +`; + +exports[`extra-brackets-leading.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over +[[[the end like this]]. + +================================================================================ +`; + +exports[`extra-brackets-leading.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over +[[[the end like this]]. + +================================================================================ +`; + +exports[`extra-brackets-leading.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. + +================================================================================ +`; + +exports[`extra-brackets-leading.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. + +================================================================================ +`; + +exports[`extra-brackets-trailing.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over +[[the end like this]]]. + +================================================================================ +`; + +exports[`extra-brackets-trailing.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over +[[the end like this]]]. + +================================================================================ +`; + +exports[`extra-brackets-trailing.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. + +================================================================================ +`; + +exports[`extra-brackets-trailing.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. + + +=====================================output===================================== +A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. + +================================================================================ +`; + +exports[`multi-line.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +[[a +b]] + +=====================================output===================================== +[[a b]] + +================================================================================ +`; + +exports[`multi-line.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +[[a +b]] + +=====================================output===================================== +[[a b]] + +================================================================================ +`; + +exports[`multi-line.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +[[a +b]] + +=====================================output===================================== +[[a b]] + +================================================================================ +`; + +exports[`multi-line.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +[[a +b]] + +=====================================output===================================== +[[a +b]] + +================================================================================ +`; + +exports[`nested-link.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +Here's some text to ensure that the link and wiki link break the line [[a[b](http://www.example.com/)]] + +=====================================output===================================== +Here's some text to ensure that the link and wiki link break the line +[[a[b](http://www.example.com/)]] + +================================================================================ +`; + +exports[`nested-link.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +Here's some text to ensure that the link and wiki link break the line [[a[b](http://www.example.com/)]] + +=====================================output===================================== +Here's some text to ensure that the link and wiki link break the line +[[a[b](http://www.example.com/)]] + +================================================================================ +`; + +exports[`nested-link.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +Here's some text to ensure that the link and wiki link break the line [[a[b](http://www.example.com/)]] + +=====================================output===================================== +Here's some text to ensure that the link and wiki link break the line [[a[b](http://www.example.com/)]] + +================================================================================ +`; + +exports[`nested-link.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +Here's some text to ensure that the link and wiki link break the line [[a[b](http://www.example.com/)]] + +=====================================output===================================== +Here's some text to ensure that the link and wiki link break the line [[a[b](http://www.example.com/)]] + +================================================================================ +`; + +exports[`simple.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +[[A simple wiki link on a single line]] + +=====================================output===================================== +[[A simple wiki link on a single line]] + +================================================================================ +`; + +exports[`simple.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +[[A simple wiki link on a single line]] + +=====================================output===================================== +[[A simple wiki link on a single line]] + +================================================================================ +`; + +exports[`simple.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +[[A simple wiki link on a single line]] + +=====================================output===================================== +[[A simple wiki link on a single line]] + +================================================================================ +`; + +exports[`simple.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +[[A simple wiki link on a single line]] + +=====================================output===================================== +[[A simple wiki link on a single line]] + +================================================================================ +`; + +exports[`with-whitespace.md - {"proseWrap":"always","singleQuote":true} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" +singleQuote: true + | printWidth +=====================================input====================================== +[[ Here is a link with leading and trailing whitespace. ]] + +=====================================output===================================== +[[Here is a link with leading and trailing whitespace.]] + +================================================================================ +`; + +exports[`with-whitespace.md - {"proseWrap":"always"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "always" + | printWidth +=====================================input====================================== +[[ Here is a link with leading and trailing whitespace. ]] + +=====================================output===================================== +[[Here is a link with leading and trailing whitespace.]] + +================================================================================ +`; + +exports[`with-whitespace.md - {"proseWrap":"never"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "never" + | printWidth +=====================================input====================================== +[[ Here is a link with leading and trailing whitespace. ]] + +=====================================output===================================== +[[Here is a link with leading and trailing whitespace.]] + +================================================================================ +`; + +exports[`with-whitespace.md - {"proseWrap":"preserve"} format 1`] = ` +====================================options===================================== +parsers: ["markdown"] +printWidth: 80 +proseWrap: "preserve" + | printWidth +=====================================input====================================== +[[ Here is a link with leading and trailing whitespace. ]] + +=====================================output===================================== +[[Here is a link with leading and trailing whitespace.]] + +================================================================================ +`; diff --git a/tests/markdown/wiki-link/additional-spacing.md b/tests/markdown/wiki-link/additional-spacing.md new file mode 100644 index 000000000..ad7c0b906 --- /dev/null +++ b/tests/markdown/wiki-link/additional-spacing.md @@ -0,0 +1 @@ +[[Additional spacing within the link should be preserved]] diff --git a/tests/markdown/wiki-link/end-of-line.md b/tests/markdown/wiki-link/end-of-line.md new file mode 100644 index 000000000..b3ec177a3 --- /dev/null +++ b/tests/markdown/wiki-link/end-of-line.md @@ -0,0 +1,2 @@ +If I have some markdown text, it should be wrapped properly at the character limit for markdown. +However, if I have a link that overflows the end of line it should be [[wrapped as a single entity]] like this. diff --git a/tests/markdown/wiki-link/exceeds-line-length-in-prose-broken.md b/tests/markdown/wiki-link/exceeds-line-length-in-prose-broken.md new file mode 100644 index 000000000..070b8bda4 --- /dev/null +++ b/tests/markdown/wiki-link/exceeds-line-length-in-prose-broken.md @@ -0,0 +1,2 @@ +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I +continue it into an obscenely long wiki-style link thingy]]. diff --git a/tests/markdown/wiki-link/exceeds-line-length-in-prose.md b/tests/markdown/wiki-link/exceeds-line-length-in-prose.md new file mode 100644 index 000000000..c74bc9c9d --- /dev/null +++ b/tests/markdown/wiki-link/exceeds-line-length-in-prose.md @@ -0,0 +1 @@ +I have some markdown prose here, with a horrible run-on sentence that [[makes little sense at all as I continue it into an obscenely long wiki-style link thingy]]. diff --git a/tests/markdown/wiki-link/exceeds-line-length.md b/tests/markdown/wiki-link/exceeds-line-length.md new file mode 100644 index 000000000..357750691 --- /dev/null +++ b/tests/markdown/wiki-link/exceeds-line-length.md @@ -0,0 +1 @@ +[[Here is an incredibly long wiki-style link that overflows the standard wrap width for markdown]]. diff --git a/tests/markdown/wiki-link/extra-brackets-leading.md b/tests/markdown/wiki-link/extra-brackets-leading.md new file mode 100644 index 000000000..24e58c13e --- /dev/null +++ b/tests/markdown/wiki-link/extra-brackets-leading.md @@ -0,0 +1,2 @@ +A very long line of markdown with additional brackets as it wraps over [[[the end like this]]. + diff --git a/tests/markdown/wiki-link/extra-brackets-trailing.md b/tests/markdown/wiki-link/extra-brackets-trailing.md new file mode 100644 index 000000000..b9720bbb0 --- /dev/null +++ b/tests/markdown/wiki-link/extra-brackets-trailing.md @@ -0,0 +1,2 @@ +A very long line of markdown with additional brackets as it wraps over [[the end like this]]]. + diff --git a/tests/markdown/wiki-link/extra-brackets.md b/tests/markdown/wiki-link/extra-brackets.md new file mode 100644 index 000000000..7b5595f1a --- /dev/null +++ b/tests/markdown/wiki-link/extra-brackets.md @@ -0,0 +1,2 @@ +A very long line of markdown with additional brackets as it wraps over the [[[end like this]]]. + diff --git a/tests/markdown/wiki-link/jsfmt.spec.js b/tests/markdown/wiki-link/jsfmt.spec.js new file mode 100644 index 000000000..6bf2457cb --- /dev/null +++ b/tests/markdown/wiki-link/jsfmt.spec.js @@ -0,0 +1,4 @@ +run_spec(__dirname, ["markdown"], { proseWrap: "always" }); +run_spec(__dirname, ["markdown"], { proseWrap: "always", singleQuote: true }); +run_spec(__dirname, ["markdown"], { proseWrap: "never" }); +run_spec(__dirname, ["markdown"], { proseWrap: "preserve" }); diff --git a/tests/markdown/wiki-link/multi-line.md b/tests/markdown/wiki-link/multi-line.md new file mode 100644 index 000000000..803eeac94 --- /dev/null +++ b/tests/markdown/wiki-link/multi-line.md @@ -0,0 +1,2 @@ +[[a +b]] diff --git a/tests/markdown/wiki-link/nested-link.md b/tests/markdown/wiki-link/nested-link.md new file mode 100644 index 000000000..be908a4e9 --- /dev/null +++ b/tests/markdown/wiki-link/nested-link.md @@ -0,0 +1 @@ +Here's some text to ensure that the link and wiki link break the line [[a[b](http://www.example.com/)]] diff --git a/tests/markdown/wiki-link/simple.md b/tests/markdown/wiki-link/simple.md new file mode 100644 index 000000000..2755eca02 --- /dev/null +++ b/tests/markdown/wiki-link/simple.md @@ -0,0 +1 @@ +[[A simple wiki link on a single line]] diff --git a/tests/markdown/wiki-link/with-whitespace.md b/tests/markdown/wiki-link/with-whitespace.md new file mode 100644 index 000000000..6f37e96ea --- /dev/null +++ b/tests/markdown/wiki-link/with-whitespace.md @@ -0,0 +1 @@ +[[ Here is a link with leading and trailing whitespace. ]]