|
|
@ -71,6 +71,7 @@ pub struct Document {
|
|
|
|
pub struct Section {
|
|
|
|
pub struct Section {
|
|
|
|
pub(crate) header: Header,
|
|
|
|
pub(crate) header: Header,
|
|
|
|
pub(crate) elements: Vec<Block>,
|
|
|
|
pub(crate) elements: Vec<Block>,
|
|
|
|
|
|
|
|
pub(crate) metadata: Option<InlineMetadata>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
@ -264,9 +265,11 @@ impl Document {
|
|
|
|
list.ordered = true;
|
|
|
|
list.ordered = true;
|
|
|
|
self.elements.iter().for_each(|e| match e {
|
|
|
|
self.elements.iter().for_each(|e| match e {
|
|
|
|
Block::Section(sec) => {
|
|
|
|
Block::Section(sec) => {
|
|
|
|
let mut item = ListItem::new(Inline::Anchor(sec.header.get_anchor()), 1, true);
|
|
|
|
if !sec.get_hide_in_toc() {
|
|
|
|
item.children.append(&mut sec.get_toc_list().items);
|
|
|
|
let mut item = ListItem::new(Inline::Anchor(sec.header.get_anchor()), 1, true);
|
|
|
|
list.add_item(item);
|
|
|
|
item.children.append(&mut sec.get_toc_list().items);
|
|
|
|
|
|
|
|
list.add_item(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Block::Import(imp) => {
|
|
|
|
Block::Import(imp) => {
|
|
|
|
let anchor = imp.anchor.lock().unwrap();
|
|
|
|
let anchor = imp.anchor.lock().unwrap();
|
|
|
@ -286,6 +289,7 @@ impl Section {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
header,
|
|
|
|
header,
|
|
|
|
elements: Vec::new(),
|
|
|
|
elements: Vec::new(),
|
|
|
|
|
|
|
|
metadata: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -317,14 +321,24 @@ impl Section {
|
|
|
|
let mut list = List::new();
|
|
|
|
let mut list = List::new();
|
|
|
|
self.elements.iter().for_each(|e| {
|
|
|
|
self.elements.iter().for_each(|e| {
|
|
|
|
if let Block::Section(sec) = e {
|
|
|
|
if let Block::Section(sec) = e {
|
|
|
|
let mut item = ListItem::new(Inline::Anchor(sec.header.get_anchor()), 1, true);
|
|
|
|
if !sec.get_hide_in_toc() {
|
|
|
|
item.children.append(&mut sec.get_toc_list().items);
|
|
|
|
let mut item = ListItem::new(Inline::Anchor(sec.header.get_anchor()), 1, true);
|
|
|
|
list.add_item(item);
|
|
|
|
item.children.append(&mut sec.get_toc_list().items);
|
|
|
|
|
|
|
|
list.add_item(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
list
|
|
|
|
list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_hide_in_toc(&self) -> bool {
|
|
|
|
|
|
|
|
if let Some(meta) = &self.metadata {
|
|
|
|
|
|
|
|
meta.get_bool("toc-hidden")
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Header {
|
|
|
|
impl Header {
|
|
|
@ -463,3 +477,13 @@ impl Placeholder {
|
|
|
|
self.value = Some(value);
|
|
|
|
self.value = Some(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl InlineMetadata {
|
|
|
|
|
|
|
|
pub fn get_bool(&self, key: &str) -> bool {
|
|
|
|
|
|
|
|
if let Some(MetadataValue::Bool(value)) = self.data.get(key) {
|
|
|
|
|
|
|
|
*value
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|