summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYip Coekjan <69834864+Coekjan@users.noreply.github.com>2024-09-08 16:29:58 +0800
committerGitHub <noreply@github.com>2024-09-08 08:29:58 +0000
commit40fcd97d584fc1dfa6446bc4922d3b1e440e0afd (patch)
tree29d0439aad5fc5a0301f058c7153cfc4b74a30b9
parent4cddb485847e01f62cc1fe65d37028a87df52daa (diff)
Make `QuoteElem` locatable (#4909)
-rw-r--r--crates/typst/src/introspection/location.rs8
-rw-r--r--crates/typst/src/model/quote.rs3
-rw-r--r--tests/ref/query-quote.pngbin0 -> 1368 bytes
-rw-r--r--tests/suite/introspection/query.typ16
4 files changed, 22 insertions, 5 deletions
diff --git a/crates/typst/src/introspection/location.rs b/crates/typst/src/introspection/location.rs
index 5cd6aae0..70076bca 100644
--- a/crates/typst/src/introspection/location.rs
+++ b/crates/typst/src/introspection/location.rs
@@ -17,10 +17,10 @@ use crate::model::Numbering;
///
/// # Locatable elements { #locatable }
/// Currently, only a subset of element functions is locatable. Aside from
-/// headings and figures, this includes equations, references and all elements
-/// with an explicit label. As a result, you _can_ query for e.g. [`strong`]
-/// elements, but you will find only those that have an explicit label attached
-/// to them. This limitation will be resolved in the future.
+/// headings and figures, this includes equations, references, quotes and all
+/// elements with an explicit label. As a result, you _can_ query for e.g.
+/// [`strong`] elements, but you will find only those that have an explicit
+/// label attached to them. This limitation will be resolved in the future.
#[ty(scope)]
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct Location(u128);
diff --git a/crates/typst/src/model/quote.rs b/crates/typst/src/model/quote.rs
index ff6ae110..160d96d6 100644
--- a/crates/typst/src/model/quote.rs
+++ b/crates/typst/src/model/quote.rs
@@ -4,6 +4,7 @@ use crate::foundations::{
cast, elem, Content, Depth, Label, NativeElement, Packed, Show, ShowSet, Smart,
StyleChain, Styles,
};
+use crate::introspection::Locatable;
use crate::layout::{
Alignment, BlockChild, BlockElem, Em, HElem, PadElem, Spacing, VElem,
};
@@ -42,7 +43,7 @@ use crate::text::{SmartQuoteElem, SmartQuotes, SpaceElem, TextElem};
/// flame of Udûn. Go back to the Shadow! You cannot pass.
/// ]
/// ```
-#[elem(ShowSet, Show)]
+#[elem(Locatable, ShowSet, Show)]
pub struct QuoteElem {
/// Whether this is a block quote.
///
diff --git a/tests/ref/query-quote.png b/tests/ref/query-quote.png
new file mode 100644
index 00000000..e2136592
--- /dev/null
+++ b/tests/ref/query-quote.png
Binary files differ
diff --git a/tests/suite/introspection/query.typ b/tests/suite/introspection/query.typ
index 76ecc913..3d71529e 100644
--- a/tests/suite/introspection/query.typ
+++ b/tests/suite/introspection/query.typ
@@ -281,3 +281,19 @@
// New show rules apply to this, but its location and the materialized fields
// from the original are retained.
#context query(heading).join()
+
+--- query-quote ---
+// Test quoting a query.
+
+#quote[ABC] & #quote[EFG]
+
+#context query(selector(quote).before(here())).first()
+
+#quote(block: true)[HIJ]
+#quote(block: true)[KLM]
+
+#context query(selector(quote).before(here())).last()
+
+#quote[NOP] <nop>
+
+#context query(<nop>).first()