summaryrefslogtreecommitdiff
path: root/tests/typ/meta
diff options
context:
space:
mode:
authorSébastien d'Herbais de Thun <sebastien.d.herbais@gmail.com>2023-04-12 12:47:51 +0200
committerGitHub <noreply@github.com>2023-04-12 12:47:51 +0200
commit1198e0cd385737efc38dbd8ba13db802a68e0dc7 (patch)
treead15c6173f196cc6df30faca1e94bac2aa400894 /tests/typ/meta
parentfe2640c55268f167d8749f77b37e52b7b17f21dd (diff)
Selector rework (#640)
Diffstat (limited to 'tests/typ/meta')
-rw-r--r--tests/typ/meta/query-before-after.typ69
-rw-r--r--tests/typ/meta/query.typ6
2 files changed, 72 insertions, 3 deletions
diff --git a/tests/typ/meta/query-before-after.typ b/tests/typ/meta/query-before-after.typ
new file mode 100644
index 00000000..734e84b4
--- /dev/null
+++ b/tests/typ/meta/query-before-after.typ
@@ -0,0 +1,69 @@
+
+---
+#set page(
+ paper: "a7",
+ numbering: "1 / 1",
+ margin: (bottom: 1cm, rest: 0.5cm),
+)
+
+#show heading.where(level: 1, outlined: true): it => [
+ #it
+
+ #set text(size: 12pt, weight: "regular")
+ #outline(
+ title: "Chapter outline",
+ indent: true,
+ target: heading
+ .where(level: 1)
+ .or(heading.where(level: 2))
+ .after(it.location(), inclusive: true)
+ .before(
+ heading
+ .where(level: 1, outlined: true)
+ .after(it.location(), inclusive: false),
+ inclusive: false,
+ )
+ )
+]
+
+#set heading(outlined: true, numbering: "1.")
+
+= Section 1
+== Subsection 1
+== Subsection 2
+=== Subsubsection 1
+=== Subsubsection 2
+== Subsection 3
+= Section 2
+== Subsection 1
+== Subsection 2
+
+= Section 3
+== Subsection 1
+== Subsection 2
+=== Subsubsection 1
+=== Subsubsection 2
+=== Subsubsection 3
+== Subsection 3
+
+---
+
+#set page(
+ paper: "a7",
+ numbering: "1 / 1",
+ margin: (bottom: 1cm, rest: 0.5cm),
+)
+
+#set heading(outlined: true, numbering: "1.")
+
+// This is purposefully an empty
+#locate(loc => [
+ Non-outlined elements:
+ #(query(selector(heading).and(heading.where(outlined: false)), loc)
+ .map(it => it.body).join(", "))
+])
+
+#heading("A", outlined: false)
+#heading("B", outlined: true)
+#heading("C", outlined: true)
+#heading("D", outlined: false)
diff --git a/tests/typ/meta/query.typ b/tests/typ/meta/query.typ
index 7dfbbcfc..91325b61 100644
--- a/tests/typ/meta/query.typ
+++ b/tests/typ/meta/query.typ
@@ -8,8 +8,8 @@
smallcaps[Typst Academy]
h(1fr)
locate(it => {
- let after = query(heading, after: it)
- let before = query(heading, before: it)
+ let after = query(selector(heading).after(it), it)
+ let before = query(selector(heading).before(it), it)
let elem = if before.len() != 0 {
before.last()
} else if after.len() != 0 {
@@ -43,7 +43,7 @@
= List of Figures
#locate(it => {
- let elements = query(figure, after: it)
+ let elements = query(selector(figure).after(it), it)
for it in elements [
Figure
#numbering(it.numbering,