mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-24 21:19:37 +00:00
test: add more completion tests (#776)
* dev: add more tests * test: add show/set completion tests * test: test completion about arguments of builtin functions
This commit is contained in:
parent
411f29fd53
commit
662ae488be
20 changed files with 681 additions and 5 deletions
|
|
@ -0,0 +1,3 @@
|
||||||
|
/// contains: columns
|
||||||
|
|
||||||
|
#table(/* range 0..1 */)
|
||||||
2
crates/tinymist-query/src/fixtures/completion/set.typ
Normal file
2
crates/tinymist-query/src/fixtures/completion/set.typ
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement
|
||||||
|
#set r/* range 0..1 */
|
||||||
2
crates/tinymist-query/src/fixtures/completion/set2.typ
Normal file
2
crates/tinymist-query/src/fixtures/completion/set2.typ
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement
|
||||||
|
#set /* range 0..1 */
|
||||||
2
crates/tinymist-query/src/fixtures/completion/show.typ
Normal file
2
crates/tinymist-query/src/fixtures/completion/show.typ
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement, regex selector
|
||||||
|
#show r/* range 0..1 */
|
||||||
2
crates/tinymist-query/src/fixtures/completion/show2.typ
Normal file
2
crates/tinymist-query/src/fixtures/completion/show2.typ
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement, regex selector
|
||||||
|
#show /* range 0..1 */
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement
|
||||||
|
#show raw: r/* range 0..1 */
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement
|
||||||
|
#show raw: /* range 0..1 */
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (30..31)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/completion/func_builtin_args.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 5,
|
||||||
|
"label": "columns",
|
||||||
|
"sortText": "002",
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "columns: ${1:}",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 2
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "columns",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(int, content, gutter: relative) => columns"
|
||||||
|
},
|
||||||
|
"sortText": "054",
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "columns(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 2
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (30..31)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/completion/set.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 5,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (86..87)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/completion/set2.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 5,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 5,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (75..76)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/completion/show.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw.where",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw.where(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw.with",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw.with(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "read",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "read(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "read.with",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "read.with(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 7,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (103..104)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/completion/show2.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw: ",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw.where",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw.where(${1:}): ",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 15,
|
||||||
|
"label": "regex selector",
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "regex(\"${1:regex}\"): ${2:}",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 6,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (80..81)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 12,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw.where",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw.where(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 12,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw.with",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw.with(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 12,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "read",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "read(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 12,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "read.with",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "read.with(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 12,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (92..93)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 3,
|
||||||
|
"label": "raw.where",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
|
||||||
|
},
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "raw.where(${1:})",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 15,
|
||||||
|
"label": "replacement",
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "[${1:content}]",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 11,
|
||||||
|
"line": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -1,12 +1,52 @@
|
||||||
---
|
---
|
||||||
source: crates/tinymist-query/src/completion.rs
|
source: crates/tinymist-query/src/completion.rs
|
||||||
description: Completion on / (65..66)
|
description: Completion on / (63..64)
|
||||||
expression: "JsonRepr::new_pure(results)"
|
expression: "JsonRepr::new_pure(results)"
|
||||||
input_file: crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-current-heading.typ
|
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-heading.typ
|
||||||
---
|
---
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"isIncomplete": false,
|
"isIncomplete": false,
|
||||||
"items": []
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 15,
|
||||||
|
"label": "int",
|
||||||
|
"sortText": "001",
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "${1:integer}",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 24,
|
||||||
|
"line": 2
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 24,
|
||||||
|
"line": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": 7,
|
||||||
|
"label": "int",
|
||||||
|
"labelDetails": {
|
||||||
|
"description": "type"
|
||||||
|
},
|
||||||
|
"sortText": "125",
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "int",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 24,
|
||||||
|
"line": 2
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 24,
|
||||||
|
"line": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (58..59)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"kind": 21,
|
||||||
|
"label": "0",
|
||||||
|
"sortText": "000",
|
||||||
|
"textEdit": {
|
||||||
|
"newText": "0",
|
||||||
|
"range": {
|
||||||
|
"end": {
|
||||||
|
"character": 21,
|
||||||
|
"line": 2
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"character": 21,
|
||||||
|
"line": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
source: crates/tinymist-query/src/completion.rs
|
||||||
|
description: Completion on / (58..59)
|
||||||
|
expression: "JsonRepr::new_pure(results)"
|
||||||
|
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.typ
|
||||||
|
---
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"isIncomplete": false,
|
||||||
|
"items": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
#import "lib.typ": *
|
#import "lib.typ": *
|
||||||
#current-heading(/* range 0..1 */)[];
|
#current-heading(/* range 0..1 */)[];
|
||||||
-----
|
-----
|
||||||
/// contains: "body"
|
/// contains: int
|
||||||
#import "lib.typ": *
|
#import "lib.typ": *
|
||||||
#current-heading(level: /* range 0..1 */)[];
|
#current-heading(level: /* range 0..1 */)[];
|
||||||
-----
|
-----
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
/// path: lib.typ
|
||||||
|
|
||||||
|
/// Convert content to markup text, partly from
|
||||||
|
/// [typst-examples-book](https://sitandr.github.io/typst-examples-book/book/typstonomicon/extract_markup_text.html).
|
||||||
|
///
|
||||||
|
/// - it (content): The content to convert.
|
||||||
|
///
|
||||||
|
/// - mode (string): The mode of the markup text, either `typ` or `md`.
|
||||||
|
///
|
||||||
|
/// - indent (int): The number of spaces to indent. Default is `0`.
|
||||||
|
#let markup-text(it, mode: "typ", indent: 0) = {
|
||||||
|
assert(mode == "typ" or mode == "md", message: "mode must be 'typ' or 'md'")
|
||||||
|
let indent-markup-text = markup-text.with(mode: mode, indent: indent + 2)
|
||||||
|
let markup-text = markup-text.with(mode: mode, indent: indent)
|
||||||
|
if type(it) == str {
|
||||||
|
it
|
||||||
|
} else if type(it) == content {
|
||||||
|
if it.func() == raw {
|
||||||
|
if it.block {
|
||||||
|
"\n" + indent * " " + "```" + it.lang + it
|
||||||
|
.text
|
||||||
|
.split("\n")
|
||||||
|
.map(l => "\n" + indent * " " + l)
|
||||||
|
.sum(default: "") + "\n" + indent * " " + "```"
|
||||||
|
} else {
|
||||||
|
"`" + it.text + "`"
|
||||||
|
}
|
||||||
|
} else if it == [ ] {
|
||||||
|
" "
|
||||||
|
} else if it.func() == enum.item {
|
||||||
|
"\n" + indent * " " + "+ " + indent-markup-text(it.body)
|
||||||
|
} else if it.func() == list.item {
|
||||||
|
"\n" + indent * " " + "- " + indent-markup-text(it.body)
|
||||||
|
} else if it.func() == terms.item {
|
||||||
|
"\n" + indent * " " + "/ " + markup-text(it.term) + ": " + indent-markup-text(it.description)
|
||||||
|
} else if it.func() == linebreak {
|
||||||
|
"\n" + indent * " "
|
||||||
|
} else if it.func() == parbreak {
|
||||||
|
"\n\n" + indent * " "
|
||||||
|
} else if it.func() == strong {
|
||||||
|
if mode == "md" {
|
||||||
|
"**" + markup-text(it.body) + "**"
|
||||||
|
} else {
|
||||||
|
"*" + markup-text(it.body) + "*"
|
||||||
|
}
|
||||||
|
} else if it.func() == emph {
|
||||||
|
if mode == "md" {
|
||||||
|
"*" + markup-text(it.body) + "*"
|
||||||
|
} else {
|
||||||
|
"_" + markup-text(it.body) + "_"
|
||||||
|
}
|
||||||
|
} else if it.func() == link and type(it.dest) == str {
|
||||||
|
if mode == "md" {
|
||||||
|
"[" + markup-text(it.body) + "](" + it.dest + ")"
|
||||||
|
} else {
|
||||||
|
"#link(\"" + it.dest + "\")[" + markup-text(it.body) + "]"
|
||||||
|
}
|
||||||
|
} else if it.func() == heading {
|
||||||
|
if mode == "md" {
|
||||||
|
it.depth * "#" + " " + markup-text(it.body) + "\n"
|
||||||
|
} else {
|
||||||
|
it.depth * "=" + " " + markup-text(it.body) + "\n"
|
||||||
|
}
|
||||||
|
} else if it.has("children") {
|
||||||
|
it.children.map(markup-text).join()
|
||||||
|
} else if it.has("body") {
|
||||||
|
markup-text(it.body)
|
||||||
|
} else if it.has("text") {
|
||||||
|
if type(it.text) == str {
|
||||||
|
it.text
|
||||||
|
} else {
|
||||||
|
markup-text(it.text)
|
||||||
|
}
|
||||||
|
} else if it.func() == smartquote {
|
||||||
|
if it.double {
|
||||||
|
"\""
|
||||||
|
} else {
|
||||||
|
"'"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
repr(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-----
|
||||||
|
/// contains: typ
|
||||||
|
#import "lib.typ": *
|
||||||
|
#markup-text(mode: /* range 0..1 */)[];
|
||||||
|
-----
|
||||||
|
/// contains: 0
|
||||||
|
#import "lib.typ": *
|
||||||
|
#markup-text(indent: /* range 0..1 */)[];
|
||||||
|
|
@ -166,7 +166,7 @@ pub fn find_test_range(s: &Source) -> Range<usize> {
|
||||||
}
|
}
|
||||||
let (re_base, re_len, is_after) = find_prefix(s.text(), "/* range after ", true)
|
let (re_base, re_len, is_after) = find_prefix(s.text(), "/* range after ", true)
|
||||||
.or_else(|| find_prefix(s.text(), "/* range ", false))
|
.or_else(|| find_prefix(s.text(), "/* range ", false))
|
||||||
.unwrap();
|
.unwrap_or_else(|| panic!("no range marker found in source:\n{}", s.text()));
|
||||||
let re_end = re_base + re_len;
|
let re_end = re_base + re_len;
|
||||||
let range_rng = re_end..(s.text()[re_end..].find(" */").unwrap() + re_end);
|
let range_rng = re_end..(s.text()[re_end..].find(" */").unwrap() + re_end);
|
||||||
let range_base = if is_after {
|
let range_base = if is_after {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue