Skip to content

Commit

Permalink
Add loose mode to allow whitespace immediately after inline opening, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Menci committed Mar 25, 2019
1 parent 082e48a commit cc5973a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 6 additions & 5 deletions dist/markdown-it-math.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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]);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit cc5973a

Please sign in to comment.