From ae46cf7c3e34bab7da0ed07b5efec4ae1a83b4bd Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 31 Jan 2022 16:18:04 +0100 Subject: [PATCH] Remove warnings on lists, colons --- index.js | 38 ++++++++------------------------------ package.json | 3 +-- test.js | 41 ++++++++++++++++++----------------------- 3 files changed, 27 insertions(+), 55 deletions(-) diff --git a/index.js b/index.js index fa84d9f..98b5aa4 100644 --- a/index.js +++ b/index.js @@ -14,10 +14,6 @@ import {containerFlow} from 'mdast-util-to-markdown/lib/util/container-flow.js' import {indentLines} from 'mdast-util-to-markdown/lib/util/indent-lines.js' import {safe} from 'mdast-util-to-markdown/lib/util/safe.js' import {track} from 'mdast-util-to-markdown/lib/util/track.js' -import {visit, EXIT} from 'unist-util-visit' - -let warningColonInFootnote = false -let warningListInFootnote = false /** * @returns {FromMarkdownExtension} @@ -144,41 +140,23 @@ export function gfmFootnoteToMarkdown() { let value = tracker.move('[^') const exit = context.enter('footnoteDefinition') const subexit = context.enter('label') - const id = safe(context, association(node), { - ...tracker.current(), - before: value, - after: ']' - }) - value += tracker.move(id) value += tracker.move( - ']:' + (node.children && node.children.length > 0 ? ' ' : '') + safe(context, association(node), { + ...tracker.current(), + before: value, + after: ']' + }) ) subexit() + value += tracker.move( + ']:' + (node.children && node.children.length > 0 ? ' ' : '') + ) tracker.shift(4) value += tracker.move( indentLines(containerFlow(node, context, tracker.current()), map) ) exit() - if (!warningColonInFootnote && id.includes(':')) { - console.warn( - '[mdast-util-gfm-footnote] Warning: Found a colon in footnote identifier `' + - id + - '`. GitHub currently crahes on colons in footnotes (see for more info)' - ) - warningColonInFootnote = true - } - - if (!warningListInFootnote) { - visit(node, 'list', () => { - console.warn( - '[mdast-util-gfm-footnote] Warning: Found a list in a footnote definition. GitHub currently crahes on lists in footnotes (see for more info)' - ) - warningListInFootnote = true - return EXIT - }) - } - return value /** @type {Map} */ diff --git a/package.json b/package.json index fec4104..6930b11 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,7 @@ "dependencies": { "@types/mdast": "^3.0.0", "mdast-util-to-markdown": "^1.3.0", - "micromark-util-normalize-identifier": "^1.0.0", - "unist-util-visit": "^4.0.0" + "micromark-util-normalize-identifier": "^1.0.0" }, "devDependencies": { "@types/tape": "^4.0.0", diff --git a/test.js b/test.js index 07cdece..e09f017 100644 --- a/test.js +++ b/test.js @@ -269,32 +269,27 @@ test('mdast -> markdown', (t) => { 'should escape what would otherwise be an footnote definition' ) - const warn = console.warn - let called = 0 - - console.warn = () => { - called++ - } - - toMarkdown( - {type: 'footnoteDefinition', identifier: 'a:b', children: []}, - {extensions: [gfmFootnoteToMarkdown()]} + t.deepEqual( + toMarkdown( + {type: 'footnoteDefinition', identifier: 'a:b', children: []}, + {extensions: [gfmFootnoteToMarkdown()]} + ), + '[^a:b]:\n', + 'should support colons in footnote definitions' ) - t.equal(called, 1, 'should warn on colons in footnote identifiers') - - toMarkdown( - { - type: 'footnoteDefinition', - identifier: 'a', - children: [{type: 'list', children: []}] - }, - {extensions: [gfmFootnoteToMarkdown()]} + t.deepEqual( + toMarkdown( + { + type: 'footnoteDefinition', + identifier: 'a', + children: [{type: 'list', children: [{type: 'listItem', children: []}]}] + }, + {extensions: [gfmFootnoteToMarkdown()]} + ), + '[^a]: *\n', + 'should support lists in footnote definitions' ) - t.equal(called, 2, 'should warn on lists in footnote definitions') - - console.warn = warn - t.end() })