Skip to content

Commit

Permalink
Move footnotes to remark-footnotes
Browse files Browse the repository at this point in the history
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 <christian.murphy.42@gmail.com>
  • Loading branch information
wooorm authored Mar 29, 2020
1 parent 510ceeb commit 065561b
Show file tree
Hide file tree
Showing 82 changed files with 47 additions and 16,267 deletions.
1 change: 0 additions & 1 deletion packages/remark-parse/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = {
position: true,
gfm: true,
commonmark: false,
footnotes: false,
pedantic: false,
blocks: require('./block-elements')
}
10 changes: 3 additions & 7 deletions packages/remark-parse/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ proto.interruptParagraph = [
['blockquote'],
['html'],
['setextHeading', {commonmark: false}],
['definition', {commonmark: false}],
['footnote', {commonmark: false}]
['definition', {commonmark: false}]
]

// Nodes that can interupt a list:
Expand All @@ -71,8 +70,7 @@ proto.interruptList = [
['atxHeading', {pedantic: false}],
['fencedCode', {pedantic: false}],
['thematicBreak', {pedantic: false}],
['definition', {commonmark: false}],
['footnote', {commonmark: false}]
['definition', {commonmark: false}]
]

// Nodes that can interupt a blockquote:
Expand All @@ -91,8 +89,7 @@ proto.interruptBlockquote = [
['thematicBreak', {commonmark: true}],
['html', {commonmark: true}],
['list', {commonmark: true}],
['definition', {commonmark: false}],
['footnote', {commonmark: false}]
['definition', {commonmark: false}]
]

// Handlers.
Expand All @@ -106,7 +103,6 @@ proto.blockTokenizers = {
list: require('./tokenize/list'),
setextHeading: require('./tokenize/heading-setext'),
html: require('./tokenize/html-block'),
footnote: require('./tokenize/footnote-definition'),
definition: require('./tokenize/definition'),
table: require('./tokenize/table'),
paragraph: require('./tokenize/paragraph')
Expand Down
13 changes: 9 additions & 4 deletions packages/remark-parse/lib/tokenize/blank-line.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use strict'

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

// 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),
// it's done by the list tokenizer and this blank-line tokenizer does not have to be responsible for that.
// Note that 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>), it’s done by the list
// tokenizer and this blank line tokenizer does not have to be responsible for
// that.
// Therefore, configs such as `blankLine.notInList` do not have to be set here.
module.exports = blankLine

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

while (index < length) {
match = reBlankLine.exec(value.slice(index))

if (match == null) {
break
}
Expand Down
190 changes: 0 additions & 190 deletions packages/remark-parse/lib/tokenize/footnote-definition.js

This file was deleted.

41 changes: 4 additions & 37 deletions packages/remark-parse/lib/tokenize/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ reference.locator = locate

var link = 'link'
var image = 'image'
var footnote = 'footnote'
var shortcut = 'shortcut'
var collapsed = 'collapsed'
var full = 'full'
var space = ' '
var exclamationMark = '!'
var leftSquareBracket = '['
var backslash = '\\'
var rightSquareBracket = ']'
var caret = '^'

function reference(eat, value, silent) {
var self = this
var commonmark = self.options.commonmark
var footnotes = self.options.footnotes
var character = value.charAt(0)
var index = 0
var length = value.length
Expand Down Expand Up @@ -55,19 +51,6 @@ function reference(eat, value, silent) {
intro += character
queue = ''

// Check whether we’re eating a footnote.
if (footnotes && value.charAt(index) === caret) {
// Exit if `![^` is found, so the `!` will be seen as text after this,
// and we’ll enter this function again when `[^` is found.
if (type === image) {
return
}

intro += caret
index++
type = footnote
}

// Eat the text.
depth = 0

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

character = value.charAt(index)

// Inline footnotes cannot have a label.
// If footnotes are enabled, link labels cannot start with a caret.
if (
type !== footnote &&
character === leftSquareBracket &&
(!footnotes || value.charAt(index + 1) !== caret)
) {
if (character === leftSquareBracket) {
identifier = ''
queue += character
index++
Expand Down Expand Up @@ -187,13 +164,6 @@ function reference(eat, value, silent) {
return true
}

if (type === footnote && content.indexOf(space) !== -1) {
return eat(subvalue)({
type: footnote,
children: this.tokenizeInline(content, eat.now())
})
}

now = eat.now()
now.column += intro.length
now.offset += intro.length
Expand All @@ -202,18 +172,15 @@ function reference(eat, value, silent) {
node = {
type: type + 'Reference',
identifier: normalize(identifier),
label: identifier
}

if (type === link || type === image) {
node.referenceType = referenceType
label: identifier,
referenceType: referenceType
}

if (type === link) {
exit = self.enterLink()
node.children = self.tokenizeInline(content, now)
exit()
} else if (type === image) {
} else {
node.alt = self.decode.raw(self.unescape(content), now) || null
}

Expand Down
8 changes: 6 additions & 2 deletions packages/remark-parse/lib/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ function factory(type) {
name = methods[index]
method = tokenizers[name]

// Previously, we had constructs such as footnotes and YAML that used
// these properties.
// Those are now external (plus there are userland extensions), that may
// still use them.
if (
method &&
/* istanbul ignore next */ (!method.onlyAtStart || self.atStart) &&
(!method.notInList || !self.inList) &&
(!method.notInBlock || !self.inBlock) &&
/* istanbul ignore next */ (!method.notInList || !self.inList) &&
/* istanbul ignore next */ (!method.notInBlock || !self.inBlock) &&
(!method.notInLink || !self.inLink)
) {
valueLength = value.length
Expand Down
Loading

0 comments on commit 065561b

Please sign in to comment.