mirror of
https://github.com/typst/typst
synced 2025-06-28 00:03:17 +08:00
Remove semantic role handling
This commit is contained in:
parent
66ad023519
commit
237feda063
@ -121,12 +121,7 @@ impl Show for HeadingNode {
|
|||||||
realized = realized.underlined();
|
realized = realized.underlined();
|
||||||
}
|
}
|
||||||
|
|
||||||
let role = Role::Heading {
|
realized = realized.styled_with_map(map);
|
||||||
level: self.level,
|
|
||||||
outlined: styles.get(Self::OUTLINED),
|
|
||||||
};
|
|
||||||
|
|
||||||
realized = realized.styled_with_map(map).role(role);
|
|
||||||
realized = realized.spaced(
|
realized = realized.spaced(
|
||||||
resolve!(Self::ABOVE).resolve(styles),
|
resolve!(Self::ABOVE).resolve(styles),
|
||||||
resolve!(Self::BELOW).resolve(styles),
|
resolve!(Self::BELOW).resolve(styles),
|
||||||
|
@ -128,11 +128,7 @@ impl<const L: ListKind> Show for ListNode<L> {
|
|||||||
cells.push(LayoutNode::default());
|
cells.push(LayoutNode::default());
|
||||||
|
|
||||||
let label = if L == LIST || L == ENUM {
|
let label = if L == LIST || L == ENUM {
|
||||||
label
|
label.resolve(world, L, number)?.styled_with_map(map.clone()).pack()
|
||||||
.resolve(world, L, number)?
|
|
||||||
.styled_with_map(map.clone())
|
|
||||||
.role(Role::ListLabel)
|
|
||||||
.pack()
|
|
||||||
} else {
|
} else {
|
||||||
LayoutNode::default()
|
LayoutNode::default()
|
||||||
};
|
};
|
||||||
@ -188,7 +184,7 @@ impl<const L: ListKind> Show for ListNode<L> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(realized.role(Role::List { ordered: L == ENUM }).spaced(above, below))
|
Ok(realized.spaced(above, below))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,11 +52,7 @@ impl Show for TableNode {
|
|||||||
Self {
|
Self {
|
||||||
tracks: self.tracks.clone(),
|
tracks: self.tracks.clone(),
|
||||||
gutter: self.gutter.clone(),
|
gutter: self.gutter.clone(),
|
||||||
cells: self
|
cells: self.cells.iter().map(|cell| cell.unguard(sel)).collect(),
|
||||||
.cells
|
|
||||||
.iter()
|
|
||||||
.map(|cell| cell.unguard(sel).role(Role::TableCell))
|
|
||||||
.collect(),
|
|
||||||
}
|
}
|
||||||
.pack()
|
.pack()
|
||||||
}
|
}
|
||||||
@ -108,8 +104,7 @@ impl Show for TableNode {
|
|||||||
tracks: self.tracks.clone(),
|
tracks: self.tracks.clone(),
|
||||||
gutter: self.gutter.clone(),
|
gutter: self.gutter.clone(),
|
||||||
cells,
|
cells,
|
||||||
})
|
}))
|
||||||
.role(Role::Table))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(
|
fn finalize(
|
||||||
|
@ -127,7 +127,7 @@ impl Show for RawNode {
|
|||||||
realized = realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW));
|
realized = realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(realized.styled_with_map(map).role(Role::Code))
|
Ok(realized.styled_with_map(map))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use super::{
|
|||||||
ShowNode, StyleChain, StyleEntry, StyleMap,
|
ShowNode, StyleChain, StyleEntry, StyleMap,
|
||||||
};
|
};
|
||||||
use crate::diag::{SourceResult, StrResult};
|
use crate::diag::{SourceResult, StrResult};
|
||||||
use crate::frame::{Frame, Role};
|
use crate::frame::Frame;
|
||||||
use crate::geom::Abs;
|
use crate::geom::Abs;
|
||||||
use crate::library::layout::{PageNode, Spacing};
|
use crate::library::layout::{PageNode, Spacing};
|
||||||
use crate::library::structure::ListItem;
|
use crate::library::structure::ListItem;
|
||||||
@ -160,11 +160,6 @@ impl Content {
|
|||||||
Self::Styled(Arc::new((self, styles)))
|
Self::Styled(Arc::new((self, styles)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assign a semantic role to this content.
|
|
||||||
pub fn role(self, role: Role) -> Self {
|
|
||||||
self.styled_with_entry(StyleEntry::Role(role))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reenable the show rule identified by the selector.
|
/// Reenable the show rule identified by the selector.
|
||||||
pub fn unguard(&self, sel: Selector) -> Self {
|
pub fn unguard(&self, sel: Selector) -> Self {
|
||||||
self.clone().styled_with_entry(StyleEntry::Unguard(sel))
|
self.clone().styled_with_entry(StyleEntry::Unguard(sel))
|
||||||
|
@ -202,15 +202,7 @@ impl Layout for LayoutNode {
|
|||||||
) -> SourceResult<Vec<Frame>> {
|
) -> SourceResult<Vec<Frame>> {
|
||||||
let barrier = StyleEntry::Barrier(Barrier::new(self.id()));
|
let barrier = StyleEntry::Barrier(Barrier::new(self.id()));
|
||||||
let styles = barrier.chain(&styles);
|
let styles = barrier.chain(&styles);
|
||||||
|
self.0.layout(world, regions, styles)
|
||||||
let mut frames = self.0.layout(world, regions, styles)?;
|
|
||||||
if let Some(role) = styles.role() {
|
|
||||||
for frame in &mut frames {
|
|
||||||
frame.apply_role(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(frames)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pack(self) -> LayoutNode {
|
fn pack(self) -> LayoutNode {
|
||||||
|
@ -7,7 +7,6 @@ use comemo::Tracked;
|
|||||||
|
|
||||||
use super::{Barrier, Content, Key, Property, Recipe, Selector, Show, Target};
|
use super::{Barrier, Content, Key, Property, Recipe, Selector, Show, Target};
|
||||||
use crate::diag::SourceResult;
|
use crate::diag::SourceResult;
|
||||||
use crate::frame::Role;
|
|
||||||
use crate::util::ReadableTypeId;
|
use crate::util::ReadableTypeId;
|
||||||
use crate::World;
|
use crate::World;
|
||||||
|
|
||||||
@ -161,8 +160,6 @@ pub enum StyleEntry {
|
|||||||
Property(Property),
|
Property(Property),
|
||||||
/// A show rule recipe.
|
/// A show rule recipe.
|
||||||
Recipe(Recipe),
|
Recipe(Recipe),
|
||||||
/// A semantic role.
|
|
||||||
Role(Role),
|
|
||||||
/// A barrier for scoped styles.
|
/// A barrier for scoped styles.
|
||||||
Barrier(Barrier),
|
Barrier(Barrier),
|
||||||
/// Guards against recursive show rules.
|
/// Guards against recursive show rules.
|
||||||
@ -222,7 +219,6 @@ impl Debug for StyleEntry {
|
|||||||
match self {
|
match self {
|
||||||
Self::Property(property) => property.fmt(f)?,
|
Self::Property(property) => property.fmt(f)?,
|
||||||
Self::Recipe(recipe) => recipe.fmt(f)?,
|
Self::Recipe(recipe) => recipe.fmt(f)?,
|
||||||
Self::Role(role) => role.fmt(f)?,
|
|
||||||
Self::Barrier(barrier) => barrier.fmt(f)?,
|
Self::Barrier(barrier) => barrier.fmt(f)?,
|
||||||
Self::Guard(sel) => write!(f, "Guard against {sel:?}")?,
|
Self::Guard(sel) => write!(f, "Guard against {sel:?}")?,
|
||||||
Self::Unguard(sel) => write!(f, "Unguard against {sel:?}")?,
|
Self::Unguard(sel) => write!(f, "Unguard against {sel:?}")?,
|
||||||
@ -324,21 +320,6 @@ impl<'a> StyleChain<'a> {
|
|||||||
Ok(realized)
|
Ok(realized)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the current role.
|
|
||||||
pub fn role(self) -> Option<Role> {
|
|
||||||
let mut depth = 0;
|
|
||||||
|
|
||||||
for entry in self.entries() {
|
|
||||||
match *entry {
|
|
||||||
StyleEntry::Role(role) => return Some(role),
|
|
||||||
StyleEntry::Barrier(_) if depth == 1 => return None,
|
|
||||||
StyleEntry::Barrier(_) => depth += 1,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the recipe identified by the selector is guarded.
|
/// Whether the recipe identified by the selector is guarded.
|
||||||
fn guarded(self, sel: Selector) -> bool {
|
fn guarded(self, sel: Selector) -> bool {
|
||||||
for entry in self.entries() {
|
for entry in self.entries() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user