feat: [WIP] make more things locatable

skip-checks:true
This commit is contained in:
Tobias Schmitz 2025-05-27 15:55:04 +02:00
parent c8f0e86e75
commit 3f131e9c26
No known key found for this signature in database
23 changed files with 58 additions and 40 deletions

View File

@ -7,6 +7,7 @@ pub use self::dom::*;
use ecow::EcoString;
use crate::foundations::{elem, Content, Module, Scope};
use crate::introspection::Locatable;
/// Create a module with all HTML definitions.
pub fn module() -> Module {
@ -38,7 +39,7 @@ pub fn module() -> Module {
/// A div with _Typst content_ inside!
/// ]
/// ```
#[elem(name = "elem")]
#[elem(name = "elem", Locatable)]
pub struct HtmlElem {
/// The element's tag.
#[required]

View File

@ -388,6 +388,8 @@ impl IntrospectorBuilder {
);
}
dbg!(elems.len());
self.finalize(elems)
}

View File

@ -13,6 +13,7 @@ use crate::foundations::{
cast, elem, scope, Array, CastInfo, Content, Context, Fold, FromValue, Func,
IntoValue, NativeElement, Packed, Reflect, Resolve, Show, Smart, StyleChain, Value,
};
use crate::introspection::Locatable;
use crate::layout::{
Alignment, BlockElem, Length, OuterHAlignment, OuterVAlignment, Rel, Sides, Sizing,
};
@ -136,7 +137,7 @@ use crate::visualize::{Paint, Stroke};
///
/// Furthermore, strokes of a repeated grid header or footer will take
/// precedence over regular cell strokes.
#[elem(scope, Show)]
#[elem(scope, Locatable, Show)]
pub struct GridElem {
/// The column sizes.
///
@ -462,7 +463,7 @@ impl TryFrom<Content> for GridItem {
/// If `repeat` is set to `true`, the header will be repeated across pages. For
/// an example, refer to the [`table.header`]($table.header) element and the
/// [`grid.stroke`]($grid.stroke) parameter.
#[elem(name = "header", title = "Grid Header")]
#[elem(name = "header", title = "Grid Header", Locatable)]
pub struct GridHeader {
/// Whether this header should be repeated across pages.
#[default(true)]
@ -490,7 +491,7 @@ pub struct GridHeader {
/// itself on every page of the table.
///
/// No other grid cells may be placed after the footer.
#[elem(name = "footer", title = "Grid Footer")]
#[elem(name = "footer", title = "Grid Footer", Locatable)]
pub struct GridFooter {
/// Whether this footer should be repeated across pages.
#[default(true)]
@ -657,7 +658,7 @@ pub struct GridVLine {
/// which allows you, for example, to apply styles based on a cell's position.
/// Refer to the examples of the [`table.cell`]($table.cell) element to learn
/// more about this.
#[elem(name = "cell", title = "Grid Cell", Show)]
#[elem(name = "cell", title = "Grid Cell", Locatable, Show)]
pub struct GridCell {
/// The cell's body.
#[required]

View File

@ -1,6 +1,7 @@
use crate::diag::SourceResult;
use crate::engine::Engine;
use crate::foundations::{elem, Content, Packed, Show, StyleChain};
use crate::introspection::Locatable;
/// Hides content without affecting layout.
///
@ -14,7 +15,7 @@ use crate::foundations::{elem, Content, Packed, Show, StyleChain};
/// Hello Jane \
/// #hide[Hello] Joe
/// ```
#[elem(Show)]
#[elem(Locatable, Show)]
pub struct HideElem {
/// The content to hide.
#[required]

View File

@ -1,6 +1,7 @@
use crate::diag::SourceResult;
use crate::engine::Engine;
use crate::foundations::{elem, Content, NativeElement, Packed, Show, StyleChain};
use crate::introspection::Locatable;
use crate::layout::{BlockElem, Length};
/// Repeats content to the available space.
@ -24,7 +25,7 @@ use crate::layout::{BlockElem, Length};
/// Berlin, the 22nd of December, 2022
/// ]
/// ```
#[elem(Show)]
#[elem(Locatable, Show)]
pub struct RepeatElem {
/// The content to repeat.
#[required]

View File

@ -28,6 +28,7 @@ use typst_utils::singleton;
use unicode_math_class::MathClass;
use crate::foundations::{elem, Content, Module, NativeElement, Scope};
use crate::introspection::Locatable;
use crate::layout::{Em, HElem};
use crate::text::TextElem;
@ -109,7 +110,7 @@ pub fn module() -> Module {
pub trait Mathy {}
/// A math alignment point: `&`, `&&`.
#[elem(title = "Alignment Point", Mathy)]
#[elem(title = "Alignment Point", Mathy, Locatable)]
pub struct AlignPointElem {}
impl AlignPointElem {
@ -136,7 +137,7 @@ impl AlignPointElem {
///
/// $x loves y and y loves 5$
/// ```
#[elem(Mathy)]
#[elem(Mathy, Locatable)]
pub struct ClassElem {
/// The class to apply to the content.
#[required]

View File

@ -1,6 +1,7 @@
use typst_syntax::Span;
use crate::foundations::{elem, func, Content, NativeElement};
use crate::introspection::Locatable;
use crate::math::Mathy;
/// A square root.
@ -22,7 +23,7 @@ pub fn sqrt(
/// ```example
/// $ root(3, x) $
/// ```
#[elem(Mathy)]
#[elem(Mathy, Locatable)]
pub struct RootElem {
/// Which root of the radicand to take.
#[positional]

View File

@ -43,7 +43,7 @@ use crate::text::{Lang, Region, TextElem};
/// This function indirectly has dedicated syntax. [References]($ref) can be
/// used to cite works from the bibliography. The label then corresponds to the
/// citation key.
#[elem(Synthesize)]
#[elem(Locatable, Synthesize)]
pub struct CiteElem {
/// The citation key that identifies the entry in the bibliography that
/// shall be cited, as a label.

View File

@ -4,6 +4,7 @@ use crate::foundations::{
elem, Content, NativeElement, Packed, Show, StyleChain, TargetElem,
};
use crate::html::{tag, HtmlElem};
use crate::introspection::Locatable;
use crate::text::{ItalicToggle, TextElem};
/// Emphasizes content by toggling italics.
@ -29,7 +30,7 @@ use crate::text::{ItalicToggle, TextElem};
/// This function also has dedicated syntax: To emphasize content, simply
/// enclose it in underscores (`_`). Note that this only works at word
/// boundaries. To emphasize part of a word, you have to use the function.
#[elem(title = "Emphasis", keywords = ["italic"], Show)]
#[elem(title = "Emphasis", keywords = ["italic"], Locatable, Show)]
pub struct EmphElem {
/// The content to emphasize.
#[required]

View File

@ -10,6 +10,7 @@ use crate::foundations::{
Styles, TargetElem,
};
use crate::html::{attr, tag, HtmlElem};
use crate::introspection::Locatable;
use crate::layout::{Alignment, BlockElem, Em, HAlignment, Length, VAlignment, VElem};
use crate::model::{
ListItemLike, ListLike, Numbering, NumberingPattern, ParElem, ParbreakElem,
@ -71,7 +72,7 @@ use crate::model::{
/// Enumeration items can contain multiple paragraphs and other block-level
/// content. All content that is indented more than an item's marker becomes
/// part of that item.
#[elem(scope, title = "Numbered List", Show)]
#[elem(scope, title = "Numbered List", Locatable, Show)]
pub struct EnumElem {
/// Defines the default [spacing]($enum.spacing) of the enumeration. If it
/// is `{false}`, the items are spaced apart with
@ -271,7 +272,7 @@ impl Show for Packed<EnumElem> {
}
/// An enumeration item.
#[elem(name = "item", title = "Numbered List Item")]
#[elem(name = "item", title = "Numbered List Item", Locatable)]
pub struct EnumItem {
/// The item's number.
#[positional]

View File

@ -473,7 +473,7 @@ impl Outlinable for Packed<FigureElem> {
/// caption: [A rectangle],
/// )
/// ```
#[elem(name = "caption", Synthesize, Show)]
#[elem(name = "caption", Locatable, Synthesize, Show)]
pub struct FigureCaption {
/// The caption's position in the figure. Either `{top}` or `{bottom}`.
///

View File

@ -192,7 +192,7 @@ cast! {
/// page run is a sequence of pages without an explicit pagebreak in between).
/// For this reason, set and show rules for footnote entries should be defined
/// before any page content, typically at the very start of the document.
#[elem(name = "entry", title = "Footnote Entry", Show, ShowSet)]
#[elem(name = "entry", title = "Footnote Entry", Locatable, Show, ShowSet)]
pub struct FootnoteEntry {
/// The footnote for this entry. Its location can be used to determine
/// the footnote counter state.

View File

@ -9,7 +9,7 @@ use crate::foundations::{
StyleChain, Styles, TargetElem,
};
use crate::html::{attr, tag, HtmlElem};
use crate::introspection::Location;
use crate::introspection::{Locatable, Location};
use crate::layout::Position;
use crate::text::TextElem;
@ -38,7 +38,7 @@ use crate::text::TextElem;
/// # Syntax
/// This function also has dedicated syntax: Text that starts with `http://` or
/// `https://` is automatically turned into a link.
#[elem(Show)]
#[elem(Locatable, Show)]
pub struct LinkElem {
/// The destination the link points to.
///

View File

@ -7,6 +7,7 @@ use crate::foundations::{
Smart, StyleChain, Styles, TargetElem, Value,
};
use crate::html::{tag, HtmlElem};
use crate::introspection::Locatable;
use crate::layout::{BlockElem, Em, Length, VElem};
use crate::model::{ParElem, ParbreakElem};
use crate::text::TextElem;
@ -42,7 +43,7 @@ use crate::text::TextElem;
/// followed by a space to create a list item. A list item can contain multiple
/// paragraphs and other block-level content. All content that is indented
/// more than an item's marker becomes part of that item.
#[elem(scope, title = "Bullet List", Show)]
#[elem(scope, title = "Bullet List", Locatable, Show)]
pub struct ListElem {
/// Defines the default [spacing]($list.spacing) of the list. If it is
/// `{false}`, the items are spaced apart with
@ -178,7 +179,7 @@ impl Show for Packed<ListElem> {
}
/// A bullet list item.
#[elem(name = "item", title = "Bullet List Item")]
#[elem(name = "item", title = "Bullet List Item", Locatable)]
pub struct ListItem {
/// The item's body.
#[required]

View File

@ -368,7 +368,7 @@ pub trait Outlinable: Refable {
/// With show-set and show rules on outline entries, you can richly customize
/// the outline's appearance. See the
/// [section on styling the outline]($outline/#styling-the-outline) for details.
#[elem(scope, name = "entry", title = "Outline Entry", Show)]
#[elem(scope, name = "entry", title = "Outline Entry", Locatable, Show)]
pub struct OutlineEntry {
/// The nesting level of this outline entry. Starts at `{1}` for top-level
/// entries.

View File

@ -93,7 +93,7 @@ use crate::model::Numbering;
/// let $a$ be the smallest of the
/// three integers. Then, we ...
/// ```
#[elem(scope, title = "Paragraph")]
#[elem(scope, title = "Paragraph", Locatable)]
pub struct ParElem {
/// The spacing between lines.
///

View File

@ -4,6 +4,7 @@ use crate::foundations::{
elem, Content, NativeElement, Packed, Show, StyleChain, TargetElem,
};
use crate::html::{tag, HtmlElem};
use crate::introspection::Locatable;
use crate::text::{TextElem, WeightDelta};
/// Strongly emphasizes content by increasing the font weight.
@ -24,7 +25,7 @@ use crate::text::{TextElem, WeightDelta};
/// simply enclose it in stars/asterisks (`*`). Note that this only works at
/// word boundaries. To strongly emphasize part of a word, you have to use the
/// function.
#[elem(title = "Strong Emphasis", keywords = ["bold", "weight"], Show)]
#[elem(title = "Strong Emphasis", keywords = ["bold", "weight"], Locatable, Show)]
pub struct StrongElem {
/// The delta to apply on the font weight.
///

View File

@ -10,7 +10,7 @@ use crate::foundations::{
TargetElem,
};
use crate::html::{attr, tag, HtmlAttrs, HtmlElem, HtmlTag};
use crate::introspection::Locator;
use crate::introspection::{Locatable, Locator};
use crate::layout::grid::resolve::{table_to_cellgrid, Cell, CellGrid, Entry};
use crate::layout::{
show_grid_cell, Abs, Alignment, BlockElem, Celled, GridCell, GridFooter, GridHLine,
@ -121,7 +121,7 @@ use crate::visualize::{Paint, Stroke};
/// [Robert], b, a, b,
/// )
/// ```
#[elem(scope, Show, LocalName, Figurable)]
#[elem(scope, Locatable, Show, LocalName, Figurable)]
pub struct TableElem {
/// The column sizes. See the [grid documentation]($grid) for more
/// information on track sizing.
@ -531,7 +531,7 @@ impl TryFrom<Content> for TableItem {
/// [7.34], [57], [2],
/// )
/// ```
#[elem(name = "header", title = "Table Header")]
#[elem(name = "header", title = "Table Header", Locatable)]
pub struct TableHeader {
/// Whether this header should be repeated across pages.
#[default(true)]
@ -561,7 +561,7 @@ pub struct TableHeader {
/// totals, or other information that should be visible on every page.
///
/// No other table cells may be placed after the footer.
#[elem(name = "footer", title = "Table Footer")]
#[elem(name = "footer", title = "Table Footer", Locatable)]
pub struct TableFooter {
/// Whether this footer should be repeated across pages.
#[default(true)]
@ -604,7 +604,7 @@ pub struct TableFooter {
/// [19:00], [Day 1 Attendee Mixer],
/// )
/// ```
#[elem(name = "hline", title = "Table Horizontal Line")]
#[elem(name = "hline", title = "Table Horizontal Line", Locatable)]
pub struct TableHLine {
/// The row above which the horizontal line is placed (zero-indexed).
/// Functions identically to the `y` field in [`grid.hline`]($grid.hline.y).
@ -649,7 +649,7 @@ pub struct TableHLine {
/// use the [table's `stroke`]($table.stroke) field or [`table.cell`'s
/// `stroke`]($table.cell.stroke) field instead if the line you want to place is
/// part of all your tables' designs.
#[elem(name = "vline", title = "Table Vertical Line")]
#[elem(name = "vline", title = "Table Vertical Line", Locatable)]
pub struct TableVLine {
/// The column before which the horizontal line is placed (zero-indexed).
/// Functions identically to the `x` field in [`grid.vline`]($grid.vline).
@ -770,7 +770,7 @@ pub struct TableVLine {
/// [Vikram], [49], [Perseverance],
/// )
/// ```
#[elem(name = "cell", title = "Table Cell", Show)]
#[elem(name = "cell", title = "Table Cell", Locatable, Show)]
pub struct TableCell {
/// The cell's body.
#[required]

View File

@ -7,6 +7,7 @@ use crate::foundations::{
Styles, TargetElem,
};
use crate::html::{tag, HtmlElem};
use crate::introspection::Locatable;
use crate::layout::{Em, HElem, Length, Sides, StackChild, StackElem, VElem};
use crate::model::{ListItemLike, ListLike, ParElem, ParbreakElem};
use crate::text::TextElem;
@ -27,7 +28,7 @@ use crate::text::TextElem;
/// # Syntax
/// This function also has dedicated syntax: Starting a line with a slash,
/// followed by a term, a colon and a description creates a term list item.
#[elem(scope, title = "Term List", Show)]
#[elem(scope, title = "Term List", Locatable, Show)]
pub struct TermsElem {
/// Defines the default [spacing]($terms.spacing) of the term list. If it is
/// `{false}`, the items are spaced apart with
@ -205,7 +206,7 @@ impl Show for Packed<TermsElem> {
}
/// A term list item.
#[elem(name = "item", title = "Term List Item")]
#[elem(name = "item", title = "Term List Item", Locatable)]
pub struct TermItem {
/// The term described by the list item.
#[required]

View File

@ -3,6 +3,7 @@ use smallvec::smallvec;
use crate::diag::SourceResult;
use crate::engine::Engine;
use crate::foundations::{elem, Content, Packed, Show, Smart, StyleChain};
use crate::introspection::Locatable;
use crate::layout::{Abs, Corners, Length, Rel, Sides};
use crate::text::{BottomEdge, BottomEdgeMetric, TextElem, TopEdge, TopEdgeMetric};
use crate::visualize::{Color, FixedStroke, Paint, Stroke};
@ -13,7 +14,7 @@ use crate::visualize::{Color, FixedStroke, Paint, Stroke};
/// ```example
/// This is #underline[important].
/// ```
#[elem(Show)]
#[elem(Locatable, Show)]
pub struct UnderlineElem {
/// How to [stroke] the line.
///
@ -99,7 +100,7 @@ impl Show for Packed<UnderlineElem> {
/// ```example
/// #overline[A line over text.]
/// ```
#[elem(Show)]
#[elem(Locatable, Show)]
pub struct OverlineElem {
/// How to [stroke] the line.
///
@ -191,7 +192,7 @@ impl Show for Packed<OverlineElem> {
/// ```example
/// This is #strike[not] relevant.
/// ```
#[elem(title = "Strikethrough", Show)]
#[elem(title = "Strikethrough", Locatable, Show)]
pub struct StrikeElem {
/// How to [stroke] the line.
///
@ -268,7 +269,7 @@ impl Show for Packed<StrikeElem> {
/// ```example
/// This is #highlight[important].
/// ```
#[elem(Show)]
#[elem(Locatable, Show)]
pub struct HighlightElem {
/// The color to highlight the text with.
///

View File

@ -20,6 +20,7 @@ use crate::foundations::{
PlainText, Show, ShowSet, Smart, StyleChain, Styles, Synthesize, TargetElem,
};
use crate::html::{tag, HtmlElem};
use crate::introspection::Locatable;
use crate::layout::{BlockBody, BlockElem, Em, HAlignment};
use crate::loading::{DataSource, Load};
use crate::model::{Figurable, ParElem};
@ -78,6 +79,7 @@ use crate::World;
scope,
title = "Raw Text / Code",
Synthesize,
Locatable,
Show,
ShowSet,
LocalName,
@ -636,7 +638,7 @@ fn format_theme_error(error: syntect::LoadingError) -> LoadError {
/// It allows you to access various properties of the line, such as the line
/// number, the raw non-highlighted text, the highlighted text, and whether it
/// is the first or last line of the raw block.
#[elem(name = "line", title = "Raw Text / Code Line", Show, PlainText)]
#[elem(name = "line", title = "Raw Text / Code Line", Locatable, Show, PlainText)]
pub struct RawLine {
/// The line number of the raw line inside of the raw block, starts at 1.
#[required]

View File

@ -3,6 +3,7 @@ use ecow::EcoString;
use crate::diag::SourceResult;
use crate::engine::Engine;
use crate::foundations::{elem, Content, Packed, SequenceElem, Show, StyleChain};
use crate::introspection::Locatable;
use crate::layout::{Em, Length};
use crate::text::{variant, SpaceElem, TextElem, TextSize};
use crate::World;
@ -15,7 +16,7 @@ use crate::World;
/// ```example
/// Revenue#sub[yearly]
/// ```
#[elem(title = "Subscript", Show)]
#[elem(title = "Subscript", Locatable, Show)]
pub struct SubElem {
/// Whether to prefer the dedicated subscript characters of the font.
///
@ -74,7 +75,7 @@ impl Show for Packed<SubElem> {
/// ```example
/// 1#super[st] try!
/// ```
#[elem(title = "Superscript", Show)]
#[elem(title = "Superscript", Locatable, Show)]
pub struct SuperElem {
/// Whether to prefer the dedicated superscript characters of the font.
///

View File

@ -21,6 +21,7 @@ use crate::foundations::{
cast, elem, func, scope, Bytes, Cast, Content, Derived, NativeElement, Packed, Show,
Smart, StyleChain,
};
use crate::introspection::Locatable;
use crate::layout::{BlockElem, Length, Rel, Sizing};
use crate::loading::{DataSource, Load, LoadSource, Loaded, Readable};
use crate::model::Figurable;
@ -44,7 +45,7 @@ use crate::text::LocalName;
/// ],
/// )
/// ```
#[elem(scope, Show, LocalName, Figurable)]
#[elem(scope, Locatable, Show, LocalName, Figurable)]
pub struct ImageElem {
/// A [path]($syntax/#paths) to an image file or raw bytes making up an
/// image in one of the supported [formats]($image.format).