Skip to content

Apply fence lookahead optimisation for top-level code blocks#100

Merged
RobertDober merged 1 commit intoRobertDober:masterfrom
jonatanklosko:jk-fence-lookahead-non-recursive
Mar 24, 2022
Merged

Apply fence lookahead optimisation for top-level code blocks#100
RobertDober merged 1 commit intoRobertDober:masterfrom
jonatanklosko:jk-fence-lookahead-non-recursive

Conversation

@jonatanklosko
Copy link
Copy Markdown
Collaborator

The optimisation was introduced in #70 then modified in #79, but with the latter it no longer applies to top-level code blocks (which is primarily what we need), this brings it back.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 23, 2022

Pull Request Test Coverage Report for Build b6d6dc090846f0ff9aefeba44dc524c140fd8255-PR-100

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 76d443cabc650d6d9c0b9a862e9673cec5128b2f: 0.0%
Covered Lines: 864
Relevant Lines: 864

💛 - Coveralls

%Line.Fence{delimiter: delimiter, indent: 0} = fence when recursive ->
stop = ~r/\A (?: #{delimiter} ) \s* ([^`\s]*) \s* \z/xu
%Line.Fence{delimiter: delimiter, indent: 0} = fence ->
stop = ~r/\A (\s*) (?: #{delimiter} ) \s* ([^`\s]*) \s* \z/xu
Copy link
Copy Markdown
Collaborator Author

@jonatanklosko jonatanklosko Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optional whitespace is necessary to handle code blocks is inside a list.

(Alternatively we could do this only when not recursive)

messages = [{:warning, 1, "Failed to find closing <div>"}]

assert as_ast(markdown, annotations: @annotations) == {:ok, ast, messages}
assert as_ast(markdown, annotations: @annotations) == {:error, ast, messages}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobertDober
Copy link
Copy Markdown
Owner

@jonatanklosko thanks for that, I am puzzled I played around with this during my current refactoring and it broke some cases, probably just me, I'll merge this and have a closer look.

@RobertDober RobertDober merged commit 6ec5c11 into RobertDober:master Mar 24, 2022
@jonatanklosko jonatanklosko deleted the jk-fence-lookahead-non-recursive branch March 24, 2022 11:52
@jonatanklosko
Copy link
Copy Markdown
Collaborator Author

@RobertDober thanks! I realised we can easily test if the optimisation works as expected (#101), so we don't run into the issue again when refactoring :)

@josevalim
Copy link
Copy Markdown
Collaborator

@RobertDober I think when I first added this I also changed some tests, but they were corner cases that were not defined in the spec (iirc).

@RobertDober
Copy link
Copy Markdown
Owner

@jonatanklosko and @josevalim thank you both for the code and your insights, I see now why this is ok and what I missunderstood...

Publishing package...
[#########################] 100%
Package published to https://hex.pm/packages/earmark_parser/1.4.25 (56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e)

@jonatanklosko
Copy link
Copy Markdown
Collaborator Author

@RobertDober fantastic, thanks for releasing so quickly <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants