-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
129 lines (116 loc) · 3.79 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import {
gfmFootnoteFromMarkdown,
gfmFootnoteToMarkdown
} from 'mdast-util-gfm-footnote'
import {
gfmStrikethroughFromMarkdown,
gfmStrikethroughToMarkdown
} from 'mdast-util-gfm-strikethrough'
import {
gfmTableFromMarkdown,
gfmTableToMarkdown
} from 'mdast-util-gfm-table'
import {
gfmTaskListItemFromMarkdown,
gfmTaskListItemToMarkdown
} from 'mdast-util-gfm-task-list-item'
import { gfmFootnote } from 'micromark-extension-gfm-footnote'
import {
gfmStrikethrough
} from 'micromark-extension-gfm-strikethrough'
import { gfmTable } from 'micromark-extension-gfm-table'
import { gfmTaskListItem } from 'micromark-extension-gfm-task-list-item'
import { combineExtensions } from 'micromark-util-combine-extensions'
/**
* @typedef {import("micromark-extension-gfm-strikethrough").Options} GfmStrikethroughOptions
* @typedef {import("mdast-util-gfm-table").Options} GfmTableOptions
* @typedef {GfmStrikethroughOptions & GfmTableOptions} Options
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
*/
/**
* Create an extension for `micromark` to enable GFM syntax.
*
* @param {GfmStrikethroughOptions | null | undefined} [options]
* Configuration (optional).
*
* Passed to `micromark-extens-gfm-strikethrough`.
* @returns {import('micromark-util-types').Extension}
* Extension for `micromark` that can be passed in `extensions` to enable GFM
* syntax.
*/
function gfm(options) {
return combineExtensions([
gfmFootnote(),
gfmStrikethrough(options),
gfmTable(),
gfmTaskListItem()
])
}
/**
* Create an extension for `mdast-util-from-markdown` to enable GFM (autolink
* literals, footnotes, strikethrough, tables, tasklists).
*
* @returns {Array<FromMarkdownExtension>}
* Extension for `mdast-util-from-markdown` to enable GFM (autolink literals,
* footnotes, strikethrough, tables, tasklists).
*/
export function gfmFromMarkdown() {
return [
gfmFootnoteFromMarkdown(),
gfmStrikethroughFromMarkdown(),
gfmTableFromMarkdown(),
gfmTaskListItemFromMarkdown()
]
}
/**
* @param {GfmTableOptions | null | undefined} [options]
* @returns {ToMarkdownExtension}
*/
/**
* Create an extension for `mdast-util-to-markdown` to enable GFM (autolink
* literals, footnotes, strikethrough, tables, tasklists).
*
* @param {import('mdast-util-gfm-table').Options | null | undefined} [options]
* Configuration.
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable GFM (autolink literals,
* footnotes, strikethrough, tables, tasklists).
*/
export function gfmToMarkdown(options) {
return {
extensions: [
gfmFootnoteToMarkdown(),
gfmStrikethroughToMarkdown(),
gfmTableToMarkdown(options),
gfmTaskListItemToMarkdown()
]
}
}
/** @type {Options} */
const emptyOptions = {}
/**
* Add support GFM (footnotes, strikethrough, tables, tasklists).
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {undefined}
* Nothing.
*/
export default function remarkGfmNoAutoLink(options) {
// @ts-expect-error: TS is wrong about `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {Processor} */ (this)
const settings = options || emptyOptions
const data = self.data()
const micromarkExtensions =
data.micromarkExtensions || (data.micromarkExtensions = [])
const fromMarkdownExtensions =
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
const toMarkdownExtensions =
data.toMarkdownExtensions || (data.toMarkdownExtensions = [])
micromarkExtensions.push(gfm(settings))
fromMarkdownExtensions.push(gfmFromMarkdown())
toMarkdownExtensions.push(gfmToMarkdown(settings))
}