Make QuoteElem locatable (#4909)

This commit is contained in:
Yip Coekjan 2024-09-08 16:29:58 +08:00 committed by GitHub
parent 4cddb48584
commit 40fcd97d58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 5 deletions

View File

@ -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);

View File

@ -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.
///

BIN
tests/ref/query-quote.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -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()