summaryrefslogtreecommitdiff
path: root/docs/src/html.rs
diff options
context:
space:
mode:
Diffstat (limited to 'docs/src/html.rs')
-rw-r--r--docs/src/html.rs41
1 files changed, 25 insertions, 16 deletions
diff --git a/docs/src/html.rs b/docs/src/html.rs
index d702d115..c9ed7a7f 100644
--- a/docs/src/html.rs
+++ b/docs/src/html.rs
@@ -26,9 +26,11 @@ pub struct Html {
#[serde(skip)]
md: String,
#[serde(skip)]
- description: Option<EcoString>,
- #[serde(skip)]
outline: Vec<OutlineItem>,
+ #[serde(skip)]
+ title: Option<EcoString>,
+ #[serde(skip)]
+ description: Option<EcoString>,
}
impl Html {
@@ -37,8 +39,9 @@ impl Html {
Self {
md: String::new(),
raw,
- description: None,
outline: vec![],
+ title: None,
+ description: None,
}
}
@@ -47,10 +50,12 @@ impl Html {
pub fn markdown(resolver: &dyn Resolver, md: &str, nesting: Option<usize>) -> Self {
let mut text = md;
let mut description = None;
+ let mut title = None;
let document = YamlFrontMatter::parse::<Metadata>(md);
if let Ok(document) = &document {
text = &document.content;
- description = Some(document.metadata.description.clone())
+ title = document.metadata.title.clone();
+ description = document.metadata.description.clone();
}
let options = md::Options::ENABLE_TABLES
@@ -97,8 +102,9 @@ impl Html {
Html {
md: text.into(),
raw,
- description,
outline: handler.outline,
+ title,
+ description,
}
}
@@ -112,23 +118,25 @@ impl Html {
&self.md
}
+ /// The outline of the HTML.
+ pub fn outline(&self) -> Vec<OutlineItem> {
+ self.outline.clone()
+ }
+
/// The title of the HTML.
///
/// Returns `None` if the HTML doesn't start with an `h1` tag.
pub fn title(&self) -> Option<&str> {
- let mut s = Scanner::new(&self.raw);
- s.eat_if("<h1").then(|| {
- s.eat_until('>');
- s.eat_if('>');
- s.eat_until("</h1>")
+ self.title.as_deref().or_else(|| {
+ let mut s = Scanner::new(&self.raw);
+ s.eat_if("<h1").then(|| {
+ s.eat_until('>');
+ s.eat_if('>');
+ s.eat_until("</h1>")
+ })
})
}
- /// The outline of the HTML.
- pub fn outline(&self) -> Vec<OutlineItem> {
- self.outline.clone()
- }
-
/// The description from the front matter.
pub fn description(&self) -> Option<EcoString> {
self.description.clone()
@@ -144,7 +152,8 @@ impl Debug for Html {
/// Front matter metadata.
#[derive(Deserialize)]
struct Metadata {
- description: EcoString,
+ title: Option<EcoString>,
+ description: Option<EcoString>,
}
struct Handler<'a> {