feat: recursively parse markup link according to typst syntax (#911)

This commit is contained in:
Myriad-Dreamin 2024-11-29 15:43:38 +08:00 committed by GitHub
parent 6fa07b6777
commit 8b495fe2ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 66 additions and 9 deletions

View file

@ -312,8 +312,7 @@ const markup: textmate.Pattern = {
// },
...boldItalicMarkup,
{
name: "markup.underline.link.typst",
match: /https?:\/\/[0-9a-zA-Z~\/%#&='',;\.\+\?\-\_]*/,
include: "#markupLink",
},
{
include: "#markupMath",
@ -704,6 +703,42 @@ const expressions = (): textmate.Grammar => {
};
};
const link = (): textmate.Grammar => {
const markupLink: textmate.Pattern = {
name: "markup.underline.link.typst",
begin: /(?:https?):\/\//,
end: /(?=[\s\]\)]|(?=[!,.:;?'](?:[\s\]\)]|$)))/,
patterns: [
{ include: "#markupLinkParen" },
{ include: "#markupLinkBracket" },
{
match:
/(^|\G)(?:[0-9a-zA-Z#$%&*\+\-\/\=\@\_\~]+|(?:[!,.:;?']+(?![\s\]\)]|$)))/,
},
],
};
const markupLinkParen: textmate.Pattern = {
begin: /\(/,
end: /\)|(?=[\s\]])/,
patterns: [{ include: "#markupLink" }],
};
const markupLinkBracket: textmate.Pattern = {
begin: /\[/,
end: /\]|(?=[\s\)])/,
patterns: [{ include: "#markupLink" }],
};
return {
repository: {
markupLink,
markupLinkParen,
markupLinkBracket,
},
};
};
const blockComment: textmate.Pattern = {
name: "comment.block.typst",
begin: /\/\*/,
@ -1460,6 +1495,7 @@ export const typst: textmate.Grammar = {
markupBold,
markupItalic,
markupMath,
...link().repository,
markupHeading,
markupBrace,
mathBrace,

View file

@ -1,2 +1,4 @@
>https://zh.wikipedia.org
#^^^^^^^^^^^^^^^^^^^^^^^^ source.typst markup.underline.link.typst
#^^^^^^^^ source.typst markup.underline.link.typst
# ^^ source.typst markup.underline.link.typst
# ^^^^^^^^^^^^^^ source.typst markup.underline.link.typst

View file

@ -35,7 +35,9 @@
# ^^^ source.typst meta.expr.call.typst markup.raw.block.typst punctuation.definition.raw.begin.typst
# ^^^ source.typst meta.expr.call.typst markup.raw.block.typst fenced_code.block.language.typst
# ^ source.typst meta.expr.call.typst markup.raw.block.typst meta.embedded.block.typst
# ^^^^^^^^^^^^^^^^^^^^^^^^ source.typst meta.expr.call.typst markup.raw.block.typst meta.embedded.block.typst markup.underline.link.typst
# ^^^^^^^^ source.typst meta.expr.call.typst markup.raw.block.typst meta.embedded.block.typst markup.underline.link.typst
# ^^ source.typst meta.expr.call.typst markup.raw.block.typst meta.embedded.block.typst markup.underline.link.typst
# ^^^^^^^^^^^^^^ source.typst meta.expr.call.typst markup.raw.block.typst meta.embedded.block.typst markup.underline.link.typst
# ^^^ source.typst meta.expr.call.typst markup.raw.block.typst punctuation.definition.raw.end.typst
# ^ source.typst meta.expr.call.typst meta.brace.round.typst
>
@ -43,7 +45,9 @@
#^^^^ source.typst markup.raw.block.typst punctuation.definition.raw.begin.typst
# ^^^ source.typst markup.raw.block.typst fenced_code.block.language.typst
>https://zh.wikipedia.org
#^^^^^^^^^^^^^^^^^^^^^^^^ source.typst markup.raw.block.typst meta.embedded.block.typst markup.underline.link.typst
#^^^^^^^^ source.typst markup.raw.block.typst meta.embedded.block.typst markup.underline.link.typst
# ^^ source.typst markup.raw.block.typst meta.embedded.block.typst markup.underline.link.typst
# ^^^^^^^^^^^^^^ source.typst markup.raw.block.typst meta.embedded.block.typst markup.underline.link.typst
>````
#^^^^ source.typst markup.raw.block.typst punctuation.definition.raw.end.typst
>

View file

@ -0,0 +1,2 @@
https://[::1]:8080/test
https://test.

View file

@ -0,0 +1,11 @@
>https://[::1]:8080/test
#^^^^^^^^ source.typst markup.underline.link.typst
# ^ source.typst markup.underline.link.typst
# ^^^ source.typst markup.underline.link.typst
# ^ source.typst markup.underline.link.typst
# ^^^^^^^^^^ source.typst markup.underline.link.typst
>https://test.
#^^^^^^^^ source.typst markup.underline.link.typst
# ^^^^ source.typst markup.underline.link.typst
# ^^ source.typst
>

View file

@ -1,8 +1,9 @@
>("https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#symbol-view")[integrating]
#^ source.typst markup.content.brace.typst
# ^ source.typst
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.typst markup.underline.link.typst
# ^ source.typst
# ^^^^^^^^ source.typst markup.underline.link.typst
# ^^^^^^ source.typst markup.underline.link.typst
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.typst markup.underline.link.typst
# ^ source.typst markup.content.brace.typst
# ^ source.typst markup.content.brace.typst
# ^^^^^^^^^^^ source.typst
@ -10,8 +11,9 @@
>("https://github.com/istudyatuni/sublimelsp-LSP/blob/40ea8ea01af19b8719b0e2e827dbfb8651261199/docs/src/language_servers.md#tinymist")[]
#^ source.typst markup.content.brace.typst
# ^ source.typst
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.typst markup.underline.link.typst
# ^ source.typst
# ^^^^^^^^ source.typst markup.underline.link.typst
# ^^^^^^ source.typst markup.underline.link.typst
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.typst markup.underline.link.typst
# ^ source.typst markup.content.brace.typst
# ^ source.typst markup.content.brace.typst
# ^ source.typst markup.content.brace.typst