Skip to content

Commit 065561b

Browse files
authored
Move footnotes to remark-footnotes
Footnotes are now available in `remark-footnotes`, where they received significant improvements to become much better! Footnotes parsing has been completely rewritten there, so please take note when upgrading and switching to `remark-footnotes`. Upgrade remark, remove the `footnotes: true` option, and instead: ```js .use(footnotes, {inlineNotes: true}) ``` * Inline notes changed from `[^inline note]` (broken) to `^[inline note]` (works) * Many bug fixes! Closes GH-483. Reviewed-by: Christian Murphy <[email protected]>
1 parent 510ceeb commit 065561b

File tree

82 files changed

+47
-16267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+47
-16267
lines changed

packages/remark-parse/lib/defaults.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = {
44
position: true,
55
gfm: true,
66
commonmark: false,
7-
footnotes: false,
87
pedantic: false,
98
blocks: require('./block-elements')
109
}

packages/remark-parse/lib/parser.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ proto.interruptParagraph = [
5555
['blockquote'],
5656
['html'],
5757
['setextHeading', {commonmark: false}],
58-
['definition', {commonmark: false}],
59-
['footnote', {commonmark: false}]
58+
['definition', {commonmark: false}]
6059
]
6160

6261
// Nodes that can interupt a list:
@@ -71,8 +70,7 @@ proto.interruptList = [
7170
['atxHeading', {pedantic: false}],
7271
['fencedCode', {pedantic: false}],
7372
['thematicBreak', {pedantic: false}],
74-
['definition', {commonmark: false}],
75-
['footnote', {commonmark: false}]
73+
['definition', {commonmark: false}]
7674
]
7775

7876
// Nodes that can interupt a blockquote:
@@ -91,8 +89,7 @@ proto.interruptBlockquote = [
9189
['thematicBreak', {commonmark: true}],
9290
['html', {commonmark: true}],
9391
['list', {commonmark: true}],
94-
['definition', {commonmark: false}],
95-
['footnote', {commonmark: false}]
92+
['definition', {commonmark: false}]
9693
]
9794

9895
// Handlers.
@@ -106,7 +103,6 @@ proto.blockTokenizers = {
106103
list: require('./tokenize/list'),
107104
setextHeading: require('./tokenize/heading-setext'),
108105
html: require('./tokenize/html-block'),
109-
footnote: require('./tokenize/footnote-definition'),
110106
definition: require('./tokenize/definition'),
111107
table: require('./tokenize/table'),
112108
paragraph: require('./tokenize/paragraph')

packages/remark-parse/lib/tokenize/blank-line.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
'use strict'
22

3-
// A line containing no characters, or a line containing only spaces (U+0020) or tabs (U+0009), is called a blank line.
4-
// See https://spec.commonmark.org/0.29/#blank-line
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 <https://spec.commonmark.org/0.29/#blank-line>.
56
var reBlankLine = /^[ \t]*(\n|$)/
67

7-
// NOTE: Though blank lines play a special role in lists to determine whether the list is tight or loose (https://spec.commonmark.org/0.29/#blank-lines),
8-
// it's done by the list tokenizer and this blank-line tokenizer does not have to be responsible for that.
8+
// Note that though blank lines play a special role in lists to determine
9+
// whether the list is tight or loose
10+
// (<https://spec.commonmark.org/0.29/#blank-lines>), it’s done by the list
11+
// tokenizer and this blank line tokenizer does not have to be responsible for
12+
// that.
913
// Therefore, configs such as `blankLine.notInList` do not have to be set here.
1014
module.exports = blankLine
1115

@@ -17,6 +21,7 @@ function blankLine(eat, value, silent) {
1721

1822
while (index < length) {
1923
match = reBlankLine.exec(value.slice(index))
24+
2025
if (match == null) {
2126
break
2227
}

packages/remark-parse/lib/tokenize/footnote-definition.js

Lines changed: 0 additions & 190 deletions
This file was deleted.

packages/remark-parse/lib/tokenize/reference.js

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@ reference.locator = locate
99

1010
var link = 'link'
1111
var image = 'image'
12-
var footnote = 'footnote'
1312
var shortcut = 'shortcut'
1413
var collapsed = 'collapsed'
1514
var full = 'full'
16-
var space = ' '
1715
var exclamationMark = '!'
1816
var leftSquareBracket = '['
1917
var backslash = '\\'
2018
var rightSquareBracket = ']'
21-
var caret = '^'
2219

2320
function reference(eat, value, silent) {
2421
var self = this
2522
var commonmark = self.options.commonmark
26-
var footnotes = self.options.footnotes
2723
var character = value.charAt(0)
2824
var index = 0
2925
var length = value.length
@@ -55,19 +51,6 @@ function reference(eat, value, silent) {
5551
intro += character
5652
queue = ''
5753

58-
// Check whether we’re eating a footnote.
59-
if (footnotes && value.charAt(index) === caret) {
60-
// Exit if `![^` is found, so the `!` will be seen as text after this,
61-
// and we’ll enter this function again when `[^` is found.
62-
if (type === image) {
63-
return
64-
}
65-
66-
intro += caret
67-
index++
68-
type = footnote
69-
}
70-
7154
// Eat the text.
7255
depth = 0
7356

@@ -124,13 +107,7 @@ function reference(eat, value, silent) {
124107

125108
character = value.charAt(index)
126109

127-
// Inline footnotes cannot have a label.
128-
// If footnotes are enabled, link labels cannot start with a caret.
129-
if (
130-
type !== footnote &&
131-
character === leftSquareBracket &&
132-
(!footnotes || value.charAt(index + 1) !== caret)
133-
) {
110+
if (character === leftSquareBracket) {
134111
identifier = ''
135112
queue += character
136113
index++
@@ -187,13 +164,6 @@ function reference(eat, value, silent) {
187164
return true
188165
}
189166

190-
if (type === footnote && content.indexOf(space) !== -1) {
191-
return eat(subvalue)({
192-
type: footnote,
193-
children: this.tokenizeInline(content, eat.now())
194-
})
195-
}
196-
197167
now = eat.now()
198168
now.column += intro.length
199169
now.offset += intro.length
@@ -202,18 +172,15 @@ function reference(eat, value, silent) {
202172
node = {
203173
type: type + 'Reference',
204174
identifier: normalize(identifier),
205-
label: identifier
206-
}
207-
208-
if (type === link || type === image) {
209-
node.referenceType = referenceType
175+
label: identifier,
176+
referenceType: referenceType
210177
}
211178

212179
if (type === link) {
213180
exit = self.enterLink()
214181
node.children = self.tokenizeInline(content, now)
215182
exit()
216-
} else if (type === image) {
183+
} else {
217184
node.alt = self.decode.raw(self.unescape(content), now) || null
218185
}
219186

packages/remark-parse/lib/tokenizer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ function factory(type) {
4646
name = methods[index]
4747
method = tokenizers[name]
4848

49+
// Previously, we had constructs such as footnotes and YAML that used
50+
// these properties.
51+
// Those are now external (plus there are userland extensions), that may
52+
// still use them.
4953
if (
5054
method &&
5155
/* istanbul ignore next */ (!method.onlyAtStart || self.atStart) &&
52-
(!method.notInList || !self.inList) &&
53-
(!method.notInBlock || !self.inBlock) &&
56+
/* istanbul ignore next */ (!method.notInList || !self.inList) &&
57+
/* istanbul ignore next */ (!method.notInBlock || !self.inBlock) &&
5458
(!method.notInLink || !self.inLink)
5559
) {
5660
valueLength = value.length

0 commit comments

Comments
 (0)