mirror of
https://github.com/typst/typst
synced 2025-07-26 13:57:53 +08:00
feat: add alt field to figure
This commit is contained in:
parent
3909bdae6b
commit
042330cd66
@ -282,7 +282,8 @@ const HEADING_RULE: ShowFn<HeadingElem> = |elem, engine, styles| {
|
||||
|
||||
const FIGURE_RULE: ShowFn<FigureElem> = |elem, _, styles| {
|
||||
let span = elem.span();
|
||||
let mut realized = PdfMarkerTag::FigureBody(elem.body.clone());
|
||||
let mut realized =
|
||||
PdfMarkerTag::FigureBody(elem.alt.get_cloned(styles), elem.body.clone());
|
||||
|
||||
// Build the caption, if any.
|
||||
if let Some(caption) = elem.caption.get_cloned(styles) {
|
||||
|
@ -103,6 +103,9 @@ use crate::visualize::ImageElem;
|
||||
/// ```
|
||||
#[elem(scope, Locatable, Synthesize, Count, ShowSet, Refable, Outlinable)]
|
||||
pub struct FigureElem {
|
||||
/// An alternative description of the figure.
|
||||
pub alt: Option<EcoString>,
|
||||
|
||||
/// The content of the figure. Often, an [image].
|
||||
#[required]
|
||||
pub body: Content,
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use ecow::EcoString;
|
||||
use typst_macros::{Cast, elem, func};
|
||||
use typst_utils::NonZeroExt;
|
||||
|
||||
@ -118,8 +119,8 @@ impl Construct for PdfMarkerTag {
|
||||
}
|
||||
|
||||
macro_rules! pdf_marker_tag {
|
||||
($(#[doc = $doc:expr] $variant:ident$(($($name:ident: $ty:ident)+))?,)+) => {
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
($(#[doc = $doc:expr] $variant:ident$(($($name:ident: $ty:ty)+))?,)+) => {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum PdfMarkerTagKind {
|
||||
$(
|
||||
#[doc = $doc]
|
||||
@ -147,7 +148,7 @@ pdf_marker_tag! {
|
||||
/// `TOC`
|
||||
OutlineBody,
|
||||
/// `Figure`
|
||||
FigureBody,
|
||||
FigureBody(alt: Option<EcoString>),
|
||||
/// `L` bibliography list
|
||||
Bibliography(numbered: bool),
|
||||
/// `LBody` wrapping `BibEntry`
|
||||
|
@ -59,15 +59,18 @@ pub(crate) fn handle_start(
|
||||
}
|
||||
|
||||
let mut tag: TagKind = if let Some(tag) = elem.to_packed::<PdfMarkerTag>() {
|
||||
match tag.kind {
|
||||
match &tag.kind {
|
||||
PdfMarkerTagKind::OutlineBody => {
|
||||
push_stack(gc, loc, StackEntryKind::Outline(OutlineCtx::new()))?;
|
||||
return Ok(());
|
||||
}
|
||||
PdfMarkerTagKind::FigureBody => Tag::Figure(None).into(),
|
||||
PdfMarkerTagKind::FigureBody(alt) => {
|
||||
let alt = alt.as_ref().map(|s| s.to_string());
|
||||
Tag::Figure(alt).into()
|
||||
}
|
||||
PdfMarkerTagKind::Bibliography(numbered) => {
|
||||
let numbering =
|
||||
if numbered { ListNumbering::Decimal } else { ListNumbering::None };
|
||||
if *numbered { ListNumbering::Decimal } else { ListNumbering::None };
|
||||
push_stack(gc, loc, StackEntryKind::List(ListCtx::new(numbering)))?;
|
||||
return Ok(());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user