Compare commits

..

1 Commits

5 changed files with 9 additions and 12 deletions

View File

@ -216,19 +216,13 @@ const TERMS_RULE: ShowFn<TermsElem> = |elem, _, styles| {
const LINK_MARKER_RULE: ShowFn<LinkMarker> = |elem, _, _| Ok(elem.body.clone());
const LINK_RULE: ShowFn<LinkElem> = |elem, engine, styles| {
let span = elem.span();
let body = elem.body.clone();
let dest = elem.dest.resolve(engine.introspector).at(elem.span())?;
let alt = match elem.alt.get_cloned(styles) {
Some(alt) => Some(alt),
None => dest.alt_text(engine, styles)?,
};
// Manually construct link marker that spans the whole link elem, not just
// the body.
Ok(LinkMarker::new(body, dest.clone(), alt)
.pack()
.spanned(span)
.set(LinkElem::current, Some(dest)))
Ok(body.linked(dest, alt))
};
const HEADING_RULE: ShowFn<HeadingElem> = |elem, engine, styles| {

View File

@ -479,7 +479,7 @@ impl Content {
/// Link the content somewhere.
pub fn linked(self, dest: Destination, alt: Option<EcoString>) -> Self {
let span = self.span();
LinkMarker::new(self, dest.clone(), alt)
LinkMarker::new(self, dest.clone(), alt, span)
.pack()
.spanned(span)
.set(LinkElem::current, Some(dest))
@ -797,6 +797,9 @@ pub struct LinkMarker {
#[internal]
#[required]
pub alt: Option<EcoString>,
#[internal]
#[required]
pub span: Span,
}
impl Construct for LinkMarker {

View File

@ -617,7 +617,7 @@ fn convert_error(
let span = to_span(*loc);
error!(
span, "{prefix} missing annotation alt text";
hint: "manually add alt text to your links"
hint: "please report this as a bug"
)
}
ValidationError::MissingAltText(loc) => {

View File

@ -71,7 +71,7 @@ pub(crate) fn handle_link(
let (alt, span) = if let Some((link, nodes)) = tagging_ctx {
nodes.push(TagNode::Placeholder(placeholder));
let alt = link.alt.as_ref().map(EcoString::to_string);
(alt, link.span())
(alt, link.span)
} else {
(None, Span::detached())
};

View File

@ -535,10 +535,10 @@ impl TagStack {
pub(crate) fn find_parent_link(
&mut self,
) -> Option<(LinkId, &Packed<LinkMarker>, &mut Vec<TagNode>)> {
) -> Option<(LinkId, &LinkMarker, &mut Vec<TagNode>)> {
self.0.iter_mut().rev().find_map(|e| {
let (link_id, link) = e.kind.as_link()?;
Some((link_id, link, &mut e.nodes))
Some((link_id, link.as_ref(), &mut e.nodes))
})
}