Skip to content

Commit ae46cf7

Browse files
committed
Remove warnings on lists, colons
1 parent e236216 commit ae46cf7

File tree

3 files changed

+27
-55
lines changed

3 files changed

+27
-55
lines changed

index.js

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import {containerFlow} from 'mdast-util-to-markdown/lib/util/container-flow.js'
1414
import {indentLines} from 'mdast-util-to-markdown/lib/util/indent-lines.js'
1515
import {safe} from 'mdast-util-to-markdown/lib/util/safe.js'
1616
import {track} from 'mdast-util-to-markdown/lib/util/track.js'
17-
import {visit, EXIT} from 'unist-util-visit'
18-
19-
let warningColonInFootnote = false
20-
let warningListInFootnote = false
2117

2218
/**
2319
* @returns {FromMarkdownExtension}
@@ -144,41 +140,23 @@ export function gfmFootnoteToMarkdown() {
144140
let value = tracker.move('[^')
145141
const exit = context.enter('footnoteDefinition')
146142
const subexit = context.enter('label')
147-
const id = safe(context, association(node), {
148-
...tracker.current(),
149-
before: value,
150-
after: ']'
151-
})
152-
value += tracker.move(id)
153143
value += tracker.move(
154-
']:' + (node.children && node.children.length > 0 ? ' ' : '')
144+
safe(context, association(node), {
145+
...tracker.current(),
146+
before: value,
147+
after: ']'
148+
})
155149
)
156150
subexit()
151+
value += tracker.move(
152+
']:' + (node.children && node.children.length > 0 ? ' ' : '')
153+
)
157154
tracker.shift(4)
158155
value += tracker.move(
159156
indentLines(containerFlow(node, context, tracker.current()), map)
160157
)
161158
exit()
162159

163-
if (!warningColonInFootnote && id.includes(':')) {
164-
console.warn(
165-
'[mdast-util-gfm-footnote] Warning: Found a colon in footnote identifier `' +
166-
id +
167-
'`. GitHub currently crahes on colons in footnotes (see <https://github.com/github/cmark-gfm/issues/241> for more info)'
168-
)
169-
warningColonInFootnote = true
170-
}
171-
172-
if (!warningListInFootnote) {
173-
visit(node, 'list', () => {
174-
console.warn(
175-
'[mdast-util-gfm-footnote] Warning: Found a list in a footnote definition. GitHub currently crahes on lists in footnotes (see <https://github.com/github/cmark-gfm/issues/241> for more info)'
176-
)
177-
warningListInFootnote = true
178-
return EXIT
179-
})
180-
}
181-
182160
return value
183161

184162
/** @type {Map} */

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
"dependencies": {
3737
"@types/mdast": "^3.0.0",
3838
"mdast-util-to-markdown": "^1.3.0",
39-
"micromark-util-normalize-identifier": "^1.0.0",
40-
"unist-util-visit": "^4.0.0"
39+
"micromark-util-normalize-identifier": "^1.0.0"
4140
},
4241
"devDependencies": {
4342
"@types/tape": "^4.0.0",

test.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -269,32 +269,27 @@ test('mdast -> markdown', (t) => {
269269
'should escape what would otherwise be an footnote definition'
270270
)
271271

272-
const warn = console.warn
273-
let called = 0
274-
275-
console.warn = () => {
276-
called++
277-
}
278-
279-
toMarkdown(
280-
{type: 'footnoteDefinition', identifier: 'a:b', children: []},
281-
{extensions: [gfmFootnoteToMarkdown()]}
272+
t.deepEqual(
273+
toMarkdown(
274+
{type: 'footnoteDefinition', identifier: 'a:b', children: []},
275+
{extensions: [gfmFootnoteToMarkdown()]}
276+
),
277+
'[^a:b]:\n',
278+
'should support colons in footnote definitions'
282279
)
283280

284-
t.equal(called, 1, 'should warn on colons in footnote identifiers')
285-
286-
toMarkdown(
287-
{
288-
type: 'footnoteDefinition',
289-
identifier: 'a',
290-
children: [{type: 'list', children: []}]
291-
},
292-
{extensions: [gfmFootnoteToMarkdown()]}
281+
t.deepEqual(
282+
toMarkdown(
283+
{
284+
type: 'footnoteDefinition',
285+
identifier: 'a',
286+
children: [{type: 'list', children: [{type: 'listItem', children: []}]}]
287+
},
288+
{extensions: [gfmFootnoteToMarkdown()]}
289+
),
290+
'[^a]: *\n',
291+
'should support lists in footnote definitions'
293292
)
294293

295-
t.equal(called, 2, 'should warn on lists in footnote definitions')
296-
297-
console.warn = warn
298-
299294
t.end()
300295
})

0 commit comments

Comments
 (0)