diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-09-16 22:04:54 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-09-16 22:17:16 -0700 |
commit | ac8529c9f55da7fdc1186e3f34313cf411de6e71 (patch) | |
tree | 8c93dfb7d1aaa07bf41d197149539535fe53f05a /js | |
parent | 1ffcc1d908a4b3f8c6e0c0ca0af7cc6cc4c28331 (diff) |
Re-added backtracking and memoization.
Gives better results for things like
**foo*
Diffstat (limited to 'js')
-rwxr-xr-x | js/stmd.js | 30 |
1 files changed, 11 insertions, 19 deletions
@@ -289,6 +289,7 @@ } this.pos += numdelims; + var delimpos = this.pos; var next_inline; var first = []; @@ -472,36 +473,31 @@ } } + this.pos = startpos; + return null; switch (state) { case 1: // ***a - return [{t: 'Str', c: c+c+c}].concat(first); + return [{t: 'Emph', c: [{t: 'Str', c: c}]}].concat(first); case 2: // **a return [{t: 'Str', c: c+c}].concat(first); case 3: // *a return [{t: 'Str', c: c}].concat(first); case 4: // ***a**b case 6: // ***a** b - return [{t: 'Str', c: c+c+c}] - .concat(first, - [{t: 'Str', c: c+c}], - second); + return [{t: 'Strong', c: + [{t: 'Str', c: c}].concat(first)}].concat(second); case 5: // ***a*b case 7: // ***a* b - return [{t: 'Str', c: c+c+c}] - .concat(first, - [{t: 'Str', c: c}], - second); + return [{t: 'Emph', c: + [{t: 'Str', c: c+c}].concat(first)}].concat(second); case 8: // **a *b return [{t: 'Str', c: c+c}] .concat(first, [{t: 'Str', c: c}], second); case 9: // *a **b - return [{t: 'Str', c: c}] - .concat(first, - [{t: 'Str', c: c+c}], - second); + return [{t: 'Emph', c: first.concat([{t: 'Str', c: c}])}].concat(second); default: console.log("Unknown state, parseEmphasis"); // shouldn't happen @@ -783,13 +779,11 @@ // and returning the inline parsed. var parseInline = function() { var startpos = this.pos; - /* var memoized = this.memo[startpos]; if (memoized) { this.pos = memoized.endpos; return memoized.inline; } - */ var c = this.peek(); if (!c) { return null; @@ -830,12 +824,10 @@ this.pos += 1; res = [{t: 'Str', c: c}]; } - /* if (res) { this.memo[startpos] = { inline: res, endpos: this.pos }; } - */ return res; }; @@ -844,7 +836,7 @@ this.subject = s; this.pos = 0; this.refmap = refmap || {}; - // this.memo = {}; + this.memo = {}; this.last_emphasis_closer = null; var inlines = []; var next_inline; @@ -862,7 +854,7 @@ last_emphasis_closer: null, // used by parseEmphasis method pos: 0, refmap: {}, - // memo: {}, + memo: {}, match: match, peek: peek, spnl: spnl, |