feat: simplify public api

This commit is contained in:
PoiScript 2023-11-17 13:34:06 +08:00
parent 394c013fd2
commit e924359df6
No known key found for this signature in database
GPG key ID: 22C2B1249D99985E
10 changed files with 586 additions and 356 deletions

View file

@ -1,4 +1,5 @@
use rowan::WalkEvent;
use std::cmp::min;
use std::fmt;
use super::TraversalContext;
@ -188,19 +189,11 @@ impl Traverser for HtmlExport {
fn headline_title(&mut self, event: WalkEvent<&HeadlineTitle>, _ctx: &mut TraversalContext) {
self.output += &match event {
WalkEvent::Enter(title) => {
let level = title
.headline()
.and_then(|hdl| hdl.level())
.map(|lvl| std::cmp::min(lvl, 6))
.unwrap_or(1);
let level = title.headline().map(|h| min(h.level(), 6)).unwrap_or(1);
format!("<h{level}>")
}
WalkEvent::Leave(title) => {
let level = title
.headline()
.and_then(|hdl| hdl.level())
.map(|lvl| std::cmp::min(lvl, 6))
.unwrap_or(1);
let level = title.headline().map(|h| min(h.level(), 6)).unwrap_or(1);
format!("</h{level}>")
}
};