1
0
mirror of synced 2025-12-20 02:19:14 -05:00
Files
docs/lib/render-content/create-processor.js
Jason Etcovitch 989006bab5 Move the rewriteLocalLinks behavior to an AST pipeline plugin (#17550)
* Write our plugin

* Include it

* Move the RegEx

* Don't rewriteLocalLinks with cheerio anymore

* Process after HTML ast is generated

* Use the same logic as before, just to see if it'll pass

* Don't require languageCode/version

* Only work on local links

* Needs an href

* Only update href if there's a new one to use

* Check for node.properties

* Some links are just mean
2021-01-29 15:36:17 +00:00

28 lines
1.1 KiB
JavaScript

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')
const rewriteLocalLinks = require('./plugins/rewrite-local-links')
module.exports = function createProcessor (context) {
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(rewriteLocalLinks, { languageCode: context.currentLanguage, version: context.currentVersion })
.use(html)
}