mirror of
https://github.com/typst/typst
synced 2025-06-19 20:02:52 +08:00
WIP [no ci]
This commit is contained in:
parent
96e29d5773
commit
4a64a717e8
@ -422,6 +422,7 @@ impl Show for Packed<OutlineEntry> {
|
|||||||
let context = Context::new(None, Some(styles));
|
let context = Context::new(None, Some(styles));
|
||||||
let context = context.track();
|
let context = context.track();
|
||||||
|
|
||||||
|
// TODO: prefix should be wrapped in a `Lbl` structure element
|
||||||
let prefix = self.prefix(engine, context, span)?;
|
let prefix = self.prefix(engine, context, span)?;
|
||||||
let body = self.body().at(span)?;
|
let body = self.body().at(span)?;
|
||||||
let page = self.page(engine, context, span)?;
|
let page = self.page(engine, context, span)?;
|
||||||
|
@ -74,12 +74,12 @@ pub(crate) fn handle_link(
|
|||||||
|
|
||||||
let placeholder = gc.tags.reserve_placeholder();
|
let placeholder = gc.tags.reserve_placeholder();
|
||||||
let mut node = TagNode::Placeholder(placeholder);
|
let mut node = TagNode::Placeholder(placeholder);
|
||||||
let (parent_tag, _) = gc.tags.parent_nodes();
|
let (parent_tag, _) = gc.tags.parent();
|
||||||
if !matches!(parent_tag, Some(Tag::Link | Tag::Reference)) {
|
if !matches!(parent_tag, Some(Tag::Link)) {
|
||||||
node = TagNode::Group(Link, )
|
node = TagNode::Group(Tag::Link, vec![node]);
|
||||||
}
|
}
|
||||||
// Prepend so the link annotation is the first child.
|
// Prepend so the link annotation is the first child.
|
||||||
gc.tags.prepend();
|
gc.tags.prepend(node);
|
||||||
|
|
||||||
fc.push_annotation(
|
fc.push_annotation(
|
||||||
placeholder,
|
placeholder,
|
||||||
|
@ -67,20 +67,22 @@ impl Tags {
|
|||||||
.expect("initialized placeholder node")
|
.expect("initialized placeholder node")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn push(&mut self, node: TagNode) {
|
/// Returns the current parent's list of children and the structure type ([Tag]).
|
||||||
if let Some((_, _, nodes)) = self.stack.last_mut() {
|
/// In case of the document root the structure type will be `None`.
|
||||||
nodes.push(node);
|
pub(crate) fn parent(&mut self) -> (Option<&mut Tag>, &mut Vec<TagNode>) {
|
||||||
|
if let Some((_, tag, parent_nodes)) = self.stack.last_mut() {
|
||||||
|
(Some(tag), parent_nodes)
|
||||||
} else {
|
} else {
|
||||||
self.tree.push(node);
|
(None, &mut self.tree)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn push(&mut self, node: TagNode) {
|
||||||
|
self.parent().1.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn prepend(&mut self, node: TagNode) {
|
pub(crate) fn prepend(&mut self, node: TagNode) {
|
||||||
if let Some((_, _, nodes)) = self.stack.last_mut() {
|
self.parent().1.insert(0, node);
|
||||||
nodes.insert(0, node);
|
|
||||||
} else {
|
|
||||||
self.tree.insert(0, node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn build_tree(&mut self) -> TagTree {
|
pub(crate) fn build_tree(&mut self) -> TagTree {
|
||||||
@ -109,15 +111,6 @@ impl Tags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current parent's list of children and whether it is the tree root.
|
|
||||||
pub(crate) fn parent_nodes(&mut self) -> (Option<&mut Tag>, &mut Vec<TagNode>) {
|
|
||||||
if let Some((_, tag, parent_nodes)) = self.stack.last_mut() {
|
|
||||||
(Some(tag), parent_nodes)
|
|
||||||
} else {
|
|
||||||
(None, &mut self.tree)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn context_supports(&self, _tag: &Tag) -> bool {
|
fn context_supports(&self, _tag: &Tag) -> bool {
|
||||||
// TODO: generate using: https://pdfa.org/resource/iso-ts-32005-hierarchical-inclusion-rules/
|
// TODO: generate using: https://pdfa.org/resource/iso-ts-32005-hierarchical-inclusion-rules/
|
||||||
true
|
true
|
||||||
@ -245,9 +238,9 @@ pub(crate) fn handle_end(gc: &mut GlobalContext, surface: &mut Surface, loc: &Lo
|
|||||||
|
|
||||||
surface.end_tagged();
|
surface.end_tagged();
|
||||||
|
|
||||||
let (is_root, parent_nodes) = gc.tags.parent_nodes();
|
let (parent_tag, parent_nodes) = gc.tags.parent();
|
||||||
parent_nodes.push(TagNode::Group(tag, nodes));
|
parent_nodes.push(TagNode::Group(tag, nodes));
|
||||||
if !is_root {
|
if parent_tag.is_some() {
|
||||||
// TODO: somehow avoid empty marked-content sequences
|
// TODO: somehow avoid empty marked-content sequences
|
||||||
let id = surface.start_tagged(ContentTag::Other);
|
let id = surface.start_tagged(ContentTag::Other);
|
||||||
parent_nodes.push(TagNode::Leaf(id));
|
parent_nodes.push(TagNode::Leaf(id));
|
||||||
@ -258,8 +251,7 @@ fn start_artifact(gc: &mut GlobalContext, surface: &mut Surface, kind: ArtifactK
|
|||||||
let ty = artifact_type(kind);
|
let ty = artifact_type(kind);
|
||||||
let id = surface.start_tagged(ContentTag::Artifact(ty));
|
let id = surface.start_tagged(ContentTag::Artifact(ty));
|
||||||
|
|
||||||
let (_, parent_nodes) = gc.tags.parent_nodes();
|
gc.tags.push(TagNode::Leaf(id));
|
||||||
parent_nodes.push(TagNode::Leaf(id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn artifact_type(kind: ArtifactKind) -> ArtifactType {
|
fn artifact_type(kind: ArtifactKind) -> ArtifactType {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user