summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-04-17 13:25:31 +0200
committerLaurenz <laurmaedje@gmail.com>2023-04-17 13:26:49 +0200
commit9bdc4a7de0fb685fa2b8d02280e70aa0b5d92bf9 (patch)
treee67c75c32183e734272943107ad2d034b1e8e818 /library
parent428c55b6eed3536bb228924c6fb0ad6cea6d6d4b (diff)
Write PDF outline
Diffstat (limited to 'library')
-rw-r--r--library/src/lib.rs1
-rw-r--r--library/src/meta/figure.rs12
-rw-r--r--library/src/prelude.rs6
-rw-r--r--library/src/text/misc.rs8
-rw-r--r--library/src/text/mod.rs8
5 files changed, 24 insertions, 11 deletions
diff --git a/library/src/lib.rs b/library/src/lib.rs
index caf76ded..ccdf448c 100644
--- a/library/src/lib.rs
+++ b/library/src/lib.rs
@@ -211,6 +211,7 @@ fn items() -> LangItems {
},
bibliography_keys: meta::BibliographyElem::keys,
heading: |level, title| meta::HeadingElem::new(title).with_level(level).pack(),
+ heading_func: meta::HeadingElem::func(),
list_item: |body| layout::ListItem::new(body).pack(),
enum_item: |number, body| {
let mut elem = layout::EnumItem::new(body);
diff --git a/library/src/meta/figure.rs b/library/src/meta/figure.rs
index 42b32c9d..1f1499fc 100644
--- a/library/src/meta/figure.rs
+++ b/library/src/meta/figure.rs
@@ -173,14 +173,14 @@ impl Synthesize for FigureElem {
// Determine the figure's kind.
let kind = match self.kind(styles) {
Smart::Auto => self
- .find_figurable(vt, styles)
+ .find_figurable(styles)
.map(|elem| FigureKind::Elem(elem.func()))
.unwrap_or_else(|| FigureKind::Elem(ImageElem::func())),
Smart::Custom(kind) => kind,
};
let content = match &kind {
- FigureKind::Elem(func) => self.find_of_elem(vt, *func),
+ FigureKind::Elem(func) => self.find_of_elem(*func),
FigureKind::Name(_) => None,
}
.unwrap_or_else(|| self.body());
@@ -303,9 +303,9 @@ impl Refable for FigureElem {
impl FigureElem {
/// Determines the type of the figure by looking at the content, finding all
/// [`Figurable`] elements and sorting them by priority then returning the highest.
- pub fn find_figurable(&self, vt: &Vt, styles: StyleChain) -> Option<Content> {
+ pub fn find_figurable(&self, styles: StyleChain) -> Option<Content> {
self.body()
- .query(vt.introspector, Selector::can::<dyn Figurable>())
+ .query(Selector::can::<dyn Figurable>())
.into_iter()
.max_by_key(|elem| elem.with::<dyn Figurable>().unwrap().priority(styles))
.cloned()
@@ -313,9 +313,9 @@ impl FigureElem {
/// Finds the element with the given function in the figure's content.
/// Returns `None` if no element with the given function is found.
- pub fn find_of_elem(&self, vt: &Vt, func: ElemFunc) -> Option<Content> {
+ pub fn find_of_elem(&self, func: ElemFunc) -> Option<Content> {
self.body()
- .query(vt.introspector, Selector::Elem(func, None))
+ .query(Selector::Elem(func, None))
.into_iter()
.next()
.cloned()
diff --git a/library/src/prelude.rs b/library/src/prelude.rs
index fc71e2c2..cb21a732 100644
--- a/library/src/prelude.rs
+++ b/library/src/prelude.rs
@@ -23,9 +23,9 @@ pub use typst::geom::*;
#[doc(no_inline)]
pub use typst::model::{
element, Behave, Behaviour, Construct, Content, ElemFunc, Element, Finalize, Fold,
- Introspector, Label, Locatable, LocatableSelector, Location, MetaElem, Resolve,
- Selector, Set, Show, StabilityProvider, StyleChain, StyleVec, Styles, Synthesize,
- Unlabellable, Vt,
+ Introspector, Label, Locatable, LocatableSelector, Location, MetaElem, PlainText,
+ Resolve, Selector, Set, Show, StabilityProvider, StyleChain, StyleVec, Styles,
+ Synthesize, Unlabellable, Vt,
};
#[doc(no_inline)]
pub use typst::syntax::{Span, Spanned};
diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs
index e1d9c0f2..a707d130 100644
--- a/library/src/text/misc.rs
+++ b/library/src/text/misc.rs
@@ -5,7 +5,7 @@ use crate::prelude::*;
///
/// Display: Space
/// Category: text
-#[element(Unlabellable, Behave)]
+#[element(Behave, Unlabellable, PlainText)]
pub struct SpaceElem {}
impl Behave for SpaceElem {
@@ -16,6 +16,12 @@ impl Behave for SpaceElem {
impl Unlabellable for SpaceElem {}
+impl PlainText for SpaceElem {
+ fn plain_text(&self, text: &mut EcoString) {
+ text.push(' ');
+ }
+}
+
/// Inserts a line break.
///
/// Advances the paragraph to the next line. A single trailing line break at the
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index 16268aad..f4b3c0de 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -40,7 +40,7 @@ use crate::prelude::*;
///
/// Display: Text
/// Category: text
-#[element(Construct)]
+#[element(Construct, PlainText)]
pub struct TextElem {
/// A prioritized sequence of font families.
///
@@ -497,6 +497,12 @@ impl Construct for TextElem {
}
}
+impl PlainText for TextElem {
+ fn plain_text(&self, text: &mut EcoString) {
+ text.push_str(&self.text());
+ }
+}
+
/// A lowercased font family like "arial".
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct FontFamily(EcoString);