markdown-it-mathjax3
Advanced tools
Comparing version 3.0.0-0 to 3.0.0
56
index.js
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
/* Process inline math */ | ||
@@ -10,17 +9,20 @@ /* | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
const mathjax_1 = require("mathjax-full/js/mathjax"); | ||
const tex_1 = require("mathjax-full/js/input/tex"); | ||
const svg_1 = require("mathjax-full/js/output/svg"); | ||
const liteAdaptor_1 = require("mathjax-full/js/adaptors/liteAdaptor"); | ||
const html_1 = require("mathjax-full/js/handlers/html"); | ||
const AllPackages_1 = require("mathjax-full/js/input/tex/AllPackages"); | ||
const juice_1 = __importDefault(require("juice")); | ||
const adaptor = (0, liteAdaptor_1.liteAdaptor)(); | ||
(0, html_1.RegisterHTMLHandler)(adaptor); | ||
const tex = new tex_1.TeX({ packages: AllPackages_1.AllPackages }); | ||
const svg = new svg_1.SVG({ fontCache: "none" }); | ||
const mathDocument = mathjax_1.mathjax.document("", { InputJax: tex, OutputJax: svg }); | ||
import { mathjax } from "mathjax-full/js/mathjax.js"; | ||
import { TeX } from "mathjax-full/js/input/tex.js"; | ||
import { SVG } from "mathjax-full/js/output/svg.js"; | ||
import { liteAdaptor } from "mathjax-full/js/adaptors/liteAdaptor.js"; | ||
import { RegisterHTMLHandler } from "mathjax-full/js/handlers/html.js"; | ||
import { AllPackages } from "mathjax-full/js/input/tex/AllPackages.js"; | ||
import { rehype } from "rehype"; | ||
import inlineCss from "rehype-inline-css"; | ||
function renderMath(content, options) { | ||
const adaptor = liteAdaptor(); | ||
RegisterHTMLHandler(adaptor); | ||
const tex = new TeX({ packages: AllPackages }); | ||
const svg = new SVG({ fontCache: "none" }); | ||
const mathDocument = mathjax.document(content, { InputJax: tex, OutputJax: svg }); | ||
const html = adaptor.outerHTML(mathDocument.convert(content, options)); | ||
const stylesheet = adaptor.outerHTML(svg.styleSheet(mathDocument)); | ||
return rehype().use(inlineCss).processSync(html + stylesheet).toString(); | ||
} | ||
// Test if potential opening or closing delimieter | ||
@@ -157,3 +159,3 @@ // Assumes that there is a "$" at state.src[pos] | ||
} | ||
module.exports = function (md, options) { | ||
export default function (md, options) { | ||
// Default options | ||
@@ -168,21 +170,9 @@ options = options || {}; | ||
options.display = false; | ||
return adaptor.outerHTML(mathDocument.convert(tokens[idx].content, options)); | ||
return renderMath(tokens[idx].content, options); | ||
}; | ||
md.renderer.rules.math_block = function (tokens, idx) { | ||
options.display = true; | ||
return adaptor.outerHTML(mathDocument.convert(tokens[idx].content, options)); | ||
return renderMath(tokens[idx].content, options); | ||
}; | ||
const render = md.renderer.render.bind(md.renderer); | ||
md.renderer.render = function (tokens, options, env) { | ||
const result = render(tokens, options, env); | ||
const noMath = tokens.every(function isNotMath(token) { | ||
return (token.tag !== "math" && | ||
(Array.isArray(token.children) ? token.children.every(isNotMath) : true)); | ||
}); | ||
if (!noMath) { | ||
const styleSheet = adaptor.textContent(svg.styleSheet(mathDocument)); | ||
return (0, juice_1.default)(`${result}<style>${styleSheet}</style>`); | ||
} | ||
return result; | ||
}; | ||
}; | ||
} | ||
; |
{ | ||
"name": "markdown-it-mathjax3", | ||
"version": "3.0.0-0", | ||
"version": "3.0.0", | ||
"type": "module", | ||
"description": "Fast math support for markdown-it with MathJax", | ||
@@ -21,4 +22,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"juice": "^8.0.0", | ||
"mathjax-full": "^3.2.0" | ||
"mathjax-full": "^3.2.0", | ||
"rehype": "^12.0.0", | ||
"rehype-inline-css": "^0.5.1" | ||
}, | ||
@@ -25,0 +27,0 @@ "devDependencies": { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
Yes
9997
3
174
+ Addedrehype@^12.0.0
+ Addedrehype-inline-css@^0.5.1
+ Added@types/hast@2.3.10(transitive)
+ Added@types/parse5@6.0.3(transitive)
+ Added@types/unist@2.0.11(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbail@2.0.2(transitive)
+ Addedbcp-47-match@2.0.3(transitive)
+ Addedccount@2.0.1(transitive)
+ Addedcharacter-entities-html4@2.1.0(transitive)
+ Addedcharacter-entities-legacy@3.0.0(transitive)
+ Addedcomma-separated-tokens@2.0.3(transitive)
+ Addedcss@3.0.0(transitive)
+ Addedcss-selector-parser@1.4.1(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddirection@2.0.1(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedhast-util-from-parse5@7.1.2(transitive)
+ Addedhast-util-has-property@2.0.1(transitive)
+ Addedhast-util-parse-selector@3.1.1(transitive)
+ Addedhast-util-raw@7.2.3(transitive)
+ Addedhast-util-select@5.0.5(transitive)
+ Addedhast-util-to-html@8.0.4(transitive)
+ Addedhast-util-to-parse5@7.1.0(transitive)
+ Addedhast-util-to-string@2.0.0(transitive)
+ Addedhast-util-whitespace@2.0.1(transitive)
+ Addedhastscript@7.2.0(transitive)
+ Addedhtml-void-elements@2.0.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedis-plain-obj@4.1.0(transitive)
+ Addednot@0.1.0(transitive)
+ Addedproperty-information@6.5.0(transitive)
+ Addedrehype@12.0.1(transitive)
+ Addedrehype-inline-css@0.5.1(transitive)
+ Addedrehype-parse@8.0.5(transitive)
+ Addedrehype-stringify@9.0.4(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsource-map-resolve@0.6.0(transitive)
+ Addedspace-separated-tokens@2.0.2(transitive)
+ Addedstringify-entities@4.0.4(transitive)
+ Addedtrough@2.2.0(transitive)
+ Addedunified@10.1.2(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-position@4.0.4(transitive)
+ Addedunist-util-remove@3.1.1(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedunist-util-visit@4.1.2(transitive)
+ Addedunist-util-visit-parents@5.1.3(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-location@4.1.0(transitive)
+ Addedvfile-message@3.1.4(transitive)
+ Addedweb-namespaces@2.0.1(transitive)
+ Addedzwitch@2.0.4(transitive)
- Removedjuice@^8.0.0
- Removedansi-colors@4.1.3(transitive)
- Removedcheerio@1.0.0-rc.10(transitive)
- Removedcheerio-select@1.6.0(transitive)
- Removedcommander@6.2.1(transitive)
- Removedcss-select@4.3.0(transitive)
- Removedcss-what@6.1.0(transitive)
- Removeddom-serializer@1.4.1(transitive)
- Removeddomelementtype@2.3.0(transitive)
- Removeddomhandler@3.3.04.3.1(transitive)
- Removeddomutils@2.8.0(transitive)
- Removedentities@2.2.0(transitive)
- Removedescape-goat@3.0.0(transitive)
- Removedhtmlparser2@5.0.16.1.0(transitive)
- Removedjuice@8.1.0(transitive)
- Removedmensch@0.3.4(transitive)
- Removedmime@2.6.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedparse5-htmlparser2-tree-adapter@6.0.1(transitive)
- Removedslick@1.12.2(transitive)
- Removedtr46@0.0.3(transitive)
- Removedtslib@2.8.1(transitive)
- Removedvalid-data-url@3.0.1(transitive)
- Removedweb-resource-inliner@6.0.1(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)