Skip to content

Commit 91239b6

Browse files
authored
fix(message-parser): Add file path structure to URL reference markdown (#901)
1 parent 6062700 commit 91239b6

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

packages/message-parser/src/grammar.pegjs

+11-6
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Inline
148148
)+
149149
EndOfLine? { return reducePlainTexts(value); }
150150

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

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

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

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

266+
FilePath = $(urlScheme urlBody+)
267+
266268
LinkTitle = text:(Emphasis / Line / Whitespace) { return text; }
267269

268-
LinkRef = text:(URL / p:Phone { return 'tel:' + p.number; }) { return text; }
270+
LinkRef
271+
= text:(URL / FilePath / p:Phone { return 'tel:' + p.number; }) {
272+
return text;
273+
}
269274

270275
Image
271276
= "![](" href:LinkRef ")" { return image(href); }
@@ -389,13 +394,13 @@ phonePrefix
389394
*/
390395

391396
URL
392-
= $(urlScheme urlAuthority urlBody)
393-
/ $(urlAuthorityHost urlBody)
397+
= $(urlScheme urlAuthority urlBody*)
398+
/ $(urlAuthorityHost urlBody*)
394399

395400
urlScheme
396401
= $(
397402
[[A-Za-z0-9+.-]
398-
[A-Za-z0-9+.-]
403+
[A-Za-z0-9+.-]?
399404
[A-Za-z0-9+.-]?
400405
[A-Za-z0-9+.-]?
401406
[A-Za-z0-9+.-]?
@@ -446,7 +451,7 @@ urlBody
446451
/ "~"
447452
/ "("
448453
)
449-
)*
454+
)
450455

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

packages/message-parser/tests/link.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,25 @@ Text after line break`,
414414
['[9gag](9gag.com)', [paragraph([link('9gag.com', plain(`9gag`))])]],
415415
['<9gag.com|9gag>', [paragraph([link('9gag.com', plain(`9gag`))])]],
416416
['9gag.com', [paragraph([link('9gag.com')])]],
417+
[
418+
'[notes link](notes://Server/C3257116002CAD60/0/CCAF6BE2824A1F49432588D2001FA73E)',
419+
[
420+
paragraph([
421+
link(
422+
'notes://Server/C3257116002CAD60/0/CCAF6BE2824A1F49432588D2001FA73E',
423+
plain('notes link')
424+
),
425+
]),
426+
],
427+
],
428+
[
429+
'[File Path](C:/Users/user1/Documents/projects/file.js)',
430+
[
431+
paragraph([
432+
link('C:/Users/user1/Documents/projects/file.js', plain('File Path')),
433+
]),
434+
],
435+
],
417436

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

0 commit comments

Comments
 (0)