-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathprocessor.js
More file actions
94 lines (91 loc) · 3.37 KB
/
processor.js
File metadata and controls
94 lines (91 loc) · 3.37 KB
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
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import gfm from 'remark-gfm'
import emoji from 'remark-gemoji-to-emoji'
import remark2rehype from 'remark-rehype'
import raw from 'rehype-raw'
import slug from 'rehype-slug'
import highlight from 'rehype-highlight'
import { common } from 'lowlight'
import dockerfile from 'highlight.js/lib/languages/dockerfile'
import http from 'highlight.js/lib/languages/http'
import groovy from 'highlight.js/lib/languages/groovy'
import erb from 'highlight.js/lib/languages/erb'
import powershell from 'highlight.js/lib/languages/powershell'
import graphql from 'highlight.js/lib/languages/graphql'
import html from 'rehype-stringify'
import codeHeader from './code-header.js'
import rewriteLocalLinks from './rewrite-local-links.js'
import rewriteImgSources from './rewrite-asset-urls.js'
import rewriteAssetImgTags from './rewrite-asset-img-tags.js'
import useEnglishHeadings from './use-english-headings.js'
import headingLinks from './heading-links.js'
import rewriteTheadThScope from './rewrite-thead-th-scope.js'
import rewriteEmptyTableRows from './rewrite-empty-table-rows.js'
import rewriteForRowheaders from './rewrite-for-rowheaders.js'
import wrapProceduralImages from './wrap-procedural-images.js'
import parseInfoString from './parse-info-string.js'
import annotate from './annotate.js'
import alerts from './alerts.js'
import removeHtmlComments from 'remark-remove-comments'
import remarkStringify from 'remark-stringify'
export function createProcessor(context) {
return (
unified()
.use(remarkParse)
.use(removeHtmlComments)
.use(gfm)
// Markdown AST below vvv
.use(parseInfoString)
.use(rewriteLocalLinks, context)
.use(emoji)
// Markdown AST above ^^^
.use(remark2rehype, { allowDangerousHtml: true })
// HTML AST below vvv
.use(slug)
.use(useEnglishHeadings, context)
.use(headingLinks)
.use(codeHeader)
.use(annotate)
.use(highlight, {
languages: { ...common, graphql, dockerfile, http, groovy, erb, powershell },
subset: false,
aliases: {
// As of Jan 2024, 'jsonc' is not supported by highlight.js. It
// just because plain text.
// But 'jsonc' works great in github.com. For example, when
// previewing and edited .md content in the browser. Or viewing
// PR diffs in web view.
// So by sticking to 'jsonc' where there's JSON with comments,
// it's technically more correct, looks good in github.com,
// but with this alias you get the nice syntax highlighting when
// viewed on our site.
json: 'jsonc',
},
})
.use(raw)
.use(wrapProceduralImages)
.use(rewriteEmptyTableRows)
.use(rewriteTheadThScope)
.use(rewriteForRowheaders)
.use(rewriteImgSources)
.use(rewriteAssetImgTags)
.use(alerts, context)
// HTML AST above ^^^
.use(html)
// String below vvv
)
}
export function createMarkdownOnlyProcessor(context) {
return unified().use(remarkParse).use(gfm).use(rewriteLocalLinks, context).use(remarkStringify)
}
export function createMinimalProcessor(context) {
return unified()
.use(remarkParse)
.use(gfm)
.use(rewriteLocalLinks, context)
.use(remark2rehype, { allowDangerousHtml: true })
.use(slug)
.use(raw)
.use(html)
}