Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CHTML Output Processor #43

Merged
merged 9 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions packages/rehype-mathjax/browser-renderer.js

This file was deleted.

36 changes: 36 additions & 0 deletions packages/rehype-mathjax/chtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const visit = require('unist-util-visit')
const toText = require('hast-util-to-text')
const CHTMLRenderer = require('./renderer/chtml')

module.exports = rehypeMathJaxCHTML

function rehypeMathJaxCHTML(options = {}) {
return transformMath

function transformMath(tree) {
const renderer = new CHTMLRenderer(options)

let found = false

visit(tree, 'element', onelement)

if (found) {
tree.children.push(renderer.styleSheet)
}

function onelement(element) {
const classes = element.properties.className || []
const inline = classes.includes('math-inline')
const display = classes.includes('math-display')

if (!inline && !display) {
return
}

found = true
element.children = [renderer.render(toText(element), {display: display})]

return visit.SKIP
}
}
}
36 changes: 2 additions & 34 deletions packages/rehype-mathjax/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,2 @@
const visit = require('unist-util-visit')
const toText = require('hast-util-to-text')
const renderer = require('./renderer')

module.exports = rehypeMathJax

function rehypeMathJax() {
return transformMath
}

function transformMath(tree) {
let found = false

visit(tree, 'element', onelement)

if (found) {
tree.children.push(renderer.styleSheet())
}

function onelement(element) {
const classes = element.properties.className || []
const inline = classes.includes('math-inline')
const display = classes.includes('math-display')

if (!inline && !display) {
return
}

found = true
element.children = [renderer.render(toText(element), {display: display})]

return visit.SKIP
}
}
exports.rehypeMathJaxCHTML = require('./chtml')
exports.rehypeMathJaxSVG = require('./svg')
2 changes: 1 addition & 1 deletion packages/rehype-mathjax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"url": "https://opencollective.com/unified"
},
"browser": {
"./renderer": "./browser-renderer"
"./renderer/node": "./renderer/browser"
},
"author": "TANIGUCHI Masaya <taniguchi.masaya@yandex.com> (https://docs.casa)",
"files": [
Expand Down
Loading