diff --git a/README.md b/README.md index ca05e43..e353125 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,10 @@ support for that version for marky-markdown. For more information on Node.js LTS and support, click [here](https://github.com/nodejs/LTS). +- marky-markdown >= `11.x` supports `4`, `6`, `8` +- marky-markdown `10.x` supports `4`, `6` +- marky-markdown `9.x` supports `0.12`, `4`, `6` - marky-markdown < `9.0.0` supports `0.10`, `0.12`, `iojs`, `4`, `5` -- marky-markdown >= `9.0.0` supports `0.12`, `4`, `6` ## Installation @@ -188,8 +190,6 @@ marky( - [lodash](https://github.com/lodash/lodash): A utility library delivering consistency, customization, performance, & extras. - [markdown-it](https://github.com/markdown-it/markdown-it): Markdown-it - modern pluggable markdown parser. - [markdown-it-emoji](https://github.com/markdown-it/markdown-it-emoji): Markdown-it-emoji extension for Markdown-it that parses markdown emoji syntax to unicode. -- [markdown-it-expand-tabs](https://github.com/revin/markdown-it-expand-tabs): Replace leading tabs with spaces in fenced code blocks -- [markdown-it-lazy-headers](https://github.com/Galadirith/markdown-it-lazy-headers): Lazy ATX headers plugin for markdown-it - [markdown-it-task-lists](https://github.com/revin/markdown-it-task-lists): Render GitHub-style [task lists](https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments) - [property-ttl](https://github.com/soldair/property-ttl): Save memory by nulling out a property after ttl if it has not been accessed - [sanitize-html](https://github.com/punkave/sanitize-html): Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis diff --git a/lib/gfm/image.js b/lib/gfm/image.js deleted file mode 100644 index ac86b39..0000000 --- a/lib/gfm/image.js +++ /dev/null @@ -1,179 +0,0 @@ -// CommonMark specifies that images have no whitespace between the alt text and -// src, e.g.: -// -// ![alt text](path/to/the/image) -// -// However, GitHub allows you to put whitespace between the `]` and `(` -// characters, like so: -// -// ![alt text] (path/to/the/image) -// -// To account for the difference, we need to override markdown-it's image rule. -// This file is a copy of the original markdown-it source, plus the necessary -// modifications, wrapped as a markdown-it plugin. - -// Process ![image]( "title") - -'use strict' - -module.exports = function (md) { - md.inline.ruler.at('image', image) -} - -function image (state, silent) { - var attrs - var code - var content - var label - var labelEnd - var labelStart - var pos - var ref - var res - var title - var token - var tokens - var start - var href = '' - var oldPos = state.pos - var max = state.posMax - var isSpace = state.md.utils.isSpace - var normalizeReference = state.md.utils.normalizeReference - - if (state.src.charCodeAt(state.pos) !== 0x21/* ! */) { return false } - if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) { return false } - - labelStart = state.pos + 2 - labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false) - - // parser failed to find ']', so it's not a valid link - if (labelEnd < 0) { return false } - - pos = labelEnd + 1 - - // BEGIN CUSTOM MODIFICATION - // look ahead to see if the next non-whitespace character is '(', and if - // it is, skip the whitespace - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos) - if (!isSpace(code) && code !== 0x0A) { break } - } - if (pos < max && state.src.charCodeAt(pos) !== 0x28) { pos = labelEnd + 1 } - // END CUSTOM MODIFICATION - - if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) { - // - // Inline link - // - - // [link]( "title" ) - // ^^ skipping these spaces - pos++ - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos) - if (!isSpace(code) && code !== 0x0A) { break } - } - if (pos >= max) { return false } - - // [link]( "title" ) - // ^^^^^^ parsing link destination - start = pos - res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax) - if (res.ok) { - href = state.md.normalizeLink(res.str) - if (state.md.validateLink(href)) { - pos = res.pos - } else { - href = '' - } - } - - // [link]( "title" ) - // ^^ skipping these spaces - start = pos - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos) - if (!isSpace(code) && code !== 0x0A) { break } - } - - // [link]( "title" ) - // ^^^^^^^ parsing link title - res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax) - if (pos < max && start !== pos && res.ok) { - title = res.str - pos = res.pos - - // [link]( "title" ) - // ^^ skipping these spaces - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos) - if (!isSpace(code) && code !== 0x0A) { break } - } - } else { - title = '' - } - - if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) { - state.pos = oldPos - return false - } - pos++ - } else { - // - // Link reference - // - if (typeof state.env.references === 'undefined') { return false } - - if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { - start = pos + 1 - pos = state.md.helpers.parseLinkLabel(state, pos) - if (pos >= 0) { - label = state.src.slice(start, pos++) - } else { - pos = labelEnd + 1 - } - } else { - pos = labelEnd + 1 - } - - // covers label === '' and label === undefined - // (collapsed reference link and shortcut reference link respectively) - if (!label) { label = state.src.slice(labelStart, labelEnd) } - - ref = state.env.references[normalizeReference(label)] - if (!ref) { - state.pos = oldPos - return false - } - href = ref.href - title = ref.title - } - - // - // We found the end of the link, and know for a fact it's a valid link; - // so all that's left to do is to call tokenizer. - // - if (!silent) { - content = state.src.slice(labelStart, labelEnd) - - state.md.inline.parse( - content, - state.md, - state.env, - tokens = [] - ) - - token = state.push('image', 'img', 0) - token.attrs = attrs = [ [ 'src', href ], [ 'alt', '' ] ] - token.children = tokens - token.content = content - - if (title) { - attrs.push([ 'title', title ]) - } - } - - state.pos = pos - state.posMax = max - return true -} diff --git a/lib/gfm/indented-headings.js b/lib/gfm/indented-headings.js deleted file mode 100644 index 88bbdb6..0000000 --- a/lib/gfm/indented-headings.js +++ /dev/null @@ -1,35 +0,0 @@ -module.exports = function (md, options) { - // Unfortunately, there's no public API for getting access to the existing - // installed parsing rules; rather than import the 'heading' rule directly - // from markdown-it just so we can wrap it with our own processing, we have to - // use internal utility methods to pick it up first, then do the replacement - // via normal means. - // - // This plugin allows us to more closely mimic GitHub's heading parsing. Per - // CommonMark, ATX headings are allowed to have one to three spaces before the - // hash characters. GitHub doesn't allow any leading whitespace whatsoever. - // - // For example (the `·` characters represent spaces): - // - // ·### Renders as H3 in CommonMark - // ··## Renders as H2 in CommonMark - // ···# Renders as H1 in CommonMark - // - // ... whereas on GitHub, those become standard paragraphs. - - var ruler = md.block.ruler - var originalEntry = ruler.__rules__[ruler.__find__('heading')] - var originalRule = originalEntry.fn - - ruler.at('heading', noIndentedHeadings, {alt: originalEntry.alt}) - - function noIndentedHeadings (state, startLine, endLine, silent) { - // conveniently, state.tShift holds a count of the number of leading spaces - // on each line, so all we need to do is return false if it's non-zero - if (state.tShift[startLine] > 0) { - return false - } else { - return originalRule.apply(this, arguments) - } - } -} diff --git a/lib/gfm/link.js b/lib/gfm/link.js deleted file mode 100644 index b33fa3b..0000000 --- a/lib/gfm/link.js +++ /dev/null @@ -1,186 +0,0 @@ -// CommonMark specifies that links have no whitespace between the label and -// destination, e.g.: -// -// [link text](path/to/the/thing) -// -// However, GitHub allows you to put whitespace between the `]` and `(` -// characters, like so: -// -// [link text] (path/to/the/thing) -// -// This is against CommonMark because it's ambiguous. Consider a link reference -// followed by a parenthetical statement: -// -// [link text] (parenthetical statement) -// -// [link text]: path/to/the/thing -// -// CommonMark renders: link text -// GitHub renders: link text -// -// To account for the difference, we need to override markdown-it's link rule. -// This file is a copy of the original markdown-it source, plus the necessary -// modifications, wrapped as a markdown-it plugin. - -// Process [link]( "stuff") -'use strict' - -module.exports = function (md) { - md.inline.ruler.at('link', link) -} - -function link (state, silent) { - var attrs - var code - var label - var labelEnd - var labelStart - var pos - var res - var ref - var title - var token - var href = '' - var oldPos = state.pos - var max = state.posMax - var start = state.pos - var parseReference = true - var isSpace = state.md.utils.isSpace - var normalizeReference = state.md.utils.normalizeReference - - if (state.src.charCodeAt(state.pos) !== 0x5B/* [ */) { return false } - - labelStart = state.pos + 1 - labelEnd = state.md.helpers.parseLinkLabel(state, state.pos, true) - - // parser failed to find ']', so it's not a valid link - if (labelEnd < 0) { return false } - - pos = labelEnd + 1 - - // BEGIN CUSTOM MODIFICATION - // look ahead to see if the next non-whitespace character is '(', and if - // it is, skip the whitespace - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos) - if (!isSpace(code) && code !== 0x0A) { break } - } - if (pos < max && state.src.charCodeAt(pos) !== 0x28) { pos = labelEnd + 1 } - // END CUSTOM MODIFICATION - - if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) { - // - // Inline link - // - - // might have found a valid shortcut link, disable reference parsing - parseReference = false - - // [link]( "title" ) - // ^^ skipping these spaces - pos++ - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos) - if (!isSpace(code) && code !== 0x0A) { break } - } - if (pos >= max) { return false } - - // [link]( "title" ) - // ^^^^^^ parsing link destination - start = pos - res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax) - if (res.ok) { - href = state.md.normalizeLink(res.str) - if (state.md.validateLink(href)) { - pos = res.pos - } else { - href = '' - } - } - - // [link]( "title" ) - // ^^ skipping these spaces - start = pos - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos) - if (!isSpace(code) && code !== 0x0A) { break } - } - - // [link]( "title" ) - // ^^^^^^^ parsing link title - res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax) - if (pos < max && start !== pos && res.ok) { - title = res.str - pos = res.pos - - // [link]( "title" ) - // ^^ skipping these spaces - for (; pos < max; pos++) { - code = state.src.charCodeAt(pos) - if (!isSpace(code) && code !== 0x0A) { break } - } - } else { - title = '' - } - - if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) { - // parsing a valid shortcut link failed, fallback to reference - parseReference = true - } - pos++ - } - - if (parseReference) { - // - // Link reference - // - if (typeof state.env.references === 'undefined') { return false } - - if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { - start = pos + 1 - pos = state.md.helpers.parseLinkLabel(state, pos) - if (pos >= 0) { - label = state.src.slice(start, pos++) - } else { - pos = labelEnd + 1 - } - } else { - pos = labelEnd + 1 - } - - // covers label === '' and label === undefined - // (collapsed reference link and shortcut reference link respectively) - if (!label) { label = state.src.slice(labelStart, labelEnd) } - - ref = state.env.references[normalizeReference(label)] - if (!ref) { - state.pos = oldPos - return false - } - href = ref.href - title = ref.title - } - - // - // We found the end of the link, and know for a fact it's a valid link; - // so all that's left to do is to call tokenizer. - // - if (!silent) { - state.pos = labelStart - state.posMax = labelEnd - - token = state.push('link_open', 'a', 1) - token.attrs = attrs = [ [ 'href', href ] ] - if (title) { - attrs.push([ 'title', title ]) - } - - state.md.inline.tokenize(state) - - token = state.push('link_close', 'a', -1) - } - - state.pos = pos - state.posMax = max - return true -} diff --git a/lib/gfm/override-link-destination-parser.js b/lib/gfm/override-link-destination-parser.js deleted file mode 100644 index 31d8a33..0000000 --- a/lib/gfm/override-link-destination-parser.js +++ /dev/null @@ -1,98 +0,0 @@ -// Override the markdown-it helper rule to allow spaces in the src attributes of images and the href attributes of -// anchor elements: -// e.g., ![Gitter](https://badges.gitter.im/Join Chat.svg) -// -// This is a modified version of the stock markdown-it helper for parsing link destinations -'use strict' - -function parseLinkDestination (md, str, pos, max) { - var code - var level - var lines = 0 - var start = pos - var result = { - ok: false, - pos: 0, - lines: 0, - str: '' - } - var isSpace = md.utils.isSpace - var unescapeAll = md.utils.unescapeAll - - if (str.charCodeAt(pos) === 0x3C /* < */) { - pos++ - while (pos < max) { - code = str.charCodeAt(pos) - if (code === 0x0A /* \n */ || isSpace(code)) { return result } - if (code === 0x3E /* > */) { - result.pos = pos + 1 - result.str = unescapeAll(str.slice(start + 1, pos)) - result.ok = true - return result - } - if (code === 0x5C /* \ */ && pos + 1 < max) { - pos += 2 - continue - } - - pos++ - } - - // no closing '>' - return result - } - - // this should be ... } else { ... branch - - level = 0 - while (pos < max) { - code = str.charCodeAt(pos) - - if (code === 0x20) { // space - pos++ // 0x22 => double quote, 0x27 => single quote, 0x28 => '(', 0x29 => ')' - while (pos < max && code !== 0x22 && code !== 0x27 && code !== 0x28 && code !== 0x29) { - code = str.charCodeAt(pos++) - } - pos-- - if (pos === max) { // end of the line - break - } - if (code === 0x22 || code === 0x27 || code === 0x28) { // single/double quotes or opening paren for title attributes - pos-- - break - } - } - - // ascii control characters - if (code < 0x20 || code === 0x7F) { break } - - if (code === 0x5C /* \ */ && pos + 1 < max) { - pos += 2 - continue - } - - if (code === 0x28 /* ( */) { - level++ - if (level > 1) { break } - } - - if (code === 0x29 /* ) */) { - level-- - if (level < 0) { break } - } - - pos++ - } - - if (start === pos) { return result } - - result.str = unescapeAll(str.slice(start, pos)) - result.lines = lines - result.pos = pos - result.ok = true - return result -} - -module.exports = function (md) { - md.helpers.parseLinkDestination = parseLinkDestination.bind(this, md) -} diff --git a/lib/gfm/relaxed-link-reference.js b/lib/gfm/relaxed-link-reference.js deleted file mode 100644 index 7ee9df1..0000000 --- a/lib/gfm/relaxed-link-reference.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = function (md, options) { - // Unfortunately, there's no public API for getting access to the existing - // installed parsing rules; rather than import the 'reference' rule directly - // from markdown-it just so we can re-install it into the parser with the - // 'alt' chain set up correctly, here we're just using internal utility - // methods to modify it in place at runtime. - // - // The net result is that we allow what are known in the CommonMark spec as - // "link reference definitions" to interrupt paragraphs, i.e., we relax the - // requirement that there be a blank line between a paragraph and a reference - // definition. - // - // That means that this works: - // - // Some paragraph text here with a [linkref] - // [linkref]: /actual/link/destination/here - // - // ...whereas spec compliance requires a blank line between the two. - - var ruler = md.block.ruler - var idx = ruler.__find__('reference') - ruler.__rules__[idx].alt.push('paragraph') - ruler.__compile__() -} diff --git a/lib/render.js b/lib/render.js index cd1dc34..c7cf111 100644 --- a/lib/render.js +++ b/lib/render.js @@ -1,8 +1,6 @@ var pickBy = require('lodash.pickby') var MD = require('markdown-it') -var lazyHeaders = require('markdown-it-lazy-headers') var emoji = require('markdown-it-emoji') -var expandTabs = require('markdown-it-expand-tabs') var githubTaskList = require('markdown-it-task-lists') var cleanup = require('./cleanup') @@ -16,11 +14,6 @@ var youtube = require('./plugin/youtube') var cdnImages = require('./plugin/cdn') var packagize = require('./plugin/packagize') var htmlHeading = require('./plugin/html-heading') -var relaxedLinkRefs = require('./gfm/relaxed-link-reference') -var githubHeadings = require('./gfm/indented-headings') -var overrideLinkDestinationParser = require('./gfm/override-link-destination-parser') -var looseLinkParsing = require('./gfm/link') -var looseImageParsing = require('./gfm/image') if (typeof process.browser === 'undefined') { var Highlights = require('highlights') @@ -71,21 +64,14 @@ render.getParser = function (options) { } var parser = MD(mdOptions) - .use(lazyHeaders) .use(emoji, {shortcuts: {}}) - .use(expandTabs, {tabWidth: 4}) .use(githubTaskList) .use(headingLinks, options) - .use(githubHeadings) - .use(relaxedLinkRefs) .use(gravatar) .use(github, {package: options.package}) .use(youtube) .use(packagize, {package: options.package}) .use(htmlHeading) - .use(overrideLinkDestinationParser) - .use(looseLinkParsing) - .use(looseImageParsing) if (options.highlightSyntax) parser.use(codeWrap) if (options.serveImagesWithCDN) parser.use(cdnImages, {package: options.package}) diff --git a/package-lock.json b/package-lock.json index e28f7d1..9f90a29 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "marky-markdown", - "version": "10.1.4", + "version": "11.0.0", "lockfileVersion": 1, "dependencies": { "acorn": { @@ -2060,11 +2060,6 @@ "integrity": "sha1-gNZJLcFHCGS79YNTO2UfQqn1JBU=", "dev": true }, - "lodash.repeat": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/lodash.repeat/-/lodash.repeat-4.1.0.tgz", - "integrity": "sha1-/H3oEx2MisB+S0n3T/6CnR8r7EQ=" - }, "lodash.some": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.some/-/lodash.some-4.6.0.tgz", @@ -2123,16 +2118,6 @@ "resolved": "https://registry.npmjs.org/markdown-it-emoji/-/markdown-it-emoji-1.3.0.tgz", "integrity": "sha1-kDrhqZaMPxfU4ULxFdTsV15W0ss=" }, - "markdown-it-expand-tabs": { - "version": "1.0.12", - "resolved": "https://registry.npmjs.org/markdown-it-expand-tabs/-/markdown-it-expand-tabs-1.0.12.tgz", - "integrity": "sha1-9UvS8wP4WO5nmMor2D/nAUSBTKA=" - }, - "markdown-it-lazy-headers": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/markdown-it-lazy-headers/-/markdown-it-lazy-headers-0.1.3.tgz", - "integrity": "sha1-5w3U2nnIepzoLKRwG4t8Di1yKXs=" - }, "markdown-it-task-lists": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/markdown-it-task-lists/-/markdown-it-task-lists-2.0.1.tgz", diff --git a/package.json b/package.json index 0f800e5..a9d089f 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,6 @@ "lodash.pickby": "^4.2.1", "markdown-it": "^8.2.0", "markdown-it-emoji": "^1.3.0", - "markdown-it-expand-tabs": "^1.0.12", - "markdown-it-lazy-headers": "^0.1.3", "markdown-it-task-lists": "^2.0.1", "property-ttl": "^1.0.0", "sanitize-html": "^1.6.1", diff --git a/test/fixtures/dirty.md b/test/fixtures/dirty.md index 06e3eb3..638cb0e 100644 --- a/test/fixtures/dirty.md +++ b/test/fixtures/dirty.md @@ -14,16 +14,6 @@ ###### h6 -
- - # indented h1 - - ## indented h2 - - ### indented h3 - -
- diff --git a/test/fixtures/lazyheading.md b/test/fixtures/lazyheading.md deleted file mode 100644 index 9432dfa..0000000 --- a/test/fixtures/lazyheading.md +++ /dev/null @@ -1,12 +0,0 @@ - -#lazy heading 1 - -##lazy heading 2 - -###lazy heading 3 - -####lazy heading 4 - -#####lazy heading 5 - -######lazy heading 6 diff --git a/test/fixtures/link-ref-relaxed.md b/test/fixtures/link-ref-relaxed.md deleted file mode 100644 index 81ae619..0000000 --- a/test/fixtures/link-ref-relaxed.md +++ /dev/null @@ -1,2 +0,0 @@ -Some paragraph text here with a [linkref] -[linkref]: /actual/link/here diff --git a/test/fixtures/link-ref.md b/test/fixtures/link-ref.md deleted file mode 100644 index c6565f3..0000000 --- a/test/fixtures/link-ref.md +++ /dev/null @@ -1,3 +0,0 @@ -Some paragraph text here with a [linkref] - -[linkref]: /actual/link/here diff --git a/test/headings.js b/test/headings.js index cfdbfb9..c195099 100644 --- a/test/headings.js +++ b/test/headings.js @@ -35,16 +35,6 @@ describe('headings', function () { }) }) - it('does not parse indented ATX headings as headings', function () { - assert(~fixtures.dirty.indexOf(' # indented h1')) - assert(~fixtures.dirty.indexOf(' ## indented h2')) - assert(~fixtures.dirty.indexOf(' ### indented h3')) - assert.equal($md('#user-content-indented h1').length, 0) - assert.equal($md('#user-content-indented h2').length, 0) - assert.equal($md('#user-content-indented h3').length, 0) - assert.equal($md('#user-content-indented p').length, 3) - }) - it('injects hashy anchor tags into headings that have DOM ids', function () { assert(~fixtures.dirty.indexOf('# h1')) assert($md("h1 a[href='#h1']").length) @@ -192,17 +182,6 @@ describe('headings', function () { assert.equal($('h2 a#browser-input-helpers + code').length, 1) }) - it('properly handles headings lacking a space between the leading #(s) and heading text', function () { - assert(~fixtures.lazyheading.indexOf('#lazy heading')) - $ = cheerio.load(marky(fixtures.lazyheading, {prefixHeadingIds: false})) - assert.equal($('h1 a#lazy-heading-1').length, 1) - assert.equal($('h2 a#lazy-heading-2').length, 1) - assert.equal($('h3 a#lazy-heading-3').length, 1) - assert.equal($('h4 a#lazy-heading-4').length, 1) - assert.equal($('h5 a#lazy-heading-5').length, 1) - assert.equal($('h6 a#lazy-heading-6').length, 1) - }) - it('allows headings to interrupt paragraphs', function () { var markdown = 'this is a paragraph\n# Heading text\nSome more text here\nand another line' $ = cheerio.load(marky(markdown, {prefixHeadingIds: false})) diff --git a/test/markdown.js b/test/markdown.js index 825bb11..ee48c2f 100644 --- a/test/markdown.js +++ b/test/markdown.js @@ -17,23 +17,6 @@ describe('markdown processing', function () { }) describe('github flavored markdown', function () { - it('renders relaxed link reference definitions the same as normal ones', function () { - assert(~fixtures['link-ref'].indexOf('[linkref]:')) - assert(~fixtures['link-ref-relaxed'].indexOf('[linkref]:')) - var $normal = cheerio.load(marky(fixtures['link-ref'])) - var $relaxed = cheerio.load(marky(fixtures['link-ref-relaxed'])) - assert($normal('a[href="/actual/link/here"]').length) - assert($relaxed('a[href="/actual/link/here"]').length) - assert.equal($normal.html(), $relaxed.html()) - }) - - it('converts leading tabs in code blocks to spaces', function () { - var $ = cheerio.load(marky(fixtures.basic)) - var indentHtml = $('.highlight.js .line .comment span:not(.js)').html() - assert(!~indentHtml.indexOf('\t')) - assert(~indentHtml.indexOf(' ')) - }) - it('does not convert text emoticons to unicode', function () { assert(~fixtures.github.indexOf(':)')) var $ = cheerio.load(marky(fixtures.github)) @@ -115,51 +98,6 @@ describe('markdown processing', function () { assert(~tables.indexOf('\\|')) }) }) - - describe('loose link labels', function () { - it('still parses link references properly', function () { - var markdown = 'a [link] here\n\n[link]: #destination' - var $ = cheerio.load(marky(markdown)) - assert($('a[href="#destination"]').length) - }) - - it('allows link titles, delimited by \'\', "", or ()', function () { - var markdown = 'a [one] and a [two] and a [three]' - markdown += '\n\n' - markdown += "[one]: #destination 'with a title'\n" - markdown += '[two]: #destination "with a title"\n' - markdown += '[three]: #destination (with a title)\n' - var $ = cheerio.load(marky(markdown)) - assert.equal($('a').length, 3) - assert.equal($('a[title="with a title"]').length, 3) - }) - - it('allows whitespace between link labels and destinations', function () { - var markdown = 'a [link] (#destination) here' - var $ = cheerio.load(marky(markdown)) - assert($('a[href="#destination"]').length) - }) - - it('allows whitespace between image text and src', function () { - var markdown = 'an image: ![alt] (path/to/image)' - var $ = cheerio.load(marky(markdown)) - assert($('img[src="path/to/image"]').length) - }) - - it('allows whitespace in linked images with whitespace between text and src', function () { - var markdown = 'an image: [ ![alt] (path/to/image) ] (path/to/link)' - var $ = cheerio.load(marky(markdown)) - assert($('img[src="path/to/image"]').length) - assert($('a[href="path/to/link"]').length) - }) - - it('allows loose link labels to override link references', function () { - var markdown = 'a [link] (or is it) here\n\n[link]: #destination' - var $ = cheerio.load(marky(markdown)) - assert(!$('a[href="#destination"]').length) - assert($('a[href="or%20is%20it"]').length) - }) - }) }) describe('syntax highlighting', function () { diff --git a/test/sanitize.js b/test/sanitize.js index 9734197..25d4450 100644 --- a/test/sanitize.js +++ b/test/sanitize.js @@ -147,42 +147,6 @@ describe('sanitize', function () { assert.equal($('a').attr('title'), title) }) - it('allows spaces in path names', function () { - // images - var $ = cheerio.load(marky('![Gitter](https://badges.gitter.im/Join Chat.svg)')) - assert.equal($('img').attr('src'), 'https://badges.gitter.im/Join%20Chat.svg') - // anchors - $ = cheerio.load(marky('[link text](https://example.com/link me.html)')) - assert.equal($('a').attr('href'), 'https://example.com/link%20me.html') - }) - - it('allows spaces in path names with title attributes', function () { - // images - var title = 'Image title' - var $ = cheerio.load(marky('![Gitter](https://badges.gitter.im/Join Chat.svg "' + title + '")')) - assert.equal($('img').attr('src'), 'https://badges.gitter.im/Join%20Chat.svg') - assert.equal($('img').attr('title'), title) - // anchors - title = 'Link title' - $ = cheerio.load(marky('[link text](https://example.com/link me.html "' + title + '")')) - assert.equal($('a').attr('href'), 'https://example.com/link%20me.html') - assert.equal($('a').attr('title'), title) - }) - - it('allows spaces in path names of images used as anchors', function () { - var $ = cheerio.load(marky('[![Gitter](https://badges.gitter.im/Join Chat.svg)](#url)')) - assert.equal($('img').attr('src'), 'https://badges.gitter.im/Join%20Chat.svg') - assert.equal($('a').attr('href'), '#url') - }) - - it('allows spaces in path names when inline element is in paragraph', function () { - var src = 'I am a paragraph. This is a [link](http://example.com/link me.html).' - src += 'And here is an image: ![image](http://example.com/an image.png). This paragraph is now over.' - var $ = cheerio.load(marky(src)) - assert.equal($('img').attr('src'), 'http://example.com/an%20image.png') - assert.equal($('a').attr('href'), 'http://example.com/link%20me.html') - }) - it('allows the
/ elements', function () { var src = '# Test\n\n
Summary here\nLong long information, War & Peace, etc...
\n' var $ = cheerio.load(marky(src))