Skip to content

Commit

Permalink
nested link references definitions can be used at the top-level dillo…
Browse files Browse the repository at this point in the history
…nkearns#60 (by adding a parse phase for container)
  • Loading branch information
LutSa committed Jun 4, 2021
1 parent a72ce49 commit 1441e20
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 58 deletions.
2 changes: 2 additions & 0 deletions spec-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
184,
185,
186,
187,
188
],
"Links": [
Expand Down Expand Up @@ -917,6 +918,7 @@
184,
185,
186,
187,
188
],
"Links": [
Expand Down
50 changes: 38 additions & 12 deletions src/Markdown/Parser.elm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ parse input =

Ok v ->
-- then parse the inlines of each raw block
case parseAllInlines v of
case parseAllInlines (parseContainers v) of
Err e ->
-- NOTE these messages get an incorrect location,
-- because they are parsed outside of the main (raw block) parser context.
Expand All @@ -80,6 +80,35 @@ parse input =
Ok (List.filter isNotEmptyParagraph blocks)


parseContainers: State-> State
parseContainers state =
parseContainersHelp state.rawBlocks {linkReferenceDefinitions=state.linkReferenceDefinitions, rawBlocks = []}


parseContainersHelp : List RawBlock -> State -> State
parseContainersHelp unparsedRawBlocks parsedState =
case unparsedRawBlocks of
rawBlock :: rest ->
case rawBlock of
BlockQuote rawBlocks ->
case Advanced.run rawBlockParser rawBlocks of
Ok value ->
parseContainersHelp rest
{ linkReferenceDefinitions = parsedState.linkReferenceDefinitions ++ (parseContainers value).linkReferenceDefinitions
, rawBlocks = parsedState.rawBlocks ++[ (parseContainers value).rawBlocks|>ParsedBlockQuote]
}
Err e ->
-- TODO return this error
{linkReferenceDefinitions=[], rawBlocks= []}
_ ->
parseContainersHelp rest
{ linkReferenceDefinitions = parsedState.linkReferenceDefinitions
, rawBlocks = parsedState.rawBlocks ++ [rawBlock]
}
[] ->
parsedState


deadEndsToString : List (Advanced.DeadEnd String Parser.Problem) -> String
deadEndsToString deadEnds =
deadEnds
Expand Down Expand Up @@ -294,19 +323,16 @@ parseInlines linkReferences rawBlock =
EmptyBlock

BlockQuote rawBlocks ->
case Advanced.run rawBlockParser rawBlocks of
Ok value ->
case parseAllInlines value of
Ok parsedBlocks ->
Block.BlockQuote parsedBlocks
|> ParsedBlock

Err e ->
InlineProblem e
EmptyBlock

Err error ->
InlineProblem (Parser.Problem (deadEndsToString error))
ParsedBlockQuote rawBlocks->
case parseAllInlines {linkReferenceDefinitions = linkReferences, rawBlocks = rawBlocks} of
Ok parsedBlocks ->
Block.BlockQuote parsedBlocks
|> ParsedBlock

Err e ->
InlineProblem e
IndentedCodeBlock codeBlockBody ->
Block.CodeBlock { body = codeBlockBody, language = Nothing }
|> ParsedBlock
Expand Down
1 change: 1 addition & 0 deletions src/Markdown/RawBlock.elm
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ type RawBlock
| TableDelimiter Markdown.Table.TableDelimiterRow
| BlankLine
| BlockQuote String
| ParsedBlockQuote (List RawBlock)
| SetextLine SetextLevel String
2 changes: 1 addition & 1 deletion test-results/failing/CommonMark/HTML blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ Should give output:
But instead was:
````````````html
ERROR Problem at row 1 Problem at row 2 Expecting symbol
````````````
## [Example 144](https://spec.commonmark.org/0.29/#example-144)
Expand Down
22 changes: 0 additions & 22 deletions test-results/failing/CommonMark/Link reference definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,3 @@ But instead was:
````````````html
<p>Foo<a href="/baz">bar</a></p>
````````````
## [Example 187](https://spec.commonmark.org/0.29/#example-187)

This markdown:

````````````markdown
[foo]

> [foo]: /url

````````````

Should give output:

````````````html
<p><a href="/url">foo</a></p><blockquote></blockquote>
````````````

But instead was:

````````````html
<p>[foo]</p><blockquote></blockquote>
````````````
2 changes: 1 addition & 1 deletion test-results/failing/GFM/HTML blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ Should give output:
But instead was:
````````````html
ERROR Problem at row 1 Problem at row 2 Expecting symbol
````````````
## [Example 144](https://spec.commonmark.org/0.29/#example-144)
Expand Down
22 changes: 0 additions & 22 deletions test-results/failing/GFM/Link reference definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,3 @@ But instead was:
````````````html
<p>Foo<a href="/baz">bar</a></p>
````````````
## [Example 187](https://spec.commonmark.org/0.29/#example-187)

This markdown:

````````````markdown
[foo]

> [foo]: /url

````````````

Should give output:

````````````html
<p><a href="/url">foo</a></p><blockquote></blockquote>
````````````

But instead was:

````````````html
<p>[foo]</p><blockquote></blockquote>
````````````
22 changes: 22 additions & 0 deletions test-results/passing-CommonMark.md
Original file line number Diff line number Diff line change
Expand Up @@ -6624,6 +6624,28 @@ Gives this correct output:

````````````

### [Example 187](https://spec.commonmark.org/0.29/#example-187)

This markdown:


````````````markdown
[foo]

> [foo]: /url

````````````

Gives this correct output:


````````````html
<p><a href="/url">foo</a></p>
<blockquote>
</blockquote>

````````````

### [Example 188](https://spec.commonmark.org/0.29/#example-188)

This markdown:
Expand Down
22 changes: 22 additions & 0 deletions test-results/passing-GFM.md
Original file line number Diff line number Diff line change
Expand Up @@ -6624,6 +6624,28 @@ Gives this correct output:

````````````

### [Example 187](https://spec.commonmark.org/0.29/#example-187)

This markdown:


````````````markdown
[foo]

> [foo]: /url

````````````

Gives this correct output:


````````````html
<p><a href="/url">foo</a></p>
<blockquote>
</blockquote>

````````````

### [Example 188](https://spec.commonmark.org/0.29/#example-188)

This markdown:
Expand Down

0 comments on commit 1441e20

Please sign in to comment.