diff options
| author | Chen <53432474+werifu@users.noreply.github.com> | 2023-04-13 16:41:42 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-13 10:41:42 +0200 |
| commit | a066a3d2831bc8e643349a54880671e9c7d11e0f (patch) | |
| tree | 7355c76fa93a624a47f1a553c1d1434f6e568d69 /library | |
| parent | 8300f75f22cb4dd1b871a7e617397ff7d56ba001 (diff) | |
More flexible capability to control showing reference (#646)
Diffstat (limited to 'library')
| -rw-r--r-- | library/src/meta/heading.rs | 1 | ||||
| -rw-r--r-- | library/src/meta/reference.rs | 50 |
2 files changed, 51 insertions, 0 deletions
diff --git a/library/src/meta/heading.rs b/library/src/meta/heading.rs index 56942a24..f3d0e337 100644 --- a/library/src/meta/heading.rs +++ b/library/src/meta/heading.rs @@ -102,6 +102,7 @@ impl Synthesize for HeadingElem { self.push_numbering(self.numbering(styles)); self.push_supplement(self.supplement(styles)); self.push_outlined(self.outlined(styles)); + self.push_supplement(self.supplement(styles)); Ok(()) } } diff --git a/library/src/meta/reference.rs b/library/src/meta/reference.rs index 9598decb..13d7b8ec 100644 --- a/library/src/meta/reference.rs +++ b/library/src/meta/reference.rs @@ -85,12 +85,62 @@ pub struct RefElem { /// A synthesized citation. #[synthesized] pub citation: Option<CiteElem>, + + /// Content of the element, it should be referable. + /// + /// ```example + /// #set heading(numbering: (..nums) => { + /// nums.pos().map(str).join(".") + /// }, supplement: [Chapt]) + /// + /// #show ref: it => { + /// if it.has("element") and it.element.func() == heading { + /// let element = it.element + /// "[" + /// element.supplement + /// "-" + /// numbering(element.numbering, ..counter(heading).at(element.location())) + /// "]" + /// } else { + /// it + /// } + /// } + /// + /// = Introduction <intro> + /// = Summary <sum> + /// == Subsection <sub> + /// @intro + /// + /// @sum + /// + /// @sub + /// ``` + #[synthesized] + pub element: Option<Content>, } impl Synthesize for RefElem { fn synthesize(&mut self, vt: &mut Vt, styles: StyleChain) -> SourceResult<()> { let citation = self.to_citation(vt, styles)?; self.push_citation(Some(citation)); + + if !vt.introspector.init() { + self.push_element(None); + return Ok(()); + } + + // find the element content + let target = self.target(); + let elem = vt.introspector.query_label(&self.target()); + // not in bibliography, but in document, then push the element + if let (false, Ok(elem)) = + (BibliographyElem::has(vt, &target.0), elem.at(self.span())) + { + self.push_element(Some(elem)); + } else { + self.push_element(None); + } + Ok(()) } } |
