Skip to content

Commit 9b7b270

Browse files
committed
Fix to ignore footnotes, footnote references
Closes GH-66.
1 parent 7124daf commit 9b7b270

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

lib/contents.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var LIST_ITEM = 'listItem'
99
var PARAGRAPH = 'paragraph'
1010
var LINK = 'link'
1111
var LINK_REFERENCE = 'linkReference'
12+
var FOOTNOTE = 'footnote'
13+
var FOOTNOTE_REFERENCE = 'footnoteReference'
1214

1315
// Transform a list of heading objects to a markdown list.
1416
function contents(map, tight, prefix) {
@@ -107,7 +109,7 @@ function insert(entry, parent, tight, prefix) {
107109

108110
function all(children) {
109111
var result = []
110-
var length = children.length
112+
var length = children ? children.length : 0
111113
var index = -1
112114

113115
while (++index < length) {
@@ -120,7 +122,12 @@ function all(children) {
120122
function one(node) {
121123
var copy
122124

123-
if (node.type === LINK || node.type === LINK_REFERENCE) {
125+
if (
126+
node.type === LINK ||
127+
node.type === LINK_REFERENCE ||
128+
node.type === FOOTNOTE ||
129+
node.type === FOOTNOTE_REFERENCE
130+
) {
124131
return all(node.children)
125132
}
126133

test/fixtures/phrasing-content/output.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,8 @@
174174
"url": "#a-footnote",
175175
"children": [
176176
{
177-
"type": "footnote",
178-
"children": [
179-
{
180-
"type": "text",
181-
"value": "a footnote"
182-
}
183-
]
177+
"type": "text",
178+
"value": "a footnote"
184179
}
185180
]
186181
}
@@ -203,11 +198,6 @@
203198
{
204199
"type": "text",
205200
"value": "footnote reference "
206-
},
207-
{
208-
"type": "footnoteReference",
209-
"identifier": "1",
210-
"label": "1"
211201
}
212202
]
213203
}

0 commit comments

Comments
 (0)