Reduce usage of finalize
This commit is contained in:
parent
671ce3dedd
commit
f547c97072
@ -103,16 +103,13 @@ impl Show for MathNode {
|
|||||||
&self,
|
&self,
|
||||||
_: Tracked<dyn World>,
|
_: Tracked<dyn World>,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
mut realized: Content,
|
realized: Content,
|
||||||
) -> SourceResult<Content> {
|
) -> SourceResult<Content> {
|
||||||
let mut map = StyleMap::new();
|
Ok(if self.display() {
|
||||||
map.set_family(styles.get(Self::FAMILY).clone(), styles);
|
realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW))
|
||||||
|
} else {
|
||||||
if self.display() {
|
realized
|
||||||
realized = realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW));
|
})
|
||||||
}
|
|
||||||
|
|
||||||
Ok(realized.styled_with_map(map))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,17 +73,21 @@ impl Show for LinkNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
|
fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
|
||||||
Ok(self.body.clone().unwrap_or_else(|| match &self.dest {
|
Ok(self
|
||||||
Destination::Url(url) => {
|
.body
|
||||||
let mut text = url.as_str();
|
.clone()
|
||||||
for prefix in ["mailto:", "tel:"] {
|
.unwrap_or_else(|| match &self.dest {
|
||||||
text = text.trim_start_matches(prefix);
|
Destination::Url(url) => {
|
||||||
|
let mut text = url.as_str();
|
||||||
|
for prefix in ["mailto:", "tel:"] {
|
||||||
|
text = text.trim_start_matches(prefix);
|
||||||
|
}
|
||||||
|
let shorter = text.len() < url.len();
|
||||||
|
Content::Text(if shorter { text.into() } else { url.clone() })
|
||||||
}
|
}
|
||||||
let shorter = text.len() < url.len();
|
Destination::Internal(_) => Content::Empty,
|
||||||
Content::Text(if shorter { text.into() } else { url.clone() })
|
})
|
||||||
}
|
.styled(TextNode::LINK, Some(self.dest.clone())))
|
||||||
Destination::Internal(_) => Content::Empty,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(
|
fn finalize(
|
||||||
@ -93,8 +97,6 @@ impl Show for LinkNode {
|
|||||||
mut realized: Content,
|
mut realized: Content,
|
||||||
) -> SourceResult<Content> {
|
) -> SourceResult<Content> {
|
||||||
let mut map = StyleMap::new();
|
let mut map = StyleMap::new();
|
||||||
map.set(TextNode::LINK, Some(self.dest.clone()));
|
|
||||||
|
|
||||||
if let Smart::Custom(fill) = styles.get(Self::FILL) {
|
if let Smart::Custom(fill) = styles.get(Self::FILL) {
|
||||||
map.set(TextNode::FILL, fill);
|
map.set(TextNode::FILL, fill);
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,12 @@ impl Show for RawNode {
|
|||||||
realized = Content::block(realized);
|
realized = Content::block(realized);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(realized)
|
let mut map = StyleMap::new();
|
||||||
|
map.set(TextNode::OVERHANG, false);
|
||||||
|
map.set(TextNode::HYPHENATE, Smart::Custom(Hyphenate(false)));
|
||||||
|
map.set(TextNode::SMART_QUOTES, false);
|
||||||
|
|
||||||
|
Ok(realized.styled_with_map(map))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(
|
fn finalize(
|
||||||
@ -116,9 +121,6 @@ impl Show for RawNode {
|
|||||||
) -> SourceResult<Content> {
|
) -> SourceResult<Content> {
|
||||||
let mut map = StyleMap::new();
|
let mut map = StyleMap::new();
|
||||||
map.set_family(styles.get(Self::FAMILY).clone(), styles);
|
map.set_family(styles.get(Self::FAMILY).clone(), styles);
|
||||||
map.set(TextNode::OVERHANG, false);
|
|
||||||
map.set(TextNode::HYPHENATE, Smart::Custom(Hyphenate(false)));
|
|
||||||
map.set(TextNode::SMART_QUOTES, false);
|
|
||||||
|
|
||||||
if self.block {
|
if self.block {
|
||||||
realized = realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW));
|
realized = realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW));
|
||||||
|
@ -28,7 +28,6 @@ pub trait Show: 'static {
|
|||||||
/// this for effects that should work even in the face of a user-defined
|
/// this for effects that should work even in the face of a user-defined
|
||||||
/// show rule, for example:
|
/// show rule, for example:
|
||||||
/// - Application of general settable properties
|
/// - Application of general settable properties
|
||||||
/// - Attaching things like semantics to a heading
|
|
||||||
///
|
///
|
||||||
/// Defaults to just the realized content.
|
/// Defaults to just the realized content.
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
|
@ -12,7 +12,7 @@ use crate::{LangItems, World};
|
|||||||
pub struct Vm<'a> {
|
pub struct Vm<'a> {
|
||||||
/// The core context.
|
/// The core context.
|
||||||
pub world: Tracked<'a, dyn World>,
|
pub world: Tracked<'a, dyn World>,
|
||||||
/// The route of source ids the machine took to reach its current location.
|
/// The route of source ids the VM took to reach its current location.
|
||||||
pub route: Tracked<'a, Route>,
|
pub route: Tracked<'a, Route>,
|
||||||
/// The current location.
|
/// The current location.
|
||||||
pub location: Option<SourceId>,
|
pub location: Option<SourceId>,
|
||||||
@ -52,7 +52,7 @@ impl<'a> Vm<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Err("cannot access file system from here".into());
|
Err("cannot access file system from here".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The language items.
|
/// The language items.
|
||||||
|
@ -23,7 +23,7 @@ A [= Heading] C
|
|||||||
#set heading(around: none)
|
#set heading(around: none)
|
||||||
|
|
||||||
Where is
|
Where is
|
||||||
= There are not headings around here!
|
= There are no headings around here!
|
||||||
my heading?
|
my heading?
|
||||||
|
|
||||||
---
|
---
|
||||||
|
Loading…
Reference in New Issue
Block a user