diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-11-03 17:36:01 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-11-03 17:36:01 -0800 |
commit | 158bbebe1a0eede2122feecd6f6b5aee9a53468d (patch) | |
tree | c1ec0b50ace1fbc8d85380771a34c1ef8895c716 /src/inlines.c | |
parent | a5fa2d573185bcc565da89effcfbfdc2967ef939 (diff) |
Removed artificial rule for emph/strong markers.
Previously there was a rule that nothing in a string of more than 3
`*` or `_` characters could close or start emphasis. This was artifical
and led to strange asymmetries, e.g. you could have
`*a *b**` emph within emph but not `**a **b****` strong within strong.
The new parsing strategy makes it easy to remove this limitation.
Spec, js, and c implementations have been updated. Spec might need
some further grooming.
Diffstat (limited to 'src/inlines.c')
-rw-r--r-- | src/inlines.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/inlines.c b/src/inlines.c index 9216979..e747dfd 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -297,8 +297,8 @@ static int scan_delims(subject* subj, unsigned char c, bool * can_open, bool * c advance(subj); } char_after = peek_char(subj); - *can_open = numdelims > 0 && numdelims <= 3 && !isspace(char_after); - *can_close = numdelims > 0 && numdelims <= 3 && !isspace(char_before); + *can_open = numdelims > 0 && !isspace(char_after); + *can_close = numdelims > 0 && !isspace(char_before); if (c == '_') { *can_open = *can_open && !isalnum(char_before); *can_close = *can_close && !isalnum(char_after); @@ -324,6 +324,7 @@ static node_inl* handle_strong_emph(subject* subj, unsigned char c, node_inl **l bool can_open, can_close; int numdelims; int useDelims; + int openerDelims; inline_stack * istack; node_inl * inl; node_inl * emph; @@ -347,9 +348,12 @@ static node_inl* handle_strong_emph(subject* subj, unsigned char c, node_inl **l } // calculate the actual number of delimeters used from this closer - useDelims = istack->delim_count; - if (useDelims == 3) useDelims = numdelims == 3 ? 1 : numdelims; - else if (useDelims > numdelims) useDelims = 1; + openerDelims = istack->delim_count; + if (numdelims < 3 || openerDelims < 3) { + useDelims = numdelims <= openerDelims ? numdelims : openerDelims; + } else { // (numdelims >= 3 && openerDelims >= 3) + useDelims = numdelims % 2 == 0 ? 2 : 1; + } if (istack->delim_count == useDelims) { |