mathpix-markdown-it
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -12,3 +12,3 @@ "use strict"; | ||
MathpixMarkdown.prototype.render = function () { | ||
var _a = this.props, text = _a.text, _b = _a.alignMathBlock, alignMathBlock = _b === void 0 ? 'center' : _b, _c = _a.display, display = _c === void 0 ? 'block' : _c, _d = _a.isCheckFormula, isCheckFormula = _d === void 0 ? false : _d, _e = _a.showTimeLog, showTimeLog = _e === void 0 ? false : _e, _f = _a.isDisableFancy, isDisableFancy = _f === void 0 ? false : _f, _g = _a.htmlTags, htmlTags = _g === void 0 ? false : _g, _h = _a.width, width = _h === void 0 ? 0 : _h, _j = _a.breaks, breaks = _j === void 0 ? true : _j, _k = _a.typographer, typographer = _k === void 0 ? false : _k, _l = _a.linkify, linkify = _l === void 0 ? false : _l, _m = _a.xhtmlOut, xhtmlOut = _m === void 0 ? false : _m, _o = _a.outMath, outMath = _o === void 0 ? {} : _o; | ||
var _a = this.props, text = _a.text, _b = _a.alignMathBlock, alignMathBlock = _b === void 0 ? 'center' : _b, _c = _a.display, display = _c === void 0 ? 'block' : _c, _d = _a.isCheckFormula, isCheckFormula = _d === void 0 ? false : _d, _e = _a.showTimeLog, showTimeLog = _e === void 0 ? false : _e, _f = _a.isDisableFancy, isDisableFancy = _f === void 0 ? false : _f, _g = _a.htmlTags, htmlTags = _g === void 0 ? false : _g, _h = _a.width, width = _h === void 0 ? 0 : _h, _j = _a.breaks, breaks = _j === void 0 ? true : _j, _k = _a.typographer, typographer = _k === void 0 ? false : _k, _l = _a.linkify, linkify = _l === void 0 ? false : _l, _m = _a.xhtmlOut, xhtmlOut = _m === void 0 ? false : _m, _o = _a.outMath, outMath = _o === void 0 ? {} : _o, _p = _a.mathJax, mathJax = _p === void 0 ? {} : _p; | ||
var disableRules = isDisableFancy ? mathpix_markdown_model_1.MathpixMarkdownModel.disableFancyArrayDef : this.props.disableRules; | ||
@@ -18,3 +18,4 @@ mathpix_markdown_model_1.MathpixMarkdownModel.setOptions(disableRules, isCheckFormula, showTimeLog); | ||
React.createElement("div", { id: 'container-ruller' }), | ||
React.createElement("div", { id: 'setText', style: { display: display, justifyContent: 'inherit' }, dangerouslySetInnerHTML: { __html: mathpix_markdown_model_1.MathpixMarkdownModel.convertToHTML(text, { htmlTags: htmlTags, xhtmlOut: xhtmlOut, breaks: breaks, typographer: typographer, linkify: linkify, width: width, outMath: outMath }) } }))); | ||
React.createElement("div", { id: 'setText', style: { display: display, justifyContent: 'inherit' }, dangerouslySetInnerHTML: { __html: mathpix_markdown_model_1.MathpixMarkdownModel.convertToHTML(text, { htmlTags: htmlTags, xhtmlOut: xhtmlOut, breaks: breaks, typographer: typographer, linkify: linkify, width: width, | ||
outMath: outMath, mathJax: mathJax }) } }))); | ||
}; | ||
@@ -21,0 +22,0 @@ return MathpixMarkdown; |
import MathpixLoader from './components/mathpix-loader'; | ||
import MathpixMarkdown from './components/mathpix-markdown'; | ||
import { MathpixMarkdownModel, TMarkdownItOptions, optionsMathpixMarkdown, TOutputMath } from './mathpix-markdown-model'; | ||
export { MathpixLoader, MathpixMarkdown, MathpixMarkdownModel, TMarkdownItOptions, optionsMathpixMarkdown, TOutputMath }; | ||
import { MathpixMarkdownModel, TMarkdownItOptions, optionsMathpixMarkdown, TOutputMath, TOutputMathJax } from './mathpix-markdown-model'; | ||
export { MathpixLoader, MathpixMarkdown, MathpixMarkdownModel, TMarkdownItOptions, optionsMathpixMarkdown, TOutputMath, TOutputMathJax }; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var mdInit = function (options) { | ||
var _a = options.htmlTags, htmlTags = _a === void 0 ? false : _a, _b = options.xhtmlOut, xhtmlOut = _b === void 0 ? false : _b, _c = options.width, width = _c === void 0 ? 1200 : _c, _d = options.breaks, breaks = _d === void 0 ? true : _d, _e = options.typographer, typographer = _e === void 0 ? true : _e, _f = options.linkify, linkify = _f === void 0 ? true : _f, _g = options.outMath, outMath = _g === void 0 ? {} : _g; | ||
var _a = options.htmlTags, htmlTags = _a === void 0 ? false : _a, _b = options.xhtmlOut, xhtmlOut = _b === void 0 ? false : _b, _c = options.width, width = _c === void 0 ? 1200 : _c, _d = options.breaks, breaks = _d === void 0 ? true : _d, _e = options.typographer, typographer = _e === void 0 ? true : _e, _f = options.linkify, linkify = _f === void 0 ? true : _f, _g = options.outMath, outMath = _g === void 0 ? {} : _g, _h = options.mathJax, mathJax = _h === void 0 ? {} : _h; | ||
return require("markdown-it")({ | ||
@@ -21,3 +21,3 @@ html: htmlTags, | ||
// .use(separateForBlockPlugin) | ||
.use(mdPluginConfigured_1.ConfiguredMathJaxPlugin({ width: width, outMath: outMath })) | ||
.use(mdPluginConfigured_1.ConfiguredMathJaxPlugin({ width: width, outMath: outMath, mathJax: mathJax })) | ||
.use(mdPluginConfigured_1.CustomTagPlugin()) | ||
@@ -24,0 +24,0 @@ .use(mdPluginConfigured_1.HighlightPlugin, { auto: false }) |
@@ -71,2 +71,25 @@ "use strict"; | ||
} | ||
if (match[0] === "$" || match[0] === "$$") { | ||
var beforeEndMarker = str.charCodeAt(endMarkerPos - 1); | ||
if (beforeEndMarker === 0x5c /* \ */ || | ||
(match.index > 0 && str.charCodeAt(match.index - 1) === 0x5c /* \ */)) { | ||
return str; | ||
} | ||
if (match[0] === "$") { | ||
var afterStartMarker = str.charCodeAt(match.index + 1); | ||
if (beforeEndMarker === 0x20 /* space */ || | ||
beforeEndMarker === 0x09 /* \t */ || | ||
beforeEndMarker === 0x0a /* \n */ || | ||
afterStartMarker === 0x20 /* space */ || | ||
afterStartMarker === 0x09 /* \t */ || | ||
afterStartMarker === 0x0a /* \n */) { | ||
return str; | ||
} | ||
} | ||
// Skip if closing $ is succeeded by a digit (eg $5 $10 ...) | ||
var suffix = str.charCodeAt(endMarkerPos + 1); | ||
if (suffix >= 0x30 && suffix < 0x3a) { | ||
return str; | ||
} | ||
} | ||
var nextPos = endMarkerPos + endMarker.length; | ||
@@ -73,0 +96,0 @@ var content = str.slice(match.index, nextPos); |
@@ -429,3 +429,4 @@ "use strict"; | ||
else { | ||
mathEquation = mathjax_1.MathJax.Typeset(math, { display: isBlock, metric: { cwidth: cwidth }, outMath: options.outMath }); | ||
mathEquation = mathjax_1.MathJax.Typeset(math, { display: isBlock, metric: { cwidth: cwidth }, | ||
outMath: options.outMath, mathJax: options.mathJax }); | ||
} | ||
@@ -432,0 +433,0 @@ } |
@@ -120,4 +120,8 @@ "use strict"; | ||
if (options === void 0) { options = {}; } | ||
var _a = options.display, display = _a === void 0 ? true : _a, _b = options.metric, metric = _b === void 0 ? {} : _b, _c = options.outMath, outMath = _c === void 0 ? {} : _c; | ||
var _d = metric.em, em = _d === void 0 ? 16 : _d, _e = metric.ex, ex = _e === void 0 ? 8 : _e, _f = metric.cwidth, cwidth = _f === void 0 ? 1200 : _f, _g = metric.lwidth, lwidth = _g === void 0 ? 100000 : _g, _h = metric.scale, scale = _h === void 0 ? 1 : _h; | ||
var _a = options.display, display = _a === void 0 ? true : _a, _b = options.metric, metric = _b === void 0 ? {} : _b, _c = options.outMath, outMath = _c === void 0 ? {} : _c, _d = options.mathJax, mathJax = _d === void 0 ? {} : _d; | ||
var _e = metric.em, em = _e === void 0 ? 16 : _e, _f = metric.ex, ex = _f === void 0 ? 8 : _f, _g = metric.cwidth, cwidth = _g === void 0 ? 1200 : _g, _h = metric.lwidth, lwidth = _h === void 0 ? 100000 : _h, _j = metric.scale, scale = _j === void 0 ? 1 : _j; | ||
var _k = mathJax.mtextInheritFont, mtextInheritFont = _k === void 0 ? false : _k; | ||
if (mtextInheritFont) { | ||
docTeX.outputJax.options.mtextInheritFont = true; | ||
} | ||
var node = docTeX.convert(string, { display: display, em: em, ex: ex, containerWidth: cwidth, lineWidth: lwidth, scale: scale }); | ||
@@ -124,0 +128,0 @@ var outputJax = docTeX.outputJax; |
@@ -26,3 +26,2 @@ declare const MathJaxConfig: { | ||
fontCache: string; | ||
mtextInheritFont: boolean; | ||
}; | ||
@@ -29,0 +28,0 @@ CHTML: any; |
@@ -38,3 +38,2 @@ "use strict"; | ||
fontCache: 'none', | ||
mtextInheritFont: true | ||
}, | ||
@@ -41,0 +40,0 @@ CHTML: null |
@@ -20,2 +20,3 @@ import * as CSS from 'csstype'; | ||
outMath?: TOutputMath; | ||
mathJax?: TOutputMathJax; | ||
} | ||
@@ -31,2 +32,3 @@ export declare type TMarkdownItOptions = { | ||
outMath?: TOutputMath; | ||
mathJax?: TOutputMathJax; | ||
}; | ||
@@ -45,2 +47,5 @@ export declare type TOutputMath = { | ||
}; | ||
export declare type TOutputMathJax = { | ||
mtextInheritFont?: boolean; | ||
}; | ||
declare class MathpixMarkdown_Model { | ||
@@ -47,0 +52,0 @@ disableFancyArrayDef: string[]; |
@@ -266,3 +266,3 @@ "use strict"; | ||
this.render = function (text, options) { | ||
var _a = options || {}, _b = _a.alignMathBlock, alignMathBlock = _b === void 0 ? 'center' : _b, _c = _a.display, display = _c === void 0 ? 'block' : _c, _d = _a.isCheckFormula, isCheckFormula = _d === void 0 ? false : _d, _e = _a.showTimeLog, showTimeLog = _e === void 0 ? false : _e, _f = _a.isDisableFancy, isDisableFancy = _f === void 0 ? false : _f, _g = _a.fontSize, fontSize = _g === void 0 ? null : _g, _h = _a.padding, padding = _h === void 0 ? null : _h, _j = _a.htmlTags, htmlTags = _j === void 0 ? false : _j, _k = _a.width, width = _k === void 0 ? 0 : _k, _l = _a.showToc, showToc = _l === void 0 ? false : _l, _m = _a.overflowY, overflowY = _m === void 0 ? 'unset' : _m, _o = _a.breaks, breaks = _o === void 0 ? true : _o, _p = _a.typographer, typographer = _p === void 0 ? true : _p, _q = _a.linkify, linkify = _q === void 0 ? true : _q, _r = _a.xhtmlOut, xhtmlOut = _r === void 0 ? false : _r, _s = _a.outMath, outMath = _s === void 0 ? {} : _s; | ||
var _a = options || {}, _b = _a.alignMathBlock, alignMathBlock = _b === void 0 ? 'center' : _b, _c = _a.display, display = _c === void 0 ? 'block' : _c, _d = _a.isCheckFormula, isCheckFormula = _d === void 0 ? false : _d, _e = _a.showTimeLog, showTimeLog = _e === void 0 ? false : _e, _f = _a.isDisableFancy, isDisableFancy = _f === void 0 ? false : _f, _g = _a.fontSize, fontSize = _g === void 0 ? null : _g, _h = _a.padding, padding = _h === void 0 ? null : _h, _j = _a.htmlTags, htmlTags = _j === void 0 ? false : _j, _k = _a.width, width = _k === void 0 ? 0 : _k, _l = _a.showToc, showToc = _l === void 0 ? false : _l, _m = _a.overflowY, overflowY = _m === void 0 ? 'unset' : _m, _o = _a.breaks, breaks = _o === void 0 ? true : _o, _p = _a.typographer, typographer = _p === void 0 ? true : _p, _q = _a.linkify, linkify = _q === void 0 ? true : _q, _r = _a.xhtmlOut, xhtmlOut = _r === void 0 ? false : _r, _s = _a.outMath, outMath = _s === void 0 ? {} : _s, _t = _a.mathJax, mathJax = _t === void 0 ? {} : _t; | ||
var disableRules = isDisableFancy ? _this.disableFancyArrayDef : options ? options.disableRules || [] : []; | ||
@@ -275,3 +275,4 @@ if (!showToc) { | ||
_this.setOptions(disableRules, isCheckFormula, showTimeLog); | ||
return ("<div id='preview' style='justify-content:" + alignMathBlock + ";overflow-y:" + overflowY + ";will-change:transform;'>\n <div id='container-ruller'></div>\n <div id='setText' style='display: " + display + "; justify-content: inherit;" + styleFontSize + stylePadding + "' >\n " + _this.convertToHTML(text, { htmlTags: htmlTags, xhtmlOut: xhtmlOut, breaks: breaks, typographer: typographer, linkify: linkify, width: width, outMath: outMath }) + "\n </div>\n </div>"); | ||
return ("<div id='preview' style='justify-content:" + alignMathBlock + ";overflow-y:" + overflowY + ";will-change:transform;'>\n <div id='container-ruller'></div>\n <div id='setText' style='display: " + display + "; justify-content: inherit;" + styleFontSize + stylePadding + "' >\n " + _this.convertToHTML(text, { htmlTags: htmlTags, xhtmlOut: xhtmlOut, breaks: breaks, typographer: typographer, linkify: linkify, width: width, | ||
outMath: outMath, mathJax: mathJax }) + "\n </div>\n </div>"); | ||
}; | ||
@@ -278,0 +279,0 @@ } |
{ | ||
"name": "mathpix-markdown-it", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript. It relies on the following open source libraries: MathJax v3 (to render math with SVGs), markdown-it (for standard Markdown parsing)", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -163,9 +163,9 @@ # mathpix-markdown-it | ||
const options = { | ||
outMath: { | ||
outMath: { //You can set which formats should be included into html result | ||
include_mathml: true, | ||
include_asciimath: true, | ||
include_latex: true, | ||
include_svg: true, | ||
include_svg: true, // sets in default | ||
include_tsv: true, | ||
include_table_html: true, | ||
include_table_html: true, // sets in default | ||
} | ||
@@ -245,3 +245,4 @@ }; | ||
}; | ||
const html = MathpixMarkdownModel.markdownToHTML(`$x^x$`, options); | ||
const latex = `$x^x$`; | ||
const html = MathpixMarkdownModel.markdownToHTML(latex, options); | ||
const parsed = MathpixMarkdownModel.parseMarkdownByHTML(html, false); | ||
@@ -283,3 +284,8 @@ ``` | ||
}; | ||
const html = MathpixMarkdownModel.markdownToHTML(`\\begin{tabular}{ c c } 1 & 2\\\\ 3 & 4\\\\ \\end{tabular}`, options); | ||
const latex = `\\begin{tabular}{ l c r } | ||
1 & 2 & 3 \\\\ | ||
4 & 5 & 6 \\\\ | ||
7 & 8 & 9 \\\\ | ||
\\end{tabular}`; | ||
const html = MathpixMarkdownModel.markdownToHTML(latex, options); | ||
const parsed = MathpixMarkdownModel.parseMarkdownByHTML(html, false); | ||
@@ -290,4 +296,5 @@ ``` | ||
<div class="table_tabular " style="text-align: center"> | ||
<tsv style="display: none">1 2 | ||
3 4</tsv> | ||
<tsv style="display: none">1 2 3 | ||
4 5 6 | ||
7 8 9</tsv> | ||
</div> | ||
@@ -302,3 +309,3 @@ | ||
type: 'tsv', | ||
value: '1\t2\n3\t4' | ||
value: '1\t2\t3\n4\t5\t6\n7\t8\t9' | ||
} | ||
@@ -316,7 +323,2 @@ ] | ||
```js | ||
const latex = `\begin{tabular}{ l c r } | ||
1 & {$x^1$} & 3 \\ | ||
4 & {$y^1$} & 6 \\ | ||
7 & {$z^1$} & 9 \\ | ||
\end{tabular}`; | ||
const options = { | ||
@@ -332,2 +334,7 @@ outMath: { | ||
}; | ||
const latex = `\\begin{tabular}{ l c r } | ||
1 & {$x^1$} & 3 \\\\ | ||
4 & {$y^1$} & 6 \\\\ | ||
7 & {$z^1$} & 9 \\\\ | ||
\\end{tabular}`; | ||
const html = MathpixMarkdownModel.markdownToHTML(latex, options); | ||
@@ -341,3 +348,3 @@ const parsed = MathpixMarkdownModel.parseMarkdownByHTML(html); | ||
{ | ||
type: 'thml', | ||
type: 'html', | ||
value: '<table>..</table>' | ||
@@ -367,7 +374,2 @@ }, | ||
```js | ||
const latex = `\begin{tabular}{ l c r } | ||
1 & {$x^1$} & 3 \\ | ||
4 & {$y^1$} & 6 \\ | ||
7 & {$z^1$} & 9 \\ | ||
\end{tabular}`; | ||
const options = { | ||
@@ -383,2 +385,7 @@ outMath: { | ||
}; | ||
const latex = `\\begin{tabular}{ l c r } | ||
1 & {$x^1$} & 3 \\\\ | ||
4 & {$y^1$} & 6 \\\\ | ||
7 & {$z^1$} & 9 \\\\ | ||
\\end{tabular}`; | ||
const html = MathpixMarkdownModel.markdownToHTML(latex, options); | ||
@@ -408,2 +415,3 @@ const parsed = MathpixMarkdownModel.parseMarkdownByHTML(html, false); | ||
#### [Example of mathpix-markdown-it usage in the node application](https://github.com/Mathpix/mathpix-markdown-it/tree/master/examples/mathpix-markdown-it-node-examples) | ||
#### [Example of Latex to mathml/asciimath/tsv conversion in the node application](https://github.com/Mathpix/mathpix-markdown-it/tree/master/examples/mathpix-markdown-it-node-examples#example-of-latex-to-mathmlasciimathtsv-conversion) | ||
@@ -504,2 +512,3 @@ ```js | ||
| `outMath` | [TOutputMath](https://github.com/Mathpix/mathpix-markdown-it#toutputmath);*`{}`* | Sets options to output html | | ||
| `mathJax` | [TOutputMathJax](https://github.com/Mathpix/mathpix-markdown-it#toutputmathjax);*`{}`* | Sets options to output MathJax | | ||
@@ -537,2 +546,3 @@ | ||
| `outMath` | [TOutputMath](https://github.com/Mathpix/mathpix-markdown-it#toutputmath);*`{}`* | Sets options to output html | | ||
| `mathJax` | [TOutputMathJax](https://github.com/Mathpix/mathpix-markdown-it#toutputmathjax);*`{}`* | Sets options to output MathJax | | ||
@@ -556,2 +566,3 @@ ### optionsMathpixMarkdown | ||
| `outMath` | [TOutputMath](https://github.com/Mathpix/mathpix-markdown-it#toutputmath);*`{}`* | Sets options to output html | | ||
| `mathJax` | [TOutputMathJax](https://github.com/Mathpix/mathpix-markdown-it#toutputmathjax);*`{}`* | Sets options to output MathJax | | ||
@@ -572,3 +583,8 @@ | ||
### TOutputMathJax | ||
| | type *`default`* | description | | ||
|----------------------|------------------------------|--------------------------------------------------------------------------------------------------------------------| | ||
| `mtextInheritFont` | boolean *`false`* | true to make mtext elements use surrounding font | | ||
# Development | ||
@@ -575,0 +591,0 @@ |
@@ -80,3 +80,23 @@ //Require the dev-dependencies | ||
describe('Default Options. \n Latex => ' + test.latex, () => { | ||
const html = MM.render(test.latex); | ||
const data = MM.parseMarkdownByHTML(html, false); | ||
it('Should be parser.length = 1', function(done) { | ||
data.should.have.length(1); | ||
done(); | ||
}); | ||
it('Should be have type: "html"', function(done) { | ||
data[0].should.have.property('type', 'html'); | ||
if (test.html_not_tsv) { | ||
data[0].should.have.property('value', test.html_not_tsv); | ||
} else { | ||
if (test.html) { | ||
data[0].should.have.property('value', test.html); | ||
} | ||
} | ||
done(); | ||
}); | ||
}); | ||
options.outMath.include_tsv = true; | ||
@@ -83,0 +103,0 @@ options.outMath.include_table_html = false; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4635594
10546
600