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

fix: Don't parse tags inside words & URLs #266

Merged
merged 1 commit into from
Nov 22, 2023
Merged
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
39 changes: 21 additions & 18 deletions Marksman/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,28 @@ module Markdown =
do this.OpeningCharacters <- [| '#' |]

override this.Match(processor, slice) =
let start = slice.Start
let offsetStart = processor.GetSourcePosition(slice.Start)

let shouldAccept (c: char) = c.IsAlphaNumeric() || c = '-' || c = '_'

while (shouldAccept (slice.PeekChar())) do
slice.NextChar() |> ignore

let end_ = slice.Start
let offsetEnd = offsetStart + (end_ - start)

if end_ > start then
let text = slice.Text.Substring(start, end_ - start + 1)
let tag = TagInline(text)
tag.Span <- SourceSpan(offsetStart, offsetEnd)
processor.Inline <- tag
true
else
// tags should not be placed inside words, URLs etc.
if (slice.PeekCharExtra -1).IsAlphaNumeric() then
false
else
let start = slice.Start
let offsetStart = processor.GetSourcePosition(slice.Start)
let shouldAccept (c: char) = c.IsAlphaNumeric() || c = '-' || c = '_'

while (shouldAccept (slice.PeekChar())) do
slice.NextChar() |> ignore

let end_ = slice.Start
let offsetEnd = offsetStart + (end_ - start)

if end_ > start then
let text = slice.Text.Substring(start, end_ - start + 1)
let tag = TagInline(text)
tag.Span <- SourceSpan(offsetStart, offsetEnd)
processor.Inline <- tag
true
else
false

/// <summary>Match links of the form `[[doc#heading|title]]`, where at least one of `doc` and `#heading` must be present (`|title` may be omitted).</summary>
type WikiLinkParser() as this =
Expand Down