From 1dd66684bfd2d15593f61cc1454288ef85ecc65f Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Fri, 2 Jun 2023 10:03:02 -0400 Subject: [PATCH] Parser: add "title" field and set it with the first heading found --- src/message/parser.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/message/parser.rs b/src/message/parser.rs index e573c0a..dd0544a 100644 --- a/src/message/parser.rs +++ b/src/message/parser.rs @@ -112,6 +112,7 @@ impl<'a> GemtextNode { #[derive(Debug)] pub struct Parser<'a> { state: State<'a>, + title: Option, lines: Vec, } @@ -119,6 +120,7 @@ impl<'a> Parser<'a> { pub fn new() -> Self { Self { state: State::Normal, + title: None, lines: vec![] } } @@ -139,7 +141,14 @@ impl<'a> Parser<'a> { } fn heading(&mut self, line: &'a str) { - self.lines.push(GemtextNode::parse_heading(line)); + let line = GemtextNode::parse_heading(line); + if self.title.is_none() { + match &line { + GemtextNode::Heading1(t) => self.title = Some(t.clone()), + _ => {}, + } + } + self.lines.push(line); } fn list_item(&mut self, line: &'a str) {