Skip to content

Commit b930e8a

Browse files
author
runarberg
committed
v3.0.0-dist
1 parent f435059 commit b930e8a

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

dist/markdown-it-math.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! markdown-it-math 2.0.1 https://github.com/runarberg/markdown-it-math @license MIT */
1+
/*! markdown-it-math 3.0.0 https://github.com/runarberg/markdown-it-math @license MIT */
22
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownitMath = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
33
'use strict';
44

@@ -5692,42 +5692,56 @@ var ascii2mathml = require('ascii2mathml');
56925692
require('./lib/polyfills');
56935693

56945694

5695-
function scanDelims(state, start) {
5696-
var pos = state.pos, lastChar, nextChar, count,
5695+
function scanDelims(state, start, delimLength) {
5696+
var pos = start, lastChar, nextChar, count, can_open, can_close,
56975697
isLastWhiteSpace, isLastPunctChar,
56985698
isNextWhiteSpace, isNextPunctChar,
5699-
can_open = true,
5700-
can_close = true,
5699+
left_flanking = true,
5700+
right_flanking = true,
57015701
max = state.posMax,
57025702
isWhiteSpace = state.md.utils.isWhiteSpace,
57035703
isPunctChar = state.md.utils.isPunctChar,
57045704
isMdAsciiPunct = state.md.utils.isMdAsciiPunct;
5705+
57055706
// treat beginning of the line as a whitespace
57065707
lastChar = start > 0 ? state.src.charCodeAt(start - 1) : 0x20;
5708+
57075709
if (pos >= max) {
57085710
can_open = false;
57095711
}
5712+
5713+
pos += delimLength;
5714+
57105715
count = pos - start;
5716+
57115717
// treat end of the line as a whitespace
57125718
nextChar = pos < max ? state.src.charCodeAt(pos) : 0x20;
5719+
57135720
isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctChar(String.fromCharCode(lastChar));
57145721
isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctChar(String.fromCharCode(nextChar));
5722+
57155723
isLastWhiteSpace = isWhiteSpace(lastChar);
57165724
isNextWhiteSpace = isWhiteSpace(nextChar);
5725+
57175726
if (isNextWhiteSpace) {
5718-
can_open = false;
5727+
left_flanking = false;
57195728
} else if (isNextPunctChar) {
57205729
if (!(isLastWhiteSpace || isLastPunctChar)) {
5721-
can_open = false;
5730+
left_flanking = false;
57225731
}
57235732
}
5733+
57245734
if (isLastWhiteSpace) {
5725-
can_close = false;
5735+
right_flanking = false;
57265736
} else if (isLastPunctChar) {
57275737
if (!(isNextWhiteSpace || isNextPunctChar)) {
5728-
can_close = false;
5738+
right_flanking = false;
57295739
}
57305740
}
5741+
5742+
can_open = left_flanking;
5743+
can_close = right_flanking;
5744+
57315745
return {
57325746
can_open: can_open,
57335747
can_close: can_close,
@@ -5750,7 +5764,7 @@ function makeMath_inline(open, close) {
57505764
if (openDelim !== open) { return false; }
57515765
if (silent) { return false; } // Don’t run any pairs in validation mode
57525766

5753-
res = scanDelims(state, start + open.length);
5767+
res = scanDelims(state, start, openDelim.length);
57545768
startCount = res.delims;
57555769

57565770
if (!res.can_open) {
@@ -5765,7 +5779,7 @@ function makeMath_inline(open, close) {
57655779
while (state.pos < max) {
57665780
closeDelim = state.src.slice(state.pos, state.pos + close.length);
57675781
if (closeDelim === close) {
5768-
res = scanDelims(state, state.pos + close.length);
5782+
res = scanDelims(state, state.pos, close.length);
57695783
if (res.can_close) {
57705784
found = true;
57715785
break;
@@ -5799,7 +5813,7 @@ function makeMath_inline(open, close) {
57995813

58005814
function makeMath_block(open, close) {
58015815
return function math_block(state, startLine, endLine, silent) {
5802-
var openDelim, len, params, nextLine, token,
5816+
var openDelim, len, params, nextLine, token, firstLine, lastLine, lastLinePos,
58035817
haveEndMarker = false,
58045818
pos = state.bMarks[startLine] + state.tShift[startLine],
58055819
max = state.eMarks[startLine];
@@ -5810,14 +5824,26 @@ function makeMath_block(open, close) {
58105824

58115825
if (openDelim !== open) { return false; }
58125826

5827+
pos += open.length;
5828+
firstLine = state.src.slice(pos, max);
5829+
58135830
// Since start is found, we can report success here in validation mode
58145831
if (silent) { return true; }
58155832

5833+
if (firstLine.trim().slice(-close.length) === close) {
5834+
// Single line expression
5835+
firstLine = firstLine.trim().slice(0, -close.length);
5836+
haveEndMarker = true;
5837+
}
5838+
58165839
// search end of block
58175840
nextLine = startLine;
58185841

58195842
for (;;) {
5843+
if (haveEndMarker) { break; }
5844+
58205845
nextLine++;
5846+
58215847
if (nextLine >= endLine) {
58225848
// unclosed block should be autoclosed by end of document.
58235849
// also block seems to be autoclosed by end of parent
@@ -5832,23 +5858,27 @@ function makeMath_block(open, close) {
58325858
break;
58335859
}
58345860

5835-
if (state.src.slice(pos, pos + close.length) !== close) { continue; }
5861+
if (state.src.slice(pos, max).trim().slice(-close.length) !== close) {
5862+
continue;
5863+
}
58365864

58375865
if (state.tShift[nextLine] - state.blkIndent >= 4) {
58385866
// closing block math should be indented less then 4 spaces
58395867
continue;
58405868
}
58415869

5842-
pos += close.length;
5870+
lastLinePos = state.src.slice(0, max).lastIndexOf(close);
5871+
lastLine = state.src.slice(pos, lastLinePos);
5872+
5873+
pos += lastLine.length + close.length;
58435874

58445875
// make sure tail has spaces only
58455876
pos = state.skipSpaces(pos);
58465877

58475878
if (pos < max) { continue; }
58485879

5849-
haveEndMarker = true;
58505880
// found!
5851-
break;
5881+
haveEndMarker = true;
58525882
}
58535883

58545884
// If math block has heading spaces, they should be removed from its inner block
@@ -5858,7 +5888,9 @@ function makeMath_block(open, close) {
58585888

58595889
token = state.push('math_block', 'math', 0);
58605890
token.block = true;
5861-
token.content = state.getLines(startLine + 1, nextLine, len, true);
5891+
token.content = (firstLine && firstLine.trim() ? firstLine + '\n' : '') +
5892+
state.getLines(startLine + 1, nextLine, len, true) +
5893+
(lastLine && lastLine.trim() ? lastLine : '');
58625894
token.info = params;
58635895
token.map = [ startLine, state.line ];
58645896
token.markup = open;

0 commit comments

Comments
 (0)