aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-09-09 22:23:42 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-09-11 11:17:41 -0700
commit977d40f2789eb4e22ba8380e99eab77e5860c21b (patch)
tree746719402aa27a37173bf4d3d25ce98d88f75548 /js
parente829aaf75ff5feb57c9c0f1a0cd260903116752a (diff)
Simplified parseEmphasis.
Diffstat (limited to 'js')
-rwxr-xr-xjs/stmd.js73
1 files changed, 16 insertions, 57 deletions
diff --git a/js/stmd.js b/js/stmd.js
index 4b3d994..aa21335 100755
--- a/js/stmd.js
+++ b/js/stmd.js
@@ -289,73 +289,32 @@ var parseEmphasis = function() {
this.pos += numdelims;
- var first_close_delims = 0;
var next_inline;
- switch (numdelims) {
- case 1: // we started with * or _
- while (true) {
- res = this.scanDelims(c);
- if (res.numdelims >= 1 && res.can_close) {
- this.pos += 1;
- return {t: 'Emph', c: inlines};
- } else if (next_inline = this.parseInline()) {
- inlines.push(next_inline);
- } else {
- // didn't find closing delimiter
- this.pos = startpos;
- return null;
- }
- }
- break;
-
- case 2: // We started with ** or __
- while (true) {
- res = this.scanDelims(c);
- if (res.numdelims >= 2 && res.can_close) {
- this.pos += 2;
- return {t: 'Strong', c: inlines};
- } else if (next_inline = this.parseInline()) {
- inlines.push(next_inline);
- } else {
- // didn't find closing delimiter
- this.pos = startpos;
- return null;
- }
- }
- break;
-
- case 3: // We started with *** or ___
- var first_delim = 0;
+ var delims_to_match = numdelims;
while (true) {
res = this.scanDelims(c);
- var numdelims = res.numdelims;
- var can_close = res.can_close;
- this.pos += numdelims;
- if (can_close && numdelims === 3 && first_delim === 0) {
- return {t: 'Strong', c: [{t: 'Emph', c: inlines}]};
- } else if (can_close && numdelims === 2 && first_delim === 0) {
- first_delim = 2;
- inlines = [{t: 'Strong', c: inlines}];
- } else if (can_close && numdelims === 1 && first_delim === 0) {
- first_delim = 1;
- inlines = [{t: 'Emph', c: inlines}];
- } else if (can_close && numdelims === 2 && first_delim === 1) {
- return {t: 'Strong', c: inlines};
- } else if (can_close && numdelims === 1 && first_delim === 2) {
- return {t: 'Emph', c: inlines};
+ if (res.can_close) {
+ if (res.numdelims >= 2 && delims_to_match >= 2) {
+ delims_to_match -= 2;
+ this.pos += 2;
+ inlines = [{t: 'Strong', c: inlines}];
+ } else if (res.numdelims >= 1 && delims_to_match >= 1) {
+ delims_to_match -= 1;
+ this.pos += 1;
+ inlines = [{t: 'Emph', c: inlines}];
+ }
+ if (delims_to_match === 0) {
+ return inlines[0];
+ }
} else if (next_inline = this.parseInline()) {
inlines.push(next_inline);
} else {
// didn't find closing delimiter
- this.pos = startpos;
- return null;
+ this.pos = startpos + numdelims;
+ return {t: 'Str', c: this.subject.slice(startpos, startpos + numdelims)};
}
}
- break;
-
- default: // shouldn't happen
- }
return null;
};