mirror of
https://github.com/typst/typst
synced 2025-05-20 03:55:29 +08:00
Synthesize block
and quotes
& improve documentation for quote
(#2532)
This commit is contained in:
parent
67e87149ab
commit
4d5255d9cb
@ -3,13 +3,15 @@ use crate::layout::{BlockElem, HElem, PadElem, Spacing, VElem};
|
|||||||
use crate::meta::{CitationForm, CiteElem};
|
use crate::meta::{CitationForm, CiteElem};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Displays a quote alongside it's author.
|
/// Displays a quote alongside an optional attribution.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```example
|
/// ```example
|
||||||
/// Plato is often misquoted as the author of #quote[I know that I know
|
/// Plato is often misquoted as the author of #quote[I know that I know
|
||||||
/// nothing], however, this is a derivation form his original quote:
|
/// nothing], however, this is a derivation form his original quote:
|
||||||
|
///
|
||||||
/// #set quote(block: true)
|
/// #set quote(block: true)
|
||||||
|
///
|
||||||
/// #quote(attribution: [Plato])[
|
/// #quote(attribution: [Plato])[
|
||||||
/// ... ἔοικα γοῦν τούτου γε σμικρῷ τινι αὐτῷ τούτῳ σοφώτερος εἶναι, ὅτι
|
/// ... ἔοικα γοῦν τούτου γε σμικρῷ τινι αὐτῷ τούτῳ σοφώτερος εἶναι, ὅτι
|
||||||
/// ἃ μὴ οἶδα οὐδὲ οἴομαι εἰδέναι.
|
/// ἃ μὴ οἶδα οὐδὲ οἴομαι εἰδέναι.
|
||||||
@ -33,15 +35,23 @@ use crate::prelude::*;
|
|||||||
/// flame of Udûn. Go back to the Shadow! You cannot pass.
|
/// flame of Udûn. Go back to the Shadow! You cannot pass.
|
||||||
/// ]
|
/// ]
|
||||||
/// ```
|
/// ```
|
||||||
#[elem(Finalize, Show)]
|
#[elem(Finalize, Show, Synthesize)]
|
||||||
pub struct QuoteElem {
|
pub struct QuoteElem {
|
||||||
/// Whether this is a block quote.
|
/// Whether this is a block quote.
|
||||||
///
|
///
|
||||||
/// ```example
|
/// ```example
|
||||||
/// #quote(attribution: [René Descartes])[cogito, ergo sum]
|
/// An inline citation would look like
|
||||||
///
|
/// this: #quote(
|
||||||
/// #set quote(block: true)
|
/// attribution: [René Descartes]
|
||||||
/// #quote(attribution: [JFK])[Ich bin ein Berliner.]
|
/// )[
|
||||||
|
/// cogito, ergo sum
|
||||||
|
/// ], and a block equation like this:
|
||||||
|
/// #quote(
|
||||||
|
/// block: true,
|
||||||
|
/// attribution: [JFK]
|
||||||
|
/// )[
|
||||||
|
/// Ich bin ein Berliner.
|
||||||
|
/// ]
|
||||||
/// ```
|
/// ```
|
||||||
block: bool,
|
block: bool,
|
||||||
|
|
||||||
@ -59,11 +69,16 @@ pub struct QuoteElem {
|
|||||||
///
|
///
|
||||||
/// ```example
|
/// ```example
|
||||||
/// #set text(lang: "de")
|
/// #set text(lang: "de")
|
||||||
|
///
|
||||||
|
/// Ein deutsch-sprechender Author
|
||||||
|
/// zitiert unter umständen JFK:
|
||||||
/// #quote[Ich bin ein Berliner.]
|
/// #quote[Ich bin ein Berliner.]
|
||||||
///
|
///
|
||||||
/// #set text(lang: "en")
|
/// #set text(lang: "en")
|
||||||
/// #set quote(quotes: true)
|
///
|
||||||
/// #quote(block: true)[I am a Berliner.]
|
/// And an english speaking one may
|
||||||
|
/// translate the quote:
|
||||||
|
/// #quote[I am a Berliner.]
|
||||||
/// ```
|
/// ```
|
||||||
quotes: Smart<bool>,
|
quotes: Smart<bool>,
|
||||||
|
|
||||||
@ -72,35 +87,34 @@ pub struct QuoteElem {
|
|||||||
/// displayed for block quotes, but can be changed using a `{show}` rule.
|
/// displayed for block quotes, but can be changed using a `{show}` rule.
|
||||||
///
|
///
|
||||||
/// ```example
|
/// ```example
|
||||||
/// #quote(attribution: [René Descartes])[cogito, ergo sum] \
|
/// #quote(attribution: [René Descartes])[
|
||||||
///
|
/// cogito, ergo sum
|
||||||
/// #show quote.where(block: false): it => [
|
|
||||||
/// "#it.body"
|
|
||||||
/// #if it.attribution != none [(#it.attribution)]
|
|
||||||
/// ]
|
/// ]
|
||||||
/// #quote(attribution: link("https://typst.app/home")[typst.com])[
|
///
|
||||||
|
/// #show quote.where(block: false): it => {
|
||||||
|
/// ["] + h(0pt, weak: true) + it.body + h(0pt, weak: true) + ["]
|
||||||
|
/// if it.attribution != none [ (#it.attribution)]
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// #quote(
|
||||||
|
/// attribution: link("https://typst.app/home")[typst.com]
|
||||||
|
/// )[
|
||||||
/// Compose papers faster
|
/// Compose papers faster
|
||||||
/// ]
|
/// ]
|
||||||
///
|
///
|
||||||
/// #set quote(block: true)
|
/// #set quote(block: true)
|
||||||
|
///
|
||||||
/// #quote(attribution: <tolkien54>)[
|
/// #quote(attribution: <tolkien54>)[
|
||||||
/// You cannot pass... I am a servant of the Secret Fire, wielder of the
|
/// You cannot pass... I am a servant
|
||||||
/// flame of Anor. You cannot pass. The dark fire will not avail you,
|
/// of the Secret Fire, wielder of the
|
||||||
/// flame of Udûn. Go back to the Shadow! You cannot pass.
|
/// flame of Anor. You cannot pass. The
|
||||||
|
/// dark fire will not avail you, flame
|
||||||
|
/// of Udûn. Go back to the Shadow! You
|
||||||
|
/// cannot pass.
|
||||||
/// ]
|
/// ]
|
||||||
|
///
|
||||||
/// #bibliography("works.bib", style: "apa")
|
/// #bibliography("works.bib", style: "apa")
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
/// Note that bilbiography styles which do not include the author in the
|
|
||||||
/// citation (label, numeric and notes) currently produce attributions such
|
|
||||||
/// as `[---#super[1]]` or `[--- [1]]`, this will be fixed soon with CSL
|
|
||||||
/// support. In the mean time you can simply cite yourself:
|
|
||||||
/// ```example
|
|
||||||
/// #set quote(block: true)
|
|
||||||
/// #quote(attribution: [J. R. R. Tolkien, @tolkien54])[In a hole there lived a hobbit.]
|
|
||||||
///
|
|
||||||
/// #bibliography("works.bib")
|
|
||||||
/// ```
|
|
||||||
#[borrowed]
|
#[borrowed]
|
||||||
attribution: Option<Attribution>,
|
attribution: Option<Attribution>,
|
||||||
|
|
||||||
@ -125,6 +139,14 @@ cast! {
|
|||||||
label: Label => Self::Label(label),
|
label: Label => Self::Label(label),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Synthesize for QuoteElem {
|
||||||
|
fn synthesize(&mut self, _: &mut Vt, styles: StyleChain) -> SourceResult<()> {
|
||||||
|
self.push_block(self.block(styles));
|
||||||
|
self.push_quotes(self.quotes(styles));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Show for QuoteElem {
|
impl Show for QuoteElem {
|
||||||
fn show(&self, _: &mut Vt, styles: StyleChain) -> SourceResult<Content> {
|
fn show(&self, _: &mut Vt, styles: StyleChain) -> SourceResult<Content> {
|
||||||
let mut realized = self.body().clone();
|
let mut realized = self.body().clone();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user