From 40fcd97d584fc1dfa6446bc4922d3b1e440e0afd Mon Sep 17 00:00:00 2001 From: Yip Coekjan <69834864+Coekjan@users.noreply.github.com> Date: Sun, 8 Sep 2024 16:29:58 +0800 Subject: [PATCH] Make `QuoteElem` locatable (#4909) --- crates/typst/src/introspection/location.rs | 8 ++++---- crates/typst/src/model/quote.rs | 3 ++- tests/ref/query-quote.png | Bin 0 -> 1368 bytes tests/suite/introspection/query.typ | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 tests/ref/query-quote.png diff --git a/crates/typst/src/introspection/location.rs b/crates/typst/src/introspection/location.rs index 5cd6aae05..70076bcaa 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 ff6ae1108..160d96d62 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 0000000000000000000000000000000000000000..e21365928303b6c9473b39c777f8f30c72e6810b GIT binary patch literal 1368 zcmV-e1*iInP)W8L&s~Kk+{UM!XGQ~=rywC6~&&-rGWV{xG!Nl^Ycm3tvY zH%okm21nSX#xba{NwPrsTo(egOFVSAy4e z>j8k#R+4Tf>;QsRTDZ4n$Z)EAG4)4%)7?(RB|uMrGNKItXbeuQ%yD}R0P5WV7hR0r z9;HCW5modf(Od!+uz+7WxR<^Wf%6_*=>dHU+)q{)n1RZult(DCy@nYMJu|Nrw)#Tn z1Wo=-I2&%xortRb%rL{)Y*3pp9dIx(!&>q+kY>IA@Ua}j^}WqW2M!mUeK{W}<5c&q zRl2x?gTeY)+(~~K;gD(uCJ*3XAl6ws4d}7R0$0p!p>t_K)!1O&W)1$^wAZ7N1+Fh` z##CBTS5{JM158?zs7wJ1Sik}nuz&?DU;zvGIpN3^@f2-1R=DYKjk~i!MwqvOm0H%{ zA?91;gzbR!5BN&UwS%(4W0XqeM}zRoapKXyDji?saqW<-Q$0T(&8oviYYv#hei)JO zxJGlRZA9R@B9?LUAwU$$+}Rs zHFeLaKVhjhwl`}_BJ<^e+utzR=0p#y32HieV^0f{j4Uw90;eWqP^-#SB_^usRRz>i zr%D&iC13#ySik}nuz&?DU;+O-IA&i0=S~+MKG6v&Cji@#GFf2TTXcE$vGpgQ|FvRB zk!^P}`}GelZOv{9h+QlbJjOnoLHOQX`<}9rMRJ|EW?IW2oZRg5V*(3gg2$3G+sy7X zno~mtnkHwk$R-OMIVv8{joGueo}ZVo{5tLfbu*(xfe2W@0v51<1uWpwDcA zM=EETQ_FuJ{yWaUVV{N%^QwTgX*x#|zX6Z|&Z-)#_rb0K*cqdnAF1q@3r0P~gLOB7 zB^5eHKpt4F2G6Nf%rTO?pUmZQ!M*-xyCDIZ17kBW2YBBS%_U#~3s}Ja2)9~HBLb&a zU$TTf0BuAjPvS$hn8QQEQ<0WkJ3G8^tpBpss8J2@rMYo)x8&u8dO2Zk1ero)_#bbY zZo!9LnZTqfog*c4%uRYp1~|)OCqCFW0Zwtc)m1Jx0OWuN7KZsSwH$C#>sDx + +#context query().first()