Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: Update markdig parser to fix parsing crashes #259

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MarkdigPatches/MarkdigPatches.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="0.30.2" />
<PackageReference Include="Markdig" Version="0.33.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Marksman/Marksman.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<PackageReference Include="FSharp.SystemCommandLine" Version="0.13.0-beta4"/>
<PackageReference Include="FSharpPlus" Version="1.2.4"/>
<PackageReference Include="Glob" Version="1.1.9"/>
<PackageReference Include="Markdig" Version="0.30.2"/>
<PackageReference Include="Markdig" Version="0.33.0"/>
<!-- <PackageReference Include="Ionide.LanguageServerProtocol" Version="0.3.1" />-->
<PackageReference Include="Serilog" Version="2.11.0"/>
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1"/>
Expand Down
51 changes: 23 additions & 28 deletions Marksman/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -226,34 +226,29 @@ module Markdown =
| :? HeadingBlock as h ->
let level = h.Level

// TODO: remove after https://github.com/xoofx/markdig/pull/696 is released
if h.Span.End < text.content.Length then
let fullText = text.content.Substring(h.Span.Start, h.Span.Length)
let title0 = fullText.TrimStart(' ', '#')
let headingPrefixLen = fullText.Length - title0.Length
let title = title0.TrimEnd(' ')
let headingSuffixLen = title0.Length - title.Length

let titleRange =
sourceSpanToRange
text
(SourceSpan(
h.Span.Start + headingPrefixLen,
h.Span.End - headingSuffixLen
))

let range = sourceSpanToRange text h.Span

let heading =
Node.mk
fullText
range
{ level = level
title = Node.mkText title titleRange
scope = range
children = [||] }

elements.Add(H heading)
let fullText = text.content.Substring(h.Span.Start, h.Span.Length)
let title0 = fullText.TrimStart(' ', '#')
let headingPrefixLen = fullText.Length - title0.Length
let title = title0.TrimEnd(' ')
let headingSuffixLen = title0.Length - title.Length

let titleRange =
sourceSpanToRange
text
(SourceSpan(h.Span.Start + headingPrefixLen, h.Span.End - headingSuffixLen))

let range = sourceSpanToRange text h.Span

let heading =
Node.mk
fullText
range
{ level = level
title = Node.mkText title titleRange
scope = range
children = [||] }

elements.Add(H heading)
| :? WikiLinkInline as link ->
let doc =
match link.Doc, link.DocSpan with
Expand Down
42 changes: 41 additions & 1 deletion Tests/ParserTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,44 @@ module RegressionTests =
let content = "A\n\n-\n-"

let actual = scrapeString content
checkInlineSnapshot actual []

checkInlineSnapshot
actual
[ "H2: range=(2,0)-(3,1); scope=(2,0)-(4,0)"
" text=`-"
"-`"
" title=`-"
"-` @ (2,0)-(3,1)" ]

[<Fact>]
let no235 () =
let content =
"""
[
'00000048', '00000681', '00000552', '00000206', '00000031', '00000303',
'00001268', '00000540', '00000519', '00000821', '00000731', '00001089',
'00000311', '00000784', '00000015', '00001052', '00000030', '00000352',
'00000758', '00000113', '00000152', '00000099', '00000932', '00000071',
'00000126', '00000450', '00000677', '00000722', '00000724', '00000182',
'00000507', '00000001', '00000866', '00000147', '00000186', '00000711'
]
"""

let actual = scrapeString content

checkInlineSnapshot
actual
[ "ML: [ "
"'00000048', '00000681', '00000552', '00000206', '00000031', '00000303', "
"'00001268', '00000540', '00000519', '00000821', '00000731', '00001089', "
"'00000311', '00000784', '00000015', '00001052', '00000030', '00000352', "
"'00000758', '00000113', '00000152', '00000099', '00000932', '00000071', "
"'00000126', '00000450', '00000677', '00000722', '00000724', '00000182', "
"'00000507', '00000001', '00000866', '00000147', '00000186', '00000711' "
"] @ (1,0)-(8,1)"
" RS: label='00000048', '00000681', '00000552', '00000206', '00000031', '00000303', "
" '00001268', '00000540', '00000519', '00000821', '00000731', '00001089', "
" '00000311', '00000784', '00000015', '00001052', '00000030', '00000352', "
" '00000758', '00000113', '00000152', '00000099', '00000932', '00000071', "
" '00000126', '00000450', '00000677', '00000722', '00000724', '00000182', "
" '00000507', '00000001', '00000866', '00000147', '00000186', '00000711' @ (2,0)-(7,70)" ]