Skip to content

Commit

Permalink
fix(message-parser): Add file path structure to URL reference markdown (
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocostadev authored Nov 16, 2022
1 parent 6062700 commit 91239b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/message-parser/src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Inline
)+
EndOfLine? { return reducePlainTexts(value); }

Whitespace = w:$" "+ { return plain(w); }
Whitespace = w:$Space+ { return plain(w); }

Escaped = "\\" t:$("*" / "_" / "~" / "`" / "#" / ".") { return plain(t); }

Expand Down Expand Up @@ -263,9 +263,14 @@ InlineCode = "`" text:$InlineCode__+ "`" { return inlineCode(plain(text)); }

InlineCode__ = $(!"`" !"\n" $:.)

FilePath = $(urlScheme urlBody+)

LinkTitle = text:(Emphasis / Line / Whitespace) { return text; }

LinkRef = text:(URL / p:Phone { return 'tel:' + p.number; }) { return text; }
LinkRef
= text:(URL / FilePath / p:Phone { return 'tel:' + p.number; }) {
return text;
}

Image
= "![](" href:LinkRef ")" { return image(href); }
Expand Down Expand Up @@ -389,13 +394,13 @@ phonePrefix
*/

URL
= $(urlScheme urlAuthority urlBody)
/ $(urlAuthorityHost urlBody)
= $(urlScheme urlAuthority urlBody*)
/ $(urlAuthorityHost urlBody*)

urlScheme
= $(
[[A-Za-z0-9+.-]
[A-Za-z0-9+.-]
[A-Za-z0-9+.-]?
[A-Za-z0-9+.-]?
[A-Za-z0-9+.-]?
[A-Za-z0-9+.-]?
Expand Down Expand Up @@ -446,7 +451,7 @@ urlBody
/ "~"
/ "("
)
)*
)

urlAuthority = $("//" urlAuthorityUserInfo? urlAuthorityHost)

Expand Down
19 changes: 19 additions & 0 deletions packages/message-parser/tests/link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,25 @@ Text after line break`,
['[9gag](9gag.com)', [paragraph([link('9gag.com', plain(`9gag`))])]],
['<9gag.com|9gag>', [paragraph([link('9gag.com', plain(`9gag`))])]],
['9gag.com', [paragraph([link('9gag.com')])]],
[
'[notes link](notes://Server/C3257116002CAD60/0/CCAF6BE2824A1F49432588D2001FA73E)',
[
paragraph([
link(
'notes://Server/C3257116002CAD60/0/CCAF6BE2824A1F49432588D2001FA73E',
plain('notes link')
),
]),
],
],
[
'[File Path](C:/Users/user1/Documents/projects/file.js)',
[
paragraph([
link('C:/Users/user1/Documents/projects/file.js', plain('File Path')),
]),
],
],

// Should not parse as link
['[77.77%](77.77%)', [paragraph([plain('[77.77%](77.77%)')])]],
Expand Down

0 comments on commit 91239b6

Please sign in to comment.