mirror of
https://github.com/typst/typst
synced 2025-08-06 03:07:54 +08:00
Set cite
attribute of blockquote
if attribution is a link.
This commit is contained in:
parent
61c3e363a4
commit
e84bb4b6e6
@ -4,12 +4,12 @@ use crate::foundations::{
|
||||
cast, elem, Content, Depth, Label, NativeElement, Packed, Show, ShowSet, Smart,
|
||||
StyleChain, Styles, TargetElem,
|
||||
};
|
||||
use crate::html::{tag, HtmlElem};
|
||||
use crate::html::{tag, HtmlAttr, HtmlElem};
|
||||
use crate::introspection::Locatable;
|
||||
use crate::layout::{
|
||||
Alignment, BlockBody, BlockElem, Em, HElem, PadElem, Spacing, VElem,
|
||||
};
|
||||
use crate::model::{CitationForm, CiteElem};
|
||||
use crate::model::{CitationForm, CiteElem, Destination, LinkElem, LinkTarget};
|
||||
use crate::text::{SmartQuoteElem, SmartQuotes, SpaceElem, TextElem};
|
||||
|
||||
/// Displays a quote alongside an optional attribution.
|
||||
@ -186,15 +186,28 @@ impl Show for Packed<QuoteElem> {
|
||||
.styled(QuoteElem::set_depth(Depth(1)));
|
||||
}
|
||||
|
||||
let attribution = self.attribution(styles);
|
||||
|
||||
if block {
|
||||
realized = if html {
|
||||
HtmlElem::new(tag::blockquote).with_body(Some(realized)).pack()
|
||||
let mut elem = HtmlElem::new(tag::blockquote).with_body(Some(realized));
|
||||
if let Some(Attribution::Content(attribution)) = attribution {
|
||||
if let Some(link) = attribution.to_packed::<LinkElem>() {
|
||||
if let LinkTarget::Dest(Destination::Url(url)) = &link.dest {
|
||||
elem = elem.with_attr(
|
||||
HtmlAttr::constant("cite"),
|
||||
url.clone().into_inner(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
elem.pack()
|
||||
} else {
|
||||
BlockElem::new().with_body(Some(BlockBody::Content(realized))).pack()
|
||||
}
|
||||
.spanned(self.span());
|
||||
|
||||
if let Some(attribution) = self.attribution(styles).as_ref() {
|
||||
if let Some(attribution) = attribution.as_ref() {
|
||||
let attribution = match attribution {
|
||||
Attribution::Content(content) => content.clone(),
|
||||
Attribution::Label(label) => CiteElem::new(*label)
|
||||
@ -218,7 +231,7 @@ impl Show for Packed<QuoteElem> {
|
||||
if !html {
|
||||
realized = PadElem::new(realized).pack();
|
||||
}
|
||||
} else if let Some(Attribution::Label(label)) = self.attribution(styles) {
|
||||
} else if let Some(Attribution::Label(label)) = attribution {
|
||||
realized += SpaceElem::shared().clone()
|
||||
+ CiteElem::new(*label).pack().spanned(self.span());
|
||||
}
|
||||
|
15
tests/ref/html/quote-attribution-link.html
Normal file
15
tests/ref/html/quote-attribution-link.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<blockquote cite="https://typst.app/home">
|
||||
Compose papers faster
|
||||
</blockquote>
|
||||
<p>
|
||||
— <a href="https://typst.app/home">typst.com</a>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
@ -99,3 +99,11 @@ And I quote: #quote(attribution: [René Descartes])[cogito, ergo sum].
|
||||
|
||||
--- quote-nesting-html html ---
|
||||
When you said that #quote[he surely meant that #quote[she intended to say #quote[I'm sorry]]], I was quite confused.
|
||||
|
||||
--- quote-attribution-link html ---
|
||||
#quote(
|
||||
block: true,
|
||||
attribution: link("https://typst.app/home")[typst.com]
|
||||
)[
|
||||
Compose papers faster
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user