mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Test recursive show rules
This commit is contained in:
parent
d59109e8ff
commit
e18a896a93
@ -117,7 +117,7 @@ impl Dict {
|
|||||||
/// The missing key access error message.
|
/// The missing key access error message.
|
||||||
#[cold]
|
#[cold]
|
||||||
fn missing_key(key: &EcoString) -> String {
|
fn missing_key(key: &EcoString) -> String {
|
||||||
format!("dictionary does not contain key: {:?}", key)
|
format!("dictionary does not contain key {:?}", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for Dict {
|
impl Debug for Dict {
|
||||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
BIN
tests/ref/style/show-node.png
Normal file
BIN
tests/ref/style/show-node.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
tests/ref/style/show-recursive.png
Normal file
BIN
tests/ref/style/show-recursive.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
@ -23,7 +23,7 @@
|
|||||||
// Test rvalue missing key.
|
// Test rvalue missing key.
|
||||||
{
|
{
|
||||||
let dict = (a: 1, b: 2)
|
let dict = (a: 1, b: 2)
|
||||||
// Error: 11-20 dictionary does not contain key: "c"
|
// Error: 11-20 dictionary does not contain key "c"
|
||||||
let x = dict("c")
|
let x = dict("c")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
---
|
---
|
||||||
// Error: 6-13 dictionary does not contain key: "invalid"
|
// Error: 6-13 dictionary does not contain key "invalid"
|
||||||
{(:).invalid}
|
{(:).invalid}
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Test class construction.
|
// Test node functions.
|
||||||
|
|
||||||
---
|
---
|
||||||
// Ensure that constructor styles aren't passed down the tree.
|
// Ensure that constructor styles aren't passed down the tree.
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
// Test that set affects the instantiation site and not the
|
|
||||||
// definition site of a content.
|
|
||||||
|
|
||||||
---
|
|
||||||
// Test that text is affected by instantiation-site bold.
|
|
||||||
#let x = [World]
|
|
||||||
Hello *{x}*
|
|
||||||
|
|
||||||
---
|
|
||||||
// Test that lists are affected by correct indents.
|
|
||||||
#let fruit = [
|
|
||||||
- Apple
|
|
||||||
- Orange
|
|
||||||
#list(body-indent: 20pt, [Pear])
|
|
||||||
]
|
|
||||||
|
|
||||||
- Fruit
|
|
||||||
[#set list(indent: 10pt)
|
|
||||||
#fruit]
|
|
||||||
- No more fruit
|
|
||||||
|
|
||||||
---
|
|
||||||
// Test that that par spacing and text style are respected from
|
|
||||||
// the outside, but the more specific fill is respected.
|
|
||||||
#set par(spacing: 4pt)
|
|
||||||
#set text(style: "italic", fill: eastern)
|
|
||||||
#let x = [And the forest #parbreak() lay silent!]
|
|
||||||
#text(fill: forest, x)
|
|
@ -1,5 +1,30 @@
|
|||||||
// General tests for set.
|
// General tests for set.
|
||||||
// Ref: false
|
|
||||||
|
---
|
||||||
|
// Test that text is affected by instantiation-site bold.
|
||||||
|
#let x = [World]
|
||||||
|
Hello *{x}*
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test that lists are affected by correct indents.
|
||||||
|
#let fruit = [
|
||||||
|
- Apple
|
||||||
|
- Orange
|
||||||
|
#list(body-indent: 20pt, [Pear])
|
||||||
|
]
|
||||||
|
|
||||||
|
- Fruit
|
||||||
|
[#set list(indent: 10pt)
|
||||||
|
#fruit]
|
||||||
|
- No more fruit
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test that that par spacing and text style are respected from
|
||||||
|
// the outside, but the more specific fill is respected.
|
||||||
|
#set par(spacing: 4pt)
|
||||||
|
#set text(style: "italic", fill: eastern)
|
||||||
|
#let x = [And the forest #parbreak() lay silent!]
|
||||||
|
#text(fill: forest, x)
|
||||||
|
|
||||||
---
|
---
|
||||||
// Error: 2-10 set, show and wrap are only allowed directly in markup
|
// Error: 2-10 set, show and wrap are only allowed directly in markup
|
||||||
|
67
tests/typ/style/show-node.typ
Normal file
67
tests/typ/style/show-node.typ
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Test node show rules.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Override lists.
|
||||||
|
#set list(around: none)
|
||||||
|
#show v: list as "(" + v.items.join(", ") + ")"
|
||||||
|
|
||||||
|
- A
|
||||||
|
- B
|
||||||
|
- C
|
||||||
|
- D
|
||||||
|
- E
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test full reset.
|
||||||
|
#set heading(size: 1em, strong: false, around: none)
|
||||||
|
#show heading as [B]
|
||||||
|
A [= Heading] C
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test full removal.
|
||||||
|
#show heading as []
|
||||||
|
#set heading(around: none)
|
||||||
|
|
||||||
|
Where is
|
||||||
|
= There are not headings around here!
|
||||||
|
my heading?
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test integrated example.
|
||||||
|
#set heading(size: 1em)
|
||||||
|
#show node: heading as {
|
||||||
|
move(dy: -1pt)[📖]
|
||||||
|
h(5pt)
|
||||||
|
if node.level == 1 {
|
||||||
|
underline(text(1.25em, blue, node.body))
|
||||||
|
} else {
|
||||||
|
text(red, node.body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
= Task 1
|
||||||
|
Some text.
|
||||||
|
|
||||||
|
== Subtask
|
||||||
|
Some more text.
|
||||||
|
|
||||||
|
= Task 2
|
||||||
|
Another text.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Error: 18-22 expected content, found string
|
||||||
|
#show heading as "hi"
|
||||||
|
= Heading
|
||||||
|
|
||||||
|
---
|
||||||
|
// Error: 25-29 unknown field "page"
|
||||||
|
#show it: heading as it.page
|
||||||
|
= Heading
|
||||||
|
|
||||||
|
---
|
||||||
|
// Error: 10-15 this function cannot be customized with show
|
||||||
|
#show _: upper as {}
|
||||||
|
|
||||||
|
---
|
||||||
|
// Error: 2-16 set, show and wrap are only allowed directly in markup
|
||||||
|
{show list as a}
|
65
tests/typ/style/show-recursive.typ
Normal file
65
tests/typ/style/show-recursive.typ
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Test recursive show rules.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test basic identity.
|
||||||
|
#show it: heading as it
|
||||||
|
= Heading
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test more recipes down the chain.
|
||||||
|
#show it: list as scale(origin: left, x: 80%, it)
|
||||||
|
#show heading as []
|
||||||
|
#show enum as []
|
||||||
|
- Actual
|
||||||
|
- Tight
|
||||||
|
- List
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test recursive base recipe. (Burn it with fire!)
|
||||||
|
#set list(label: [- Hey])
|
||||||
|
- Labelless
|
||||||
|
- List
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test show rule in function.
|
||||||
|
#let starwars(body) = [
|
||||||
|
#show v: list as {
|
||||||
|
stack(dir: ltr,
|
||||||
|
text(red, v),
|
||||||
|
1fr,
|
||||||
|
scale(x: -100%, text(blue, v)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
#body
|
||||||
|
]
|
||||||
|
|
||||||
|
- Normal list
|
||||||
|
#starwars[
|
||||||
|
- Star
|
||||||
|
- Wars
|
||||||
|
- List
|
||||||
|
]
|
||||||
|
- Normal list
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test multi-recursion with nested lists.
|
||||||
|
#set rect(padding: 2pt)
|
||||||
|
#show v: list as rect(stroke: blue, v)
|
||||||
|
#show v: list as rect(stroke: red, v)
|
||||||
|
|
||||||
|
- List
|
||||||
|
- Nested
|
||||||
|
- List
|
||||||
|
- Recursive!
|
||||||
|
|
||||||
|
---
|
||||||
|
// Inner heading is not finalized. Bug?
|
||||||
|
#set heading(around: none)
|
||||||
|
#show it: heading as it.body
|
||||||
|
#show heading as [
|
||||||
|
= A [
|
||||||
|
= B
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
= Discarded
|
@ -1,52 +0,0 @@
|
|||||||
// Test show rules.
|
|
||||||
|
|
||||||
#set page("a8", footer: p => v(-5pt) + align(right, [#p]))
|
|
||||||
|
|
||||||
#let i = 1
|
|
||||||
#set heading(size: 1em)
|
|
||||||
#show node: heading as {
|
|
||||||
if node.level == 1 {
|
|
||||||
v(10pt)
|
|
||||||
underline(text(1.5em, blue)[{i}. {node.body}])
|
|
||||||
i += 1
|
|
||||||
} else {
|
|
||||||
text(red, node.body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#v(-10pt)
|
|
||||||
|
|
||||||
= Aufgabe
|
|
||||||
Some text.
|
|
||||||
|
|
||||||
== Subtask
|
|
||||||
Some more text.
|
|
||||||
|
|
||||||
== Another subtask
|
|
||||||
Some more text.
|
|
||||||
|
|
||||||
= Aufgabe
|
|
||||||
Another text.
|
|
||||||
|
|
||||||
---
|
|
||||||
#set heading(size: 1em, strong: false, around: none)
|
|
||||||
#show _: heading as [B]
|
|
||||||
A [= Heading] C
|
|
||||||
|
|
||||||
---
|
|
||||||
// Error: 21-25 expected content, found string
|
|
||||||
#show _: heading as "hi"
|
|
||||||
= Heading
|
|
||||||
|
|
||||||
---
|
|
||||||
// Error: 22-29 dictionary does not contain key: "page"
|
|
||||||
#show it: heading as it.page
|
|
||||||
= Heading
|
|
||||||
|
|
||||||
---
|
|
||||||
// Error: 10-15 this function cannot be customized with show
|
|
||||||
#show _: upper as {}
|
|
||||||
|
|
||||||
---
|
|
||||||
// Error: 2-19 set, show and wrap are only allowed directly in markup
|
|
||||||
{show a: list as a}
|
|
Loading…
x
Reference in New Issue
Block a user