Skip to content

Commit 2572d7b

Browse files
authored
Remove hubdown and use our own markdown pipeline (github#17551)
* Uninstall hubdown, install unified deps * Create create-processor * Use it * Update a doc * Tweak the language * Use the same versions that hubdown used
1 parent 31d3937 commit 2572d7b

File tree

5 files changed

+59
-98
lines changed

5 files changed

+59
-98
lines changed

contributing/content-markup-reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
[Markdown](http://daringfireball.net/projects/markdown/) is a human-friendly syntax for formatting plain text. Our documentation is written with [GitHub Flavored Markdown](https://docs.github.com/en/github/writing-on-github/about-writing-and-formatting-on-github), a custom version of Markdown used across GitHub.
1818

19-
This site's Markdown rendering is powered by the [`/lib/render-content`](/lib/render-content) and [`hubdown`](https://github.com/electron/hubdown) npm packages, which are in turn built on the [`remark`](https://remark.js.org/) Markdown processor.
19+
This site's Markdown rendering is powered by [`/lib/render-content`](/lib/render-content), which is in turn built on the [`remark`](https://remark.js.org/) Markdown processor.
2020

2121
## Callout tags
2222

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const unified = require('unified')
2+
const markdown = require('remark-parse')
3+
const emoji = require('remark-gemoji-to-emoji')
4+
const remark2rehype = require('remark-rehype')
5+
const raw = require('rehype-raw')
6+
const slug = require('rehype-slug')
7+
const autolinkHeadings = require('rehype-autolink-headings')
8+
const highlight = require('rehype-highlight')
9+
const html = require('rehype-stringify')
10+
const graphql = require('highlightjs-graphql').definer
11+
const remarkCodeExtra = require('remark-code-extra')
12+
const codeHeader = require('./plugins/code-header')
13+
14+
module.exports = function createProcessor () {
15+
return unified()
16+
.use(markdown)
17+
.use(remarkCodeExtra, { transform: codeHeader })
18+
.use(emoji)
19+
.use(remark2rehype, { allowDangerousHTML: true })
20+
.use(slug)
21+
.use(autolinkHeadings, { behavior: 'wrap' })
22+
.use(highlight, { languages: { graphql }, subset: false })
23+
.use(raw)
24+
.use(html)
25+
}

lib/render-content/renderContent.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const liquid = require('./liquid')
2-
const codeHeader = require('./plugins/code-header')
3-
const hubdown = require('hubdown')
4-
const remarkCodeExtra = require('remark-code-extra')
52
const cheerio = require('cheerio')
63
const Entities = require('html-entities').XmlEntities
74
const entities = new Entities()
85
const stripHtmlComments = require('strip-html-comments')
6+
const createProcessor = require('./create-processor')
97

108
// used below to remove extra newlines in TOC lists
119
const endLine = '</a>\r?\n'
@@ -54,13 +52,9 @@ module.exports = async function renderContent (
5452
// statements so that extra space doesn't mess with list numbering
5553
template = template.replace(/(\r?\n){3}/g, '\n\n')
5654

57-
let { content: html } = await hubdown(template, {
58-
// Disable automatic language guessing in syntax highlighting
59-
highlight: { subset: false },
60-
runBefore: [[
61-
remarkCodeExtra, { transform: codeHeader }
62-
]]
63-
})
55+
const processor = createProcessor()
56+
const vFile = await processor.process(template)
57+
let html = vFile.toString()
6458

6559
// Remove unwanted newlines (which appear as spaces) from inline tags inside tables
6660
if (html.includes('<table>')) html = removeNewlinesFromInlineTags(html)

package-lock.json

+19-86
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
"hast-util-from-parse5": "^6.0.1",
5353
"hastscript": "^6.0.0",
5454
"helmet": "^3.21.2",
55+
"highlightjs-graphql": "^1.0.2",
5556
"hot-shots": "^8.2.0",
5657
"html-entities": "^1.2.1",
5758
"html-truncate": "^1.2.2",
58-
"hubdown": "^2.6.0",
5959
"imurmurhash": "^0.1.4",
6060
"ioredis": "^4.19.4",
6161
"ioredis-mock": "^5.2.0",
@@ -79,7 +79,15 @@
7979
"react": "^17.0.1",
8080
"react-dom": "^17.0.1",
8181
"readline-sync": "^1.4.10",
82+
"rehype-autolink-headings": "^2.0.5",
83+
"rehype-highlight": "^3.1.0",
84+
"rehype-raw": "^4.0.2",
85+
"rehype-slug": "^2.0.3",
86+
"rehype-stringify": "^6.0.1",
8287
"remark-code-extra": "^1.0.1",
88+
"remark-gemoji-to-emoji": "^1.1.0",
89+
"remark-parse": "^7.0.2",
90+
"remark-rehype": "^5.0.0",
8391
"resolve-url-loader": "^3.1.2",
8492
"rimraf": "^3.0.0",
8593
"sass": "^1.26.3",
@@ -89,6 +97,7 @@
8997
"slash": "^3.0.0",
9098
"strip-html-comments": "^1.0.0",
9199
"style-loader": "^1.2.1",
100+
"unified": "^8.4.2",
92101
"unist-util-visit": "^2.0.3",
93102
"uuid": "^8.3.0",
94103
"walk-sync": "^1.1.4",

0 commit comments

Comments
 (0)