From cc5973ab94e521389ab5448c16cd9c78bb816c36 Mon Sep 17 00:00:00 2001 From: Menci Date: Mon, 25 Mar 2019 12:25:39 +0800 Subject: [PATCH] Add loose mode to allow whitespace immediately after inline opening, fix #21 --- README.md | 1 + dist/markdown-it-math.js | 11 ++++++----- dist/markdown-it-math.min.js | 2 +- index.js | 11 ++++++----- test/options.js | 11 +++++++++++ 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fc67f36..0f16b81 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ var options = { blockOpen: '$$$', blockClose: '$$$', renderingOptions: {}, + loose: false, // true to allow whitespace immediately after inline opening, see #21 inlineRenderer: require('ascii2mathml')(this.rendererOptions), blockRenderer: require('ascii2mathml')(Object.assign({ display: 'block' }, this.renderingOptions)) diff --git a/dist/markdown-it-math.js b/dist/markdown-it-math.js index 0ba7e92..7daa082 100644 --- a/dist/markdown-it-math.js +++ b/dist/markdown-it-math.js @@ -1515,7 +1515,7 @@ function scanDelims(state, start, delimLength) { } -function makeMath_inline(open, close) { +function makeMath_inline(open, close, loose) { return function math_inline(state, silent) { var startCount, found, @@ -1532,7 +1532,7 @@ function makeMath_inline(open, close) { res = scanDelims(state, start, openDelim.length); startCount = res.delims; - if (!res.can_open) { + if (!(res.can_open || loose)) { state.pos += startCount; // Earlier we checked !silent, but this implementation does not need it state.pending += state.src.slice(start, state.pos); @@ -1545,7 +1545,7 @@ function makeMath_inline(open, close) { closeDelim = state.src.slice(state.pos, state.pos + close.length); if (closeDelim === close) { res = scanDelims(state, state.pos, close.length); - if (res.can_close) { + if (res.can_close || loose) { found = true; break; } @@ -1697,7 +1697,8 @@ module.exports = function math_plugin(md, options) { var inlineOpen = options.inlineOpen || '$$', inlineClose = options.inlineClose || '$$', blockOpen = options.blockOpen || '$$$', - blockClose = options.blockClose || '$$$'; + blockClose = options.blockClose || '$$$', + loose = !!options.loose; var inlineRenderer = options.inlineRenderer ? function(tokens, idx) { return options.inlineRenderer(tokens[idx].content, tokens[idx]); @@ -1710,7 +1711,7 @@ module.exports = function math_plugin(md, options) { makeMathRenderer(Object.assign({ display: 'block' }, options.renderingOptions)); - var math_inline = makeMath_inline(inlineOpen, inlineClose); + var math_inline = makeMath_inline(inlineOpen, inlineClose, loose); var math_block = makeMath_block(blockOpen, blockClose); md.inline.ruler.before('escape', 'math_inline', math_inline); diff --git a/dist/markdown-it-math.min.js b/dist/markdown-it-math.min.js index 749d98d..a542b8a 100644 --- a/dist/markdown-it-math.min.js +++ b/dist/markdown-it-math.min.js @@ -1 +1 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).markdownitMath=e()}}(function(){return function a(o,c,s){function l(t,e){if(!c[t]){if(!o[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(u)return u(t,!0);var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}var i=c[t]={exports:{}};o[t][0].call(i.exports,function(e){return l(o[t][1][e]||e)},i,i.exports,a,o,c,s)}return c[t].exports}for(var u="function"==typeof require&&require,e=0;e element");if(t.display&&"inline"!==t.display.toLowerCase())throw new Error("Can't display block without root element.");if(t.dir&&"ltr"!==t.dir.toLowerCase())throw new Error("Can't have right-to-left direction without root element.")}var e,n=(0,o.default)(t),i=t.bare?function(e){return e}:function(e){return"").concat(e,"")};if(t.annotate){var a=n(r.trim(),"");e=i(""+(a===o.default.getlastel(a)?a:"".concat(a,""))+''+r+"")}else e=i(n(r.trim(),""));return t.standalone&&(e=""+r+""+e+""),e}var i=c;r.default=i},{"./lib/parser":4}],3:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.accents=r.fonts=r.groupings=r.operators=r.identifiers=r.numbers=void 0;var n={};r.numbers=n;var i="[0-9\xb2\xb3\xb9\xbc-\xbe\u0660-\u0669\u06f0-\u06f9\u07c0-\u07c9\u0966-\u096f\u09e6-\u09ef\u09f4-\u09f9\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0b72-\u0b77\u0be6-\u0bf2\u0c66-\u0c6f\u0c78-\u0c7e\u0ce6-\u0cef\u0d66-\u0d75\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f33\u1040-\u1049\u1090-\u1099\u1369-\u137c\u16ee-\u16f0\u17e0-\u17e9\u17f0-\u17f9\u1810-\u1819\u1946-\u194f\u19d0-\u19da\u1a80-\u1a89\u1a90-\u1a99\u1b50-\u1b59\u1bb0-\u1bb9\u1c40-\u1c49\u1c50-\u1c59\u2070\u2074-\u2079\u2080-\u2089\u2150-\u2182\u2185-\u218b\u2460-\u249b\u24ea-\u24ff\u2776-\u2793\u2cfd\u3007\u3021-\u3029\u3038-\u303a\u3192-\u3195\u3220-\u3229\u3248-\u324f\u3251-\u325f\u3280-\u3289\u32b1-\u32bf\u96f6\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u5104\u5146\u4eac\u5793\ud855\udf71\u79ed\u7a63\u6e9d\u6f97\u6b63\u8f09\u5272\u5206\u5398\u6bdb\u7cf8\u5ffd\u5fae\u7e4a\u6c99\u5875\u57c3\ua620-\ua629\ua6e6-\ua6ef\ua830-\ua835\ua8d0-\ua8d9\ua900-\ua909\ua9d0-\ua9d9\uaa50-\uaa59\uabf0-\uabf9\uff10-\uff19]",a=new RegExp(i);Object.defineProperties(n,{digitRange:{value:i},digitRE:{value:a},isdigit:{value:function(e){return e.match(a)}}});var o=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh","log","ln","det","dim","lim","mod","gcd","lcm","min","max"],c={Gamma:"\u0393",Delta:"\u0394",Theta:"\u0398",Lambda:"\u039b",Xi:"\u039e",Pi:"\u03a0",Sigma:"\u03a3",Phi:"\u03a6",Psi:"\u03a8",Omega:"\u03a9",alpha:"\u03b1",beta:"\u03b2",gamma:"\u03b3",delta:"\u03b4",epsilon:"\u025b",zeta:"\u03b6",eta:"\u03b7",theta:"\u03b8",iota:"\u03b9",kappa:"\u03ba",lambda:"\u03bb",mu:"\u03bc",nu:"\u03bd",xi:"\u03be",pi:"\u03c0",rho:"\u03c1",sigma:"\u03c3",tau:"\u03c4",upsilon:"\u03c5",phi:"\u03c6",chi:"\u03c7",psi:"\u03c8",omega:"\u03c9",oo:"\u221e","O/":"\u2205",CC:"\u2102",NN:"\u2115",QQ:"\u211a",RR:"\u211d",ZZ:"\u2124"};r.identifiers=c,o.forEach(function(e){c[e]=e}),Object.defineProperty(c,"contains",{value:function(e){return void 0!==c[e]}}),Object.defineProperty(c,"funs",{value:o}),Object.defineProperty(c,"isfun",{value:function(e){return 0<=o.indexOf(e)}});var s={"*":"\xb7","**":"\u2217","***":"\u22c6","//":"/","|":"|",":":":","'":"\u2032","''":"\u2033","'''":"\u2034","''''":"\u2057",xx:"\xd7","-:":"\xf7","|><":"\u22c9","><|":"\u22ca","|><|":"\u22c8","@":"\u2218","o+":"\u2295",ox:"\u2297","o.":"\u2299","!":"!",sum:"\u2211",prod:"\u220f","^^":"\u2227","^^^":"\u22c0",vv:"\u2228",vvv:"\u22c1",nn:"\u2229",nnn:"\u22c2",uu:"\u222a",uuu:"\u22c3",int:"\u222b",oint:"\u222e",dint:"\u222c","+-":"\xb1",del:"\u2202",grad:"\u2207",aleph:"\u2135","/_":"\u2220",diamond:"\u22c4",square:"\u25a1","|__":"\u230a","__|":"\u230b","|~":"\u2308","~|":"\u2309","=":"=","!=":"\u2260","<":"<",">":">","<=":"\u2264",">=":"\u2265","-<":"\u227a","-<=":"\u2aaf",">-":"\u227b",">-=":"\u2ab0",in:"\u2208","!in":"\u2209",sub:"\u2282",sup:"\u2283",sube:"\u2286",supe:"\u2287","-=":"\u2261","==":"\u2261","~=":"\u2245","~~":"\u2248",prop:"\u221d","<-":"\u2190","->":"\u2192","=>":"\u21d2","<=>":"\u21d4","|->":"\u21a6",">->":"\u21a3","->>":"\u21a0",">->>":"\u2916",uarr:"\u2191",darr:"\u2193",larr:"\u2190",rarr:"\u2192",harr:"\u2194",lArr:"\u21d0",rArr:"\u21d2",hArr:"\u21d4",iff:"\u21d4",",":",",":.":"\u2234","...":"\u2026",cdots:"\u22ef",ddots:"\u22f1",vdots:"\u22ee",if:"if",otherwise:"otherwise",and:"and",or:"or",not:"\xac",AA:"\u2200",EE:"\u2203","_|_":"\u22a5",TT:"\u22a4","|--":"\u22a2","|==":"\u22a8"};r.operators=s,Object.defineProperty(s,"contains",{value:function(e){return void 0!==s[e]}}),Object.defineProperty(s,"get",{value:function(e){return s[e]||e}}),Object.defineProperty(s,"regexp",{value:new RegExp("("+Object.keys(s).sort(function(e,t){return t.length-e.length}).map(function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}).join("|")+"|[+-<=>|~\xac\xb1\xd7\xf7\u03d0\u03d1\u03d2\u03d5\u03f0\u03f1\u03f4\u03f5\u03f6\u0606\u0607\u0608\u2016\u2032\u2033\u2034\u2040\u2044\u2052\u2061-\u2064\u207a-\u207e\u208a-\u208e\u2605\u2606\u2660\u2661\u2662\u2663\u266d\u266e\u266f\ufb29\uff61-\uff68\uff0b\uff1c\uff1d\uff1e\uff3c\uff3e\uff5c\uff5e\uffe2\uffe9\uffea\uffeb\uffec\u2200-\u22ff\u2a00-\u2aff\u27c0-\u27e5\u2980-\u2982\u2999-\u29ff\u2301-\u23ff\u25a0-\u25ff\u2b00-\u2bff\u2190-\u21ff\u27f0-\u27ff\u2900-\u297f\u20d0-\u20ef])")});var l={open:{"(:":"\u27e8","{:":""},close:{":)":"\u27e9",":}":""},complex:{abs:{open:"|",close:"|"},floor:{open:"\u230a",close:"\u230b"},ceil:{open:"\u2308",close:"\u2309"},norm:{open:"\u2225",close:"\u2225"}}};r.groupings=l,Object.defineProperty(l.open,"regexp",{value:/([[\u27e6\u27e8\u27ea\u27ec\u27ee\u2983\u2985\u2987\u2989\u298b\u298d\u298f\u2991\u2993\u2995\u2997]|[({]:?)/}),Object.defineProperty(l.close,"regexp",{value:/([\]\u27e7\u27e9\u27eb\u27ed\u27ef\u2984\u2986\u2988\u298a\u298c\u298e\u2990\u2992\u2994\u2996\u2998]|:?[)}])/}),Object.defineProperty(l.open,"get",{value:function(e){var t=l.open[e];return"string"==typeof t?t:e}}),Object.defineProperty(l.close,"get",{value:function(e){var t=l.close[e];return"string"==typeof t?t:e}}),Object.defineProperty(l.complex,"contains",{value:function(e){return 0<=Object.keys(l.complex).indexOf(e)}}),Object.defineProperty(l.complex,"get",{value:function(e){return l.complex[e]}}),Object.freeze(l.open),Object.freeze(l.close),Object.freeze(l.complex);var u={rm:"normal",bf:"bold",it:"italic",bb:"double-struck",cc:"script",tt:"monospace",fr:"fraktur",sf:"sans-serif"};r.fonts=u,Object.defineProperty(u,"get",{value:function(e){return u[e]}}),Object.defineProperty(u,"regexp",{value:new RegExp("("+Object.keys(u).join("|")+")")});var f={hat:{type:"over",accent:"^"},bar:{type:"over",accent:"\u203e"},ul:{type:"under",accent:"_"},vec:{type:"over",accent:"\u2192"},dot:{type:"over",accent:"\u22c5"},ddot:{type:"over",accent:"\u22c5\u22c5"},tilde:{type:"over",accent:"\u02dc"},cancel:{type:"enclose",attrs:{notation:"updiagonalstrike"}}};r.accents=f,Object.defineProperty(f,"contains",{value:function(e){return 0<=Object.keys(f).indexOf(e)}}),Object.defineProperty(f,"get",{value:function(e){return f[e]}}),Object.defineProperty(f,"regexp",{value:new RegExp("("+Object.keys(f).join("|")+")")})},{}],4:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var n,le=(n=e("./syntax"))&&n.__esModule?n:{default:n},ue=e("./lexicon");function fe(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,i=!1,a=void 0;try{for(var o,c=e[Symbol.iterator]();!(n=(o=c.next()).done)&&(r.push(o.value),!t||r.length!==t);n=!0);}catch(e){i=!0,a=e}finally{try{n||null==c.return||c.return()}finally{if(i)throw a}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function pe(i){return function t(r,n){if("object"==typeof r)return function(e){return t(e,r)};if("object"!=typeof n)return"<".concat(i,">").concat(r,"");var e=Object.keys(n).map(function(e){return"".concat(e,'="').concat(n[e],'"')}).join(" ");return"<".concat(i," ").concat(e,">").concat(r,"")}}var me=pe("mi"),de=pe("mn"),he=pe("mo"),ge=pe("mfrac"),ve=pe("msup"),be=pe("msub"),ye=pe("msubsup"),xe=pe("munder"),Oe=pe("mover"),je=pe("munderover"),we=pe("menclose"),ke=pe("mrow"),_e=pe("msqrt"),Se=pe("mroot"),Pe=pe("mfenced"),Ee=pe("mtable"),Me=pe("mtr"),Re=pe("mtd");function i(te){var e="."===te.decimalMark?"\\.":te.decimalMark,re=new RegExp("^".concat(ue.numbers.digitRange,"+(").concat(e).concat(ue.numbers.digitRange,"+)?")),ne=t(te.colSep),ie=t(te.rowSep),ae=t("\n");function t(c){return function(e){for(var t=[],r=0,n=0,i=0;i');return e(t.trim(),r+c,!0)}return e(t.trim(),r,!0)}var s=fe(ce(t,i),2),l=s[0],u=s[1];if((u&&u.trimLeft().startsWith("/")||u.trimLeft().startsWith("./"))&&!u.trimLeft().match(/^\.?\/\//)){var f=fe(function e(t,r){var n=r.trim().startsWith("./"),i=r.trim().slice(n?2:1);var a,o,c;if(i.startsWith(" ")){var s=i.trim().split(" ");a=oe(s[0]),c=i.trimLeft().slice(s[0].length+1)}else{var l=ce(i),u=fe(l,2);a=u[0],c=u[1]}a=a||ke("");o=ge(We(t)+We(a),n&&{bevelled:!0});if(c&&c.trim().startsWith("/")||c.trim().startsWith("./"))return e(o,c);return[o,c]}(l,u),2);l=f[0],u=f[1]}return e(u,r+l,!1)};function oe(e){if(0===e.trim().length)return"";var t=r(e,"",!1,!0);return t===a(t)?t:ke(t)}function ce(e,t,r){if(!e)return["",""];var n,i,a,o,c,s,l,u,f=e[0],p=e.slice(1),m=f+(p.match(/^[A-Za-z]+/)||"");if(e.startsWith("sqrt")){var d=ce(e.slice(4).trim(),t);n=_e(d[0]?We(d[0]):ke("")),i=d[1]}else if(e.startsWith("root")){var h=ce(e.slice(4).trimLeft(),t),g=h[0]?We(h[0]):ke(""),v=ce(h[1].trimLeft(),t),b=v[0]?We(v[0]):ke("");n=Se(b+g),i=v[1]}else if("\\"===f&&1]*>/,"").replace(/<\/mfenced>$/,"");return(t=n,r=a(t),[t.slice(0,t.lastIndexOf(r)),r])[1]===n?n:ke(n)}function a(e){var t=e.match(/<\/(m[a-z]+)>$/);if(!t){var r=e.match(//);if(r){var n=r.match[0].length;return e.slice(n)}return""}for(var i=t[1],a=e.length-(i.length+3),o=0;0<=a;a-=1){if(e.slice(a).startsWith("<".concat(i))){if(0===o)break;o-=1}e.slice(a-2).startsWith("lim","\u2211","\u220f"];var u={endsInFunc:function(e){return e.match(n)},isgroupStart:i,isgroupable:function(e,t){var r=new RegExp("^[0-9A-Za-z+\\-!]{2,}(\\s|".concat(t.colSep,"|").concat(t.rowSep,")"));return e.match(r)},isvertGroupStart:function(e){if(!e.startsWith("|"))return!1;var t=a(e);return t&&""===t[0]},splitNextGroup:m,splitNextVert:a,splitNextOperator:function(e){var t=new RegExp("^"+p.operators.regexp.source).exec(e)[0];return[p.operators.get(t),e.slice(t.length)]},ismatrixInterior:function(e,t,r){if(!i(e))return!1;var n=m(e)[4];if(!(n.trim().startsWith(t)||n.match(/^\s*\n/)&&i(n.trim())))return!1;for(;n&&n.trim();)if((n=(m(n)||[])[4])&&(n.startsWith(r)||n.match(/^\s*\n/)))return!1;return!0},isfontCommand:function(e){return s(e)||l(e)},splitfont:function(e){var t=s(e)||l(e),r=t&&t[2],n=t&&t[3],i='"'===n?"mtext":"`"===n?"mi":"",a=e.indexOf(n),o=a+1+e.slice(a+1).indexOf(n),c=0'+e[t].content+""}:function(e,t){return''+e[t].content+""}}var r=n(Object.assign({},t));return t&&"block"===t.display?function(e,t){return r(e[t].content)+"\n"}:function(e,t){return r(e[t].content)}}e("./lib/polyfills"),t.exports=function(e,r){var l,u,m,d,t=(r="object"==typeof r?r:{}).inlineOpen||"$$",n=r.inlineClose||"$$",i=r.blockOpen||"$$$",a=r.blockClose||"$$$",o=r.inlineRenderer?function(e,t){return r.inlineRenderer(e[t].content,e[t])}:h(r.renderingOptions),c=r.blockRenderer?function(e,t){return r.blockRenderer(e[t].content,e[t])+"\n"}:h(Object.assign({display:"block"},r.renderingOptions)),s=(l=t,u=n,function(e,t){var r,n,i,a,o=e.posMax,c=e.pos,s=e.src.slice(c,c+l.length);if(s!==l)return!1;if(t)return!1;if(r=(i=p(e,c,s.length)).delims,!i.can_open)return e.pos+=r,e.pending+=e.src.slice(c,e.pos),!0;for(e.pos=c+l.length;e.posp)return!1;if(e.src.slice(f,f+m.length)!==m)return!1;if(f+=m.length,c=e.src.slice(f,p),n)return!0;for(c.trim().slice(-d.length)===d&&(c=c.trim().slice(0,-d.length),u=!0),a=t;!(u||r<=++a||(f=e.bMarks[a]+e.tShift[a])<(p=e.eMarks[a])&&e.tShift[a] element");if(t.display&&"inline"!==t.display.toLowerCase())throw new Error("Can't display block without root element.");if(t.dir&&"ltr"!==t.dir.toLowerCase())throw new Error("Can't have right-to-left direction without root element.")}var e,n=(0,a.default)(t),i=t.bare?function(e){return e}:function(e){return"").concat(e,"")};if(t.annotate){var o=n(r.trim(),"");e=i(""+(o===a.default.getlastel(o)?o:"".concat(o,""))+''+r+"")}else e=i(n(r.trim(),""));return t.standalone&&(e=""+r+""+e+""),e}var i=c;r.default=i},{"./lib/parser":4}],3:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.accents=r.fonts=r.groupings=r.operators=r.identifiers=r.numbers=void 0;var n={};r.numbers=n;var i="[0-9\xb2\xb3\xb9\xbc-\xbe\u0660-\u0669\u06f0-\u06f9\u07c0-\u07c9\u0966-\u096f\u09e6-\u09ef\u09f4-\u09f9\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0b72-\u0b77\u0be6-\u0bf2\u0c66-\u0c6f\u0c78-\u0c7e\u0ce6-\u0cef\u0d66-\u0d75\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f33\u1040-\u1049\u1090-\u1099\u1369-\u137c\u16ee-\u16f0\u17e0-\u17e9\u17f0-\u17f9\u1810-\u1819\u1946-\u194f\u19d0-\u19da\u1a80-\u1a89\u1a90-\u1a99\u1b50-\u1b59\u1bb0-\u1bb9\u1c40-\u1c49\u1c50-\u1c59\u2070\u2074-\u2079\u2080-\u2089\u2150-\u2182\u2185-\u218b\u2460-\u249b\u24ea-\u24ff\u2776-\u2793\u2cfd\u3007\u3021-\u3029\u3038-\u303a\u3192-\u3195\u3220-\u3229\u3248-\u324f\u3251-\u325f\u3280-\u3289\u32b1-\u32bf\u96f6\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07\u5104\u5146\u4eac\u5793\ud855\udf71\u79ed\u7a63\u6e9d\u6f97\u6b63\u8f09\u5272\u5206\u5398\u6bdb\u7cf8\u5ffd\u5fae\u7e4a\u6c99\u5875\u57c3\ua620-\ua629\ua6e6-\ua6ef\ua830-\ua835\ua8d0-\ua8d9\ua900-\ua909\ua9d0-\ua9d9\uaa50-\uaa59\uabf0-\uabf9\uff10-\uff19]",o=new RegExp(i);Object.defineProperties(n,{digitRange:{value:i},digitRE:{value:o},isdigit:{value:function(e){return e.match(o)}}});var a=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh","log","ln","det","dim","lim","mod","gcd","lcm","min","max"],c={Gamma:"\u0393",Delta:"\u0394",Theta:"\u0398",Lambda:"\u039b",Xi:"\u039e",Pi:"\u03a0",Sigma:"\u03a3",Phi:"\u03a6",Psi:"\u03a8",Omega:"\u03a9",alpha:"\u03b1",beta:"\u03b2",gamma:"\u03b3",delta:"\u03b4",epsilon:"\u025b",zeta:"\u03b6",eta:"\u03b7",theta:"\u03b8",iota:"\u03b9",kappa:"\u03ba",lambda:"\u03bb",mu:"\u03bc",nu:"\u03bd",xi:"\u03be",pi:"\u03c0",rho:"\u03c1",sigma:"\u03c3",tau:"\u03c4",upsilon:"\u03c5",phi:"\u03c6",chi:"\u03c7",psi:"\u03c8",omega:"\u03c9",oo:"\u221e","O/":"\u2205",CC:"\u2102",NN:"\u2115",QQ:"\u211a",RR:"\u211d",ZZ:"\u2124"};r.identifiers=c,a.forEach(function(e){c[e]=e}),Object.defineProperty(c,"contains",{value:function(e){return void 0!==c[e]}}),Object.defineProperty(c,"funs",{value:a}),Object.defineProperty(c,"isfun",{value:function(e){return 0<=a.indexOf(e)}});var s={"*":"\xb7","**":"\u2217","***":"\u22c6","//":"/","|":"|",":":":","'":"\u2032","''":"\u2033","'''":"\u2034","''''":"\u2057",xx:"\xd7","-:":"\xf7","|><":"\u22c9","><|":"\u22ca","|><|":"\u22c8","@":"\u2218","o+":"\u2295",ox:"\u2297","o.":"\u2299","!":"!",sum:"\u2211",prod:"\u220f","^^":"\u2227","^^^":"\u22c0",vv:"\u2228",vvv:"\u22c1",nn:"\u2229",nnn:"\u22c2",uu:"\u222a",uuu:"\u22c3",int:"\u222b",oint:"\u222e",dint:"\u222c","+-":"\xb1",del:"\u2202",grad:"\u2207",aleph:"\u2135","/_":"\u2220",diamond:"\u22c4",square:"\u25a1","|__":"\u230a","__|":"\u230b","|~":"\u2308","~|":"\u2309","=":"=","!=":"\u2260","<":"<",">":">","<=":"\u2264",">=":"\u2265","-<":"\u227a","-<=":"\u2aaf",">-":"\u227b",">-=":"\u2ab0",in:"\u2208","!in":"\u2209",sub:"\u2282",sup:"\u2283",sube:"\u2286",supe:"\u2287","-=":"\u2261","==":"\u2261","~=":"\u2245","~~":"\u2248",prop:"\u221d","<-":"\u2190","->":"\u2192","=>":"\u21d2","<=>":"\u21d4","|->":"\u21a6",">->":"\u21a3","->>":"\u21a0",">->>":"\u2916",uarr:"\u2191",darr:"\u2193",larr:"\u2190",rarr:"\u2192",harr:"\u2194",lArr:"\u21d0",rArr:"\u21d2",hArr:"\u21d4",iff:"\u21d4",",":",",":.":"\u2234","...":"\u2026",cdots:"\u22ef",ddots:"\u22f1",vdots:"\u22ee",if:"if",otherwise:"otherwise",and:"and",or:"or",not:"\xac",AA:"\u2200",EE:"\u2203","_|_":"\u22a5",TT:"\u22a4","|--":"\u22a2","|==":"\u22a8"};r.operators=s,Object.defineProperty(s,"contains",{value:function(e){return void 0!==s[e]}}),Object.defineProperty(s,"get",{value:function(e){return s[e]||e}}),Object.defineProperty(s,"regexp",{value:new RegExp("("+Object.keys(s).sort(function(e,t){return t.length-e.length}).map(function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}).join("|")+"|[+-<=>|~\xac\xb1\xd7\xf7\u03d0\u03d1\u03d2\u03d5\u03f0\u03f1\u03f4\u03f5\u03f6\u0606\u0607\u0608\u2016\u2032\u2033\u2034\u2040\u2044\u2052\u2061-\u2064\u207a-\u207e\u208a-\u208e\u2605\u2606\u2660\u2661\u2662\u2663\u266d\u266e\u266f\ufb29\uff61-\uff68\uff0b\uff1c\uff1d\uff1e\uff3c\uff3e\uff5c\uff5e\uffe2\uffe9\uffea\uffeb\uffec\u2200-\u22ff\u2a00-\u2aff\u27c0-\u27e5\u2980-\u2982\u2999-\u29ff\u2301-\u23ff\u25a0-\u25ff\u2b00-\u2bff\u2190-\u21ff\u27f0-\u27ff\u2900-\u297f\u20d0-\u20ef])")});var l={open:{"(:":"\u27e8","{:":""},close:{":)":"\u27e9",":}":""},complex:{abs:{open:"|",close:"|"},floor:{open:"\u230a",close:"\u230b"},ceil:{open:"\u2308",close:"\u2309"},norm:{open:"\u2225",close:"\u2225"}}};r.groupings=l,Object.defineProperty(l.open,"regexp",{value:/([[\u27e6\u27e8\u27ea\u27ec\u27ee\u2983\u2985\u2987\u2989\u298b\u298d\u298f\u2991\u2993\u2995\u2997]|[({]:?)/}),Object.defineProperty(l.close,"regexp",{value:/([\]\u27e7\u27e9\u27eb\u27ed\u27ef\u2984\u2986\u2988\u298a\u298c\u298e\u2990\u2992\u2994\u2996\u2998]|:?[)}])/}),Object.defineProperty(l.open,"get",{value:function(e){var t=l.open[e];return"string"==typeof t?t:e}}),Object.defineProperty(l.close,"get",{value:function(e){var t=l.close[e];return"string"==typeof t?t:e}}),Object.defineProperty(l.complex,"contains",{value:function(e){return 0<=Object.keys(l.complex).indexOf(e)}}),Object.defineProperty(l.complex,"get",{value:function(e){return l.complex[e]}}),Object.freeze(l.open),Object.freeze(l.close),Object.freeze(l.complex);var u={rm:"normal",bf:"bold",it:"italic",bb:"double-struck",cc:"script",tt:"monospace",fr:"fraktur",sf:"sans-serif"};r.fonts=u,Object.defineProperty(u,"get",{value:function(e){return u[e]}}),Object.defineProperty(u,"regexp",{value:new RegExp("("+Object.keys(u).join("|")+")")});var f={hat:{type:"over",accent:"^"},bar:{type:"over",accent:"\u203e"},ul:{type:"under",accent:"_"},vec:{type:"over",accent:"\u2192"},dot:{type:"over",accent:"\u22c5"},ddot:{type:"over",accent:"\u22c5\u22c5"},tilde:{type:"over",accent:"\u02dc"},cancel:{type:"enclose",attrs:{notation:"updiagonalstrike"}}};r.accents=f,Object.defineProperty(f,"contains",{value:function(e){return 0<=Object.keys(f).indexOf(e)}}),Object.defineProperty(f,"get",{value:function(e){return f[e]}}),Object.defineProperty(f,"regexp",{value:new RegExp("("+Object.keys(f).join("|")+")")})},{}],4:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var n,ie=(n=e("./syntax"))&&n.__esModule?n:{default:n},oe=e("./lexicon");function ae(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,i=!1,o=void 0;try{for(var a,c=e[Symbol.iterator]();!(n=(a=c.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){i=!0,o=e}finally{try{n||null==c.return||c.return()}finally{if(i)throw o}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function ce(i){return function t(r,n){if("object"==typeof r)return function(e){return t(e,r)};if("object"!=typeof n)return"<".concat(i,">").concat(r,"");var e=Object.keys(n).map(function(e){return"".concat(e,'="').concat(n[e],'"')}).join(" ");return"<".concat(i," ").concat(e,">").concat(r,"")}}var se=ce("mi"),le=ce("mn"),ue=ce("mo"),fe=ce("mfrac"),pe=ce("msup"),me=ce("msub"),de=ce("msubsup"),he=ce("munder"),ve=ce("mover"),ge=ce("munderover"),be=ce("menclose"),ye=ce("mrow"),xe=ce("msqrt"),Oe=ce("mroot"),je=ce("mfenced"),we=ce("mtable"),ke=ce("mtr"),_e=ce("mtd");function i(Y){var e="."===Y.decimalMark?"\\.":Y.decimalMark,B=new RegExp("^".concat(oe.numbers.digitRange,"+(").concat(e).concat(oe.numbers.digitRange,"+)?")),J=t(Y.colSep),K=t(Y.rowSep),ee=t("\n");function t(c){return function(e){for(var t=[],r=0,n=0,i=0;i');return e(t.trim(),r+c,!0)}return e(t.trim(),r,!0)}var s=ae(re(t,i),2),l=s[0],u=s[1];if((u&&u.trimLeft().startsWith("/")||u.trimLeft().startsWith("./"))&&!u.trimLeft().match(/^\.?\/\//)){var f=ae(function e(t,r){var n=r.trim().startsWith("./"),i=r.trim().slice(n?2:1);var o,a,c;if(i.startsWith(" ")){var s=i.trim().split(" ");o=te(s[0]),c=i.trimLeft().slice(s[0].length+1)}else{var l=re(i),u=ae(l,2);o=u[0],c=u[1]}o=o||ye("");a=fe(Se(t)+Se(o),n&&{bevelled:!0});if(c&&c.trim().startsWith("/")||c.trim().startsWith("./"))return e(a,c);return[a,c]}(l,u),2);l=f[0],u=f[1]}return e(u,r+l,!1)};function te(e){if(0===e.trim().length)return"";var t=r(e,"",!1,!0);return t===o(t)?t:ye(t)}function re(e,t,r){if(!e)return["",""];var n,i,o,a=e[0],c=e.slice(1),s=a+(c.match(/^[A-Za-z]+/)||"");if(e.startsWith("sqrt")){var l=re(e.slice(4).trim(),t);n=xe(l[0]?Se(l[0]):ye("")),i=l[1]}else if(e.startsWith("root")){var u=re(e.slice(4).trimLeft(),t),f=u[0]?Se(u[0]):ye(""),p=re(u[1].trimLeft(),t),m=p[0]?Se(p[0]):ye("");n=Oe(m+f),i=p[1]}else if("\\"===a&&1]*>/,"").replace(/<\/mfenced>$/,"");return function(e){var t=o(e);return[e.slice(0,e.lastIndexOf(t)),t]}(t)[1]===t?t:ye(t)}function o(e){var t=e.match(/<\/(m[a-z]+)>$/);if(!t){var r=e.match(//);if(r){var n=r.match[0].length;return e.slice(n)}return""}for(var i=t[1],o=e.length-(i.length+3),a=0;0<=o;o-=1){if(e.slice(o).startsWith("<".concat(i))){if(0===a)break;a-=1}e.slice(o-2).startsWith("lim","\u2211","\u220f"];var u={endsInFunc:function(e){return e.match(n)},isgroupStart:i,isgroupable:function(e,t){var r=new RegExp("^[0-9A-Za-z+\\-!]{2,}(\\s|".concat(t.colSep,"|").concat(t.rowSep,")"));return e.match(r)},isvertGroupStart:function(e){if(!e.startsWith("|"))return!1;var t=o(e);return t&&""===t[0]},splitNextGroup:m,splitNextVert:o,splitNextOperator:function(e){var t=new RegExp("^"+p.operators.regexp.source).exec(e)[0];return[p.operators.get(t),e.slice(t.length)]},ismatrixInterior:function(e,t,r){if(!i(e))return!1;var n=m(e)[4];if(!(n.trim().startsWith(t)||n.match(/^\s*\n/)&&i(n.trim())))return!1;for(;n&&n.trim();)if((n=(m(n)||[])[4])&&(n.startsWith(r)||n.match(/^\s*\n/)))return!1;return!0},isfontCommand:function(e){return s(e)||l(e)},splitfont:function(e){var t=s(e)||l(e),r=t&&t[2],n=t&&t[3],i='"'===n?"mtext":"`"===n?"mi":"",o=e.indexOf(n),a=o+1+e.slice(o+1).indexOf(n),c=0'+e[t].content+""}:function(e,t){return''+e[t].content+""}}var r=n(Object.assign({},t));return t&&"block"===t.display?function(e,t){return r(e[t].content)+"\n"}:function(e,t){return r(e[t].content)}}e("./lib/polyfills"),t.exports=function(e,r){var t=(r="object"==typeof r?r:{}).inlineOpen||"$$",n=r.inlineClose||"$$",i=r.blockOpen||"$$$",o=r.blockClose||"$$$",a=!!r.loose,c=r.inlineRenderer?function(e,t){return r.inlineRenderer(e[t].content,e[t])}:f(r.renderingOptions),s=r.blockRenderer?function(e,t){return r.blockRenderer(e[t].content,e[t])+"\n"}:f(Object.assign({display:"block"},r.renderingOptions)),l=function(l,u,f){return function(e,t){var r,n,i,o,a=e.posMax,c=e.pos,s=e.src.slice(c,c+l.length);if(s!==l)return!1;if(t)return!1;if(r=(i=p(e,c,s.length)).delims,!i.can_open&&!f)return e.pos+=r,e.pending+=e.src.slice(c,e.pos),!0;for(e.pos=c+l.length;e.posp)return!1;if(e.src.slice(f,f+m.length)!==m)return!1;if(f+=m.length,c=e.src.slice(f,p),n)return!0;for(c.trim().slice(-d.length)===d&&(c=c.trim().slice(0,-d.length),u=!0),o=t;!(u||r<=++o||(f=e.bMarks[o]+e.tShift[o])<(p=e.eMarks[o])&&e.tShift[o]1+1=2

\n'); assert.equal(res2, '1+1=2\n'); }); + it('Should allow whitespace immediately after inline opening in loose mode', function() { + var md = require('markdown-it')() + .use(require('../'), { + inlineOpen: '$', + inlineClose: '$', + loose: true + }); + + var res = md.render('$ 1+1 = 2 $'); + assert.equal(res, '

1+1=2

\n'); + }); }); describe("Rendering options", function() {