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 loose mode to allow whitespace immediately after inline opening #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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