From e7ca399a2846cb2d5bdbfaee934f38e988933e1e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 24 Oct 2014 11:29:03 -0700 Subject: Revised spec for new emph/strong rules. These rules go with the new stack-based parser for emph/strong. --- spec.txt | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 11 deletions(-) (limited to 'spec.txt') diff --git a/spec.txt b/spec.txt index 0c09c43..e9de0ab 100644 --- a/spec.txt +++ b/spec.txt @@ -4095,21 +4095,39 @@ for efficient parsing strategies that do not backtrack: (c) it is not followed by an ASCII alphanumeric character. 9. Emphasis begins with a delimiter that [can open - emphasis](#can-open-emphasis) and includes inlines parsed - sequentially until a delimiter that [can close + emphasis](#can-open-emphasis) and ends with a delimiter that [can close emphasis](#can-close-emphasis), and that uses the same - character (`_` or `*`) as the opening delimiter, is reached. + character (`_` or `*`) as the opening delimiter. The inlines + between the open delimiter and the closing delimiter are the + contents of the emphasis inline. 10. Strong emphasis begins with a delimiter that [can open strong - emphasis](#can-open-strong-emphasis) and includes inlines parsed - sequentially until a delimiter that [can close strong - emphasis](#can-close-strong-emphasis), and that uses the - same character (`_` or `*`) as the opening delimiter, is reached. + emphasis](#can-open-strong-emphasis) and ends with a delimiter that + [can close strong emphasis](#can-close-strong-emphasis), and that uses the + same character (`_` or `*`) as the opening delimiter. The inlines + between the open delimiter and the closing delimiter are the + contents of the strong emphasis inline. -11. In case of ambiguity, strong emphasis takes precedence. Thus, - `**foo**` is `foo`, not `foo`, - and `***foo***` is `foo`, not - `foo` or `foo`. +Where rules 1--10 above are compatible with multiple parsings, +the following principles resolve ambiguity: + +11. An interpretation `...` is always preferred to + `...`. + +12. An interpretation `...` is always + preferred to `..`. + +13. When two potential emphasis or strong emphasis spans overlap, + the first takes precedence. Thus, for example, `*foo _bar* baz_` + is parsed as `foo _bar baz_` rather than + `*foo bar* baz`. + +14. Inline code spans, links, images, and HTML tags group more tightly + than emphasis. So, when there is a choice between an interpretation + that contains one of these elements and one that does not, the + former always wins. Thus, for example, `*[foo*](bar)` is + parsed as `*foo*` rather than as + `[foo](bar)`. These rules can be illustrated through a series of examples. @@ -4689,6 +4707,15 @@ We retain symmetry in these cases:

foo bar

. +Note that this is not a case of strong emphasis, +since the interior `*` closes regular emphasis: + +. +**foo bar* baz** +. +

foo bar baz*

+. + More cases with mismatched delimiters: . @@ -4721,6 +4748,41 @@ More cases with mismatched delimiters:

***foo bar

. +The following case illustrates rule 13: + +. +*foo _bar* baz_ +. +

foo _bar baz_

+. + +The following cases illustrate rule 14: + +. +*[foo*](bar) +. +

*foo*

+. + +. +*![foo*](bar) +. +

*foo*

+. + +. +* +. +

*

+. + +. +*a`a*` +. +

*aa*

+. + + ## Links A link contains a [link label](#link-label) (the visible text), -- cgit v1.2.3 From 9e30ca443275356c1693ab785d700c280d5dfa8c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 24 Oct 2014 11:32:28 -0700 Subject: Added tricky recursive case for emph/strong. --- spec.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'spec.txt') diff --git a/spec.txt b/spec.txt index e9de0ab..3f10459 100644 --- a/spec.txt +++ b/spec.txt @@ -4782,6 +4782,32 @@ The following cases illustrate rule 14:

*aa*

. +Here is a tricky case that can be a performance problem with some +parsers: + +. +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +. +

*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a +*a **a *a **a *a **a *a **a

+. ## Links -- cgit v1.2.3