Remove hubdown and use our own markdown pipeline (#17551)

* Uninstall hubdown, install unified deps

* Create create-processor

* Use it

* Update a doc

* Tweak the language

* Use the same versions that hubdown used
This commit is contained in:
Jason Etcovitch 2021-01-28 17:06:19 -05:00 коммит произвёл GitHub
Родитель 31d3937025
Коммит 2572d7bb85
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 59 добавлений и 98 удалений

Просмотреть файл

@ -16,7 +16,7 @@
[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.
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.
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.
## Callout tags

Просмотреть файл

@ -0,0 +1,25 @@
const unified = require('unified')
const markdown = require('remark-parse')
const emoji = require('remark-gemoji-to-emoji')
const remark2rehype = require('remark-rehype')
const raw = require('rehype-raw')
const slug = require('rehype-slug')
const autolinkHeadings = require('rehype-autolink-headings')
const highlight = require('rehype-highlight')
const html = require('rehype-stringify')
const graphql = require('highlightjs-graphql').definer
const remarkCodeExtra = require('remark-code-extra')
const codeHeader = require('./plugins/code-header')
module.exports = function createProcessor () {
return unified()
.use(markdown)
.use(remarkCodeExtra, { transform: codeHeader })
.use(emoji)
.use(remark2rehype, { allowDangerousHTML: true })
.use(slug)
.use(autolinkHeadings, { behavior: 'wrap' })
.use(highlight, { languages: { graphql }, subset: false })
.use(raw)
.use(html)
}

Просмотреть файл

@ -1,11 +1,9 @@
const liquid = require('./liquid')
const codeHeader = require('./plugins/code-header')
const hubdown = require('hubdown')
const remarkCodeExtra = require('remark-code-extra')
const cheerio = require('cheerio')
const Entities = require('html-entities').XmlEntities
const entities = new Entities()
const stripHtmlComments = require('strip-html-comments')
const createProcessor = require('./create-processor')
// used below to remove extra newlines in TOC lists
const endLine = '</a>\r?\n'
@ -54,13 +52,9 @@ module.exports = async function renderContent (
// statements so that extra space doesn't mess with list numbering
template = template.replace(/(\r?\n){3}/g, '\n\n')
let { content: html } = await hubdown(template, {
// Disable automatic language guessing in syntax highlighting
highlight: { subset: false },
runBefore: [[
remarkCodeExtra, { transform: codeHeader }
]]
})
const processor = createProcessor()
const vFile = await processor.process(template)
let html = vFile.toString()
// Remove unwanted newlines (which appear as spaces) from inline tags inside tables
if (html.includes('<table>')) html = removeNewlinesFromInlineTags(html)

105
package-lock.json сгенерированный
Просмотреть файл

@ -7217,9 +7217,9 @@
"dev": true
},
"ccount": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/ccount/-/ccount-1.0.5.tgz",
"integrity": "sha512-MOli1W+nfbPLlKEhInaxhRdp7KVLFxLN5ykwzHgLsLI3H3gs5jjFAK4Eoj3OzzcxCtumDaI8onoVDeQyWaNTkw=="
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/ccount/-/ccount-1.1.0.tgz",
"integrity": "sha512-vlNK021QdI7PNeiUh/lKkC/mNHHfV0m/Ad5JoI0TYtlBnJAslM/JIkm/tGC88bkLIwO6OQ5uV6ztS6kVAtCDlg=="
},
"chalk": {
"version": "4.1.0",
@ -9002,9 +9002,9 @@
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"detab": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/detab/-/detab-2.0.3.tgz",
"integrity": "sha512-Up8P0clUVwq0FnFjDclzZsy9PadzRn5FFxrr47tQQvMHqyiFYVbpH8oXDzWtF0Q7pYy3l+RPmtBl+BsFF6wH0A==",
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/detab/-/detab-2.0.4.tgz",
"integrity": "sha512-8zdsQA5bIkoRECvCrNKPla84lyoR7DSAyf7p0YgXzBO9PDJx8KntPUay7NS6yp+KdxdVtiE5SpHKtbp2ZQyA9g==",
"requires": {
"repeat-string": "^1.5.4"
}
@ -12445,14 +12445,6 @@
"minimalistic-assert": "^1.0.1"
}
},
"hasha": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/hasha/-/hasha-3.0.0.tgz",
"integrity": "sha1-UqMvq4Vp1BymmmH/GiFPjrfIvTk=",
"requires": {
"is-stream": "^1.0.1"
}
},
"hast-to-hyperscript": {
"version": "7.0.4",
"resolved": "https://registry.npmjs.org/hast-to-hyperscript/-/hast-to-hyperscript-7.0.4.tgz",
@ -12683,9 +12675,9 @@
"integrity": "sha512-Io1zA2yOA1YJslkr+AJlWSf2yWFkKjvkcL9Ni1XSUqnGLr/qRQe2UI3Cn/J9MsJht7yEVCe0SscY1HgVMujbgg=="
},
"highlight.js": {
"version": "10.3.1",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.3.1.tgz",
"integrity": "sha512-jeW8rdPdhshYKObedYg5XGbpVgb1/DT4AHvDFXhkU7UnGSIjy9kkJ7zHG7qplhFHMitTSzh5/iClKQk3Kb2RFQ=="
"version": "10.5.0",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.5.0.tgz",
"integrity": "sha512-xTmvd9HiIHR6L53TMC7TKolEj65zG1XU+Onr8oi86mYa+nLcIbxTTWkpW7CsEwv/vK7u1zb8alZIMLDqqN6KTw=="
},
"highlightjs-graphql": {
"version": "1.0.2",
@ -12895,52 +12887,6 @@
}
}
},
"hubdown": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/hubdown/-/hubdown-2.6.0.tgz",
"integrity": "sha512-gqC4TfGK/gEuAElYRZh4HUEz+TCM4BZ6NQZkNOvWurhQu+PwaF6PVPPTb9DN1h1DUn/kEsFL37XsUJPnJWae+Q==",
"requires": {
"gray-matter": "^3.0.7",
"hasha": "^3.0.0",
"highlightjs-graphql": "^1.0.1",
"json-stable-stringify": "^1.0.1",
"rehype-autolink-headings": "^2.0.5",
"rehype-highlight": "^3.0.0",
"rehype-raw": "^4.0.1",
"rehype-slug": "^2.0.3",
"rehype-stringify": "^6.0.0",
"remark-gemoji-to-emoji": "^1.1.0",
"remark-parse": "^7.0.0",
"remark-rehype": "^5.0.0",
"unified": "^8.3.2"
},
"dependencies": {
"extend-shallow": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz",
"integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=",
"requires": {
"is-extendable": "^0.1.0"
}
},
"gray-matter": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/gray-matter/-/gray-matter-3.1.1.tgz",
"integrity": "sha512-nZ1qjLmayEv0/wt3sHig7I0s3/sJO0dkAaKYQ5YAOApUtYEOonXSFdWvL1khvnZMTvov4UufkqlFsilPnejEXA==",
"requires": {
"extend-shallow": "^2.0.1",
"js-yaml": "^3.10.0",
"kind-of": "^5.0.2",
"strip-bom-string": "^1.0.0"
}
},
"kind-of": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-5.1.0.tgz",
"integrity": "sha512-NGEErnH6F2vUuXDh+OlbcKW7/wOcfdRHaZ7VWtqCztfHri/++YKmP51OdWeGPuqCOba6kk2OTe5d02VmTB80Pw=="
}
}
},
"human-signals": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz",
@ -17431,14 +17377,6 @@
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
},
"json-stable-stringify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz",
"integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=",
"requires": {
"jsonify": "~0.0.0"
}
},
"json-stable-stringify-without-jsonify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
@ -17473,11 +17411,6 @@
"graceful-fs": "^4.1.6"
}
},
"jsonify": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
"integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM="
},
"jsprim": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
@ -17909,12 +17842,12 @@
"integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA=="
},
"lowlight": {
"version": "1.16.0",
"resolved": "https://registry.npmjs.org/lowlight/-/lowlight-1.16.0.tgz",
"integrity": "sha512-ECLdzIJvBEjK4ef51sWiGZyz21yx4IEPaF/62DRxLehoOHkWqN3OsLB1GUMfc6Mcf87rR5eW7z6lI9cNEXZDsQ==",
"version": "1.18.0",
"resolved": "https://registry.npmjs.org/lowlight/-/lowlight-1.18.0.tgz",
"integrity": "sha512-Zlc3GqclU71HRw5fTOy00zz5EOlqAdKMYhOFIO8ay4SQEDQgFuhR8JNwDIzAGMLoqTsWxe0elUNmq5o2USRAzw==",
"requires": {
"fault": "^1.0.0",
"highlight.js": "~10.3.0"
"highlight.js": "~10.5.0"
}
},
"lru-cache": {
@ -23102,9 +23035,9 @@
"integrity": "sha512-C4+gOpvmxaSMKuEf9Qc134F1ZuOHVXKRbtEflf4NTtuuJDEIJ9p5PXsalL8SkeRw+qit1Mo+yuvMPAKwWg/1hA=="
},
"trim-trailing-lines": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/trim-trailing-lines/-/trim-trailing-lines-1.1.3.tgz",
"integrity": "sha512-4ku0mmjXifQcTVfYDfR5lpgV7zVqPg6zV9rdZmwOPqq0+Zq19xDqEgagqVbc4pOOShbncuAOIs59R3+3gcF3ZA=="
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/trim-trailing-lines/-/trim-trailing-lines-1.1.4.tgz",
"integrity": "sha512-rjUWSqnfTNrjbB9NQWfPMH/xRK1deHeGsHoVfpxJ++XeYXE0d6B1En37AHfw3jtfTU7dzMzZL2jjpe8Qb5gLIQ=="
},
"trough": {
"version": "1.0.5",
@ -23390,9 +23323,9 @@
}
},
"unist-util-generated": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/unist-util-generated/-/unist-util-generated-1.1.5.tgz",
"integrity": "sha512-1TC+NxQa4N9pNdayCYA1EGUOCAO0Le3fVp7Jzns6lnua/mYgwHo0tz5WUAfrdpNch1RZLHc61VZ1SDgrtNXLSw=="
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/unist-util-generated/-/unist-util-generated-1.1.6.tgz",
"integrity": "sha512-cln2Mm1/CZzN5ttGK7vkoGw+RZ8VcUH6BtGbq98DDtRGquAAOXig1mrBQYelOwMXYS8rK+vZDyyojSjp7JX+Lg=="
},
"unist-util-is": {
"version": "3.0.0",

Просмотреть файл

@ -52,10 +52,10 @@
"hast-util-from-parse5": "^6.0.1",
"hastscript": "^6.0.0",
"helmet": "^3.21.2",
"highlightjs-graphql": "^1.0.2",
"hot-shots": "^8.2.0",
"html-entities": "^1.2.1",
"html-truncate": "^1.2.2",
"hubdown": "^2.6.0",
"imurmurhash": "^0.1.4",
"ioredis": "^4.19.4",
"ioredis-mock": "^5.2.0",
@ -79,7 +79,15 @@
"react": "^17.0.1",
"react-dom": "^17.0.1",
"readline-sync": "^1.4.10",
"rehype-autolink-headings": "^2.0.5",
"rehype-highlight": "^3.1.0",
"rehype-raw": "^4.0.2",
"rehype-slug": "^2.0.3",
"rehype-stringify": "^6.0.1",
"remark-code-extra": "^1.0.1",
"remark-gemoji-to-emoji": "^1.1.0",
"remark-parse": "^7.0.2",
"remark-rehype": "^5.0.0",
"resolve-url-loader": "^3.1.2",
"rimraf": "^3.0.0",
"sass": "^1.26.3",
@ -89,6 +97,7 @@
"slash": "^3.0.0",
"strip-html-comments": "^1.0.0",
"style-loader": "^1.2.1",
"unified": "^8.4.2",
"unist-util-visit": "^2.0.3",
"uuid": "^8.3.0",
"walk-sync": "^1.1.4",