mirror of
https://github.com/typst/typst
synced 2025-07-27 06:17: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| {
|
const FIGURE_RULE: ShowFn<FigureElem> = |elem, _, styles| {
|
||||||
let span = elem.span();
|
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.
|
// Build the caption, if any.
|
||||||
if let Some(caption) = elem.caption.get_cloned(styles) {
|
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)]
|
#[elem(scope, Locatable, Synthesize, Count, ShowSet, Refable, Outlinable)]
|
||||||
pub struct FigureElem {
|
pub struct FigureElem {
|
||||||
|
/// An alternative description of the figure.
|
||||||
|
pub alt: Option<EcoString>,
|
||||||
|
|
||||||
/// The content of the figure. Often, an [image].
|
/// The content of the figure. Often, an [image].
|
||||||
#[required]
|
#[required]
|
||||||
pub body: Content,
|
pub body: Content,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
|
use ecow::EcoString;
|
||||||
use typst_macros::{Cast, elem, func};
|
use typst_macros::{Cast, elem, func};
|
||||||
use typst_utils::NonZeroExt;
|
use typst_utils::NonZeroExt;
|
||||||
|
|
||||||
@ -118,8 +119,8 @@ impl Construct for PdfMarkerTag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! pdf_marker_tag {
|
macro_rules! pdf_marker_tag {
|
||||||
($(#[doc = $doc:expr] $variant:ident$(($($name:ident: $ty:ident)+))?,)+) => {
|
($(#[doc = $doc:expr] $variant:ident$(($($name:ident: $ty:ty)+))?,)+) => {
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum PdfMarkerTagKind {
|
pub enum PdfMarkerTagKind {
|
||||||
$(
|
$(
|
||||||
#[doc = $doc]
|
#[doc = $doc]
|
||||||
@ -147,7 +148,7 @@ pdf_marker_tag! {
|
|||||||
/// `TOC`
|
/// `TOC`
|
||||||
OutlineBody,
|
OutlineBody,
|
||||||
/// `Figure`
|
/// `Figure`
|
||||||
FigureBody,
|
FigureBody(alt: Option<EcoString>),
|
||||||
/// `L` bibliography list
|
/// `L` bibliography list
|
||||||
Bibliography(numbered: bool),
|
Bibliography(numbered: bool),
|
||||||
/// `LBody` wrapping `BibEntry`
|
/// `LBody` wrapping `BibEntry`
|
||||||
|
@ -59,15 +59,18 @@ pub(crate) fn handle_start(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut tag: TagKind = if let Some(tag) = elem.to_packed::<PdfMarkerTag>() {
|
let mut tag: TagKind = if let Some(tag) = elem.to_packed::<PdfMarkerTag>() {
|
||||||
match tag.kind {
|
match &tag.kind {
|
||||||
PdfMarkerTagKind::OutlineBody => {
|
PdfMarkerTagKind::OutlineBody => {
|
||||||
push_stack(gc, loc, StackEntryKind::Outline(OutlineCtx::new()))?;
|
push_stack(gc, loc, StackEntryKind::Outline(OutlineCtx::new()))?;
|
||||||
return Ok(());
|
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) => {
|
PdfMarkerTagKind::Bibliography(numbered) => {
|
||||||
let numbering =
|
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)))?;
|
push_stack(gc, loc, StackEntryKind::List(ListCtx::new(numbering)))?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user