* 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
28 lines
1.1 KiB
JavaScript
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)
|
|
}
|