Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 717f6ec

Browse files
committed
.
0 parents  commit 717f6ec

Some content is hidden

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

54 files changed

+2032
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
.nyc_output/
4+
coverage/
5+
node_modules/
6+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage/
2+
*.json
3+
*.html
4+
*.md

.remarkignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- lts/dubnium
4+
- node
5+
after_script: bash <(curl -s https://codecov.io/bash)

html.js

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
var normalizeIdentifier = require('micromark/dist/util/normalize-identifier')
2+
3+
exports.enter = {
4+
footnoteDefinitionLabelString: buffer,
5+
footnoteCallString: buffer,
6+
inlineNoteText: enterNoteText
7+
}
8+
exports.exit = {
9+
footnoteDefinition: exitFootnoteDefinition,
10+
footnoteDefinitionLabelString: exitFootnoteDefinitionLabelString,
11+
footnoteCallString: exitFootnoteCallString,
12+
inlineNoteText: exitNoteText,
13+
null: exitDocument
14+
}
15+
16+
var own = {}.hasOwnProperty
17+
18+
function buffer() {
19+
this.buffer()
20+
}
21+
22+
function exitFootnoteDefinitionLabelString(token) {
23+
var stack = this.getData('footnoteDefinitionStack')
24+
25+
if (!stack) this.setData('footnoteDefinitionStack', (stack = []))
26+
27+
stack.push(normalizeIdentifier(this.sliceSerialize(token)))
28+
this.resume() // Drop the label.
29+
this.buffer() // Get ready for a value.
30+
}
31+
32+
function exitFootnoteDefinition() {
33+
var definitions = this.getData('footnoteDefinitions')
34+
var stack = this.getData('footnoteDefinitionStack')
35+
var current = stack.pop()
36+
var value = this.resume()
37+
38+
if (!definitions) this.setData('footnoteDefinitions', (definitions = {}))
39+
if (!own.call(definitions, current)) definitions[current] = value
40+
}
41+
42+
function exitFootnoteCallString(token) {
43+
var calls = this.getData('footnoteCallOrder')
44+
var id = normalizeIdentifier(this.sliceSerialize(token))
45+
var index
46+
var counter
47+
48+
this.resume()
49+
50+
if (!calls) this.setData('footnoteCallOrder', (calls = []))
51+
52+
index = calls.indexOf(id)
53+
54+
if (index === -1) {
55+
calls.push(id)
56+
counter = calls.length
57+
} else {
58+
counter = index + 1
59+
}
60+
61+
createCall.call(this, String(counter))
62+
}
63+
64+
function exitDocument() {
65+
var calls = this.getData('footnoteCallOrder') || []
66+
var definitions = this.getData('footnoteDefinitions') || {}
67+
var notes = this.getData('inlineNotes') || {}
68+
var index = -1
69+
var length = calls.length
70+
var value
71+
var id
72+
var injected
73+
var back
74+
var counter
75+
76+
if (length) {
77+
this.lineEndingIfNeeded()
78+
this.tag('<div class="footnotes">')
79+
this.lineEndingIfNeeded()
80+
this.tag('<hr />')
81+
this.lineEndingIfNeeded()
82+
this.tag('<ol>')
83+
}
84+
85+
while (++index < length) {
86+
// Called definitions are always defined.
87+
id = calls[index]
88+
counter = String(index + 1)
89+
injected = false
90+
back = '<a href="#fnref' + counter + '" class="footnote-back">↩︎</a>'
91+
value = (typeof id === 'number' ? notes : definitions)[id].replace(
92+
/<\/p>(?:\r?\n|\r)?$/,
93+
injectBack
94+
)
95+
96+
this.lineEndingIfNeeded()
97+
this.tag('<li id="fn' + counter + '">')
98+
this.lineEndingIfNeeded()
99+
this.raw(value)
100+
101+
if (!injected) {
102+
this.lineEndingIfNeeded()
103+
this.tag(back)
104+
}
105+
106+
this.lineEndingIfNeeded()
107+
this.tag('</li>')
108+
}
109+
110+
if (length) {
111+
this.lineEndingIfNeeded()
112+
this.tag('</ol>')
113+
this.lineEndingIfNeeded()
114+
this.tag('</div>')
115+
}
116+
117+
function injectBack($0) {
118+
injected = true
119+
return back + $0
120+
}
121+
}
122+
123+
function enterNoteText() {
124+
var counter = (this.getData('inlineNoteCounter') || 0) + 1
125+
var stack = this.getData('inlineNoteStack')
126+
var calls = this.getData('footnoteCallOrder')
127+
128+
if (!stack) this.setData('inlineNoteStack', (stack = []))
129+
if (!calls) this.setData('footnoteCallOrder', (calls = []))
130+
131+
stack.push(counter)
132+
calls.push(counter)
133+
this.setData('inlineNoteCounter', counter)
134+
this.buffer()
135+
}
136+
137+
function exitNoteText() {
138+
var counter = this.getData('inlineNoteStack').pop()
139+
var notes = this.getData('inlineNotes')
140+
141+
if (!notes) this.setData('inlineNotes', (notes = {}))
142+
143+
notes[counter] = '<p>' + this.resume() + '</p>'
144+
createCall.call(this, String(counter))
145+
}
146+
147+
function createCall(counter) {
148+
this.tag(
149+
'<a href="#fn' +
150+
counter +
151+
'" class="footnote-ref" id="fnref' +
152+
counter +
153+
'"><sup>'
154+
)
155+
this.raw(counter)
156+
this.tag('</sup></a>')
157+
}

0 commit comments

Comments
 (0)