Fix nested anchors and placeholders

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/8/head
trivernis 4 years ago
parent d0186cc90e
commit 245c908410
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -102,6 +102,8 @@ impl ParseBlock for Parser {
header.size = size;
self.section_nesting = size;
self.sections.push(size);
self.section_anchors.push(header.anchor.clone());
let mut section = Section::new(header);
section.metadata = metadata;
self.ctm.seek_whitespace();
@ -111,6 +113,7 @@ impl ParseBlock for Parser {
}
self.sections.pop();
self.section_anchors.pop();
if let Some(sec) = self.sections.last() {
self.section_nesting = *sec
} else {
@ -337,8 +340,6 @@ impl ParseBlock for Parser {
.map(|m| m.get_string_map())
.unwrap_or(HashMap::new());
self.ctm.seek_whitespace();
match self.import(path.clone(), &metadata) {
ImportType::Document(Ok(anchor)) => Ok(Some(Import { path, anchor })),
ImportType::Stylesheet(_) => Ok(None),

@ -53,6 +53,9 @@ impl ParseLine for Parser {
self.ctm.get_text()[start_index..self.ctm.get_index()]
.iter()
.for_each(|e| anchor.push(*e));
if let Some(last) = self.section_anchors.last() {
anchor = format!("{}-{}", last, anchor);
}
anchor.retain(|c| !c.is_whitespace());
log::trace!("Line::Header");
Ok(Header::new(line, anchor))

@ -88,6 +88,7 @@ pub struct Parser {
pub(crate) ctm: CharTapeMachine,
section_nesting: u8,
sections: Vec<u8>,
section_anchors: Vec<String>,
section_return: Option<u8>,
wg: WaitGroup,
pub(crate) block_break_at: Vec<char>,
@ -111,6 +112,7 @@ impl Parser {
Self {
options,
sections: Vec::new(),
section_anchors: Vec::new(),
section_nesting: 0,
section_return: None,
wg: WaitGroup::new(),
@ -140,7 +142,7 @@ impl Parser {
text_unil.reverse();
let mut inline_pos = 0;
while text_unil[inline_pos] != LB {
while inline_pos < text_unil.len() && text_unil[inline_pos] != LB {
inline_pos += 1;
}
if let Some(path) = &self.options.path {

@ -35,6 +35,8 @@ const P_GLS: &str = "gls";
const P_DATE: &str = "date";
const P_TIME: &str = "time";
const P_DATETIME: &str = "datetime";
const P_AUTHOR: &str = "author";
const P_TITLE: &str = "title";
impl ProcessPlaceholders for Document {
/// parses all placeholders and assigns values to them
@ -65,6 +67,16 @@ impl ProcessPlaceholders for Document {
P_DATETIME => pholder.set_value(inline!(Inline::Plain(PlainText {
value: format!("{} {}", get_date_string(), get_time_string())
}))),
P_AUTHOR => {
if let Some(value) = self.config.lock().metadata.author.clone() {
pholder.set_value(inline!(Inline::Plain(PlainText { value })))
}
}
P_TITLE => {
if let Some(value) = self.config.lock().metadata.title.clone() {
pholder.set_value(inline!(Inline::Plain(PlainText { value })))
}
}
_ => {
if let Some(value) = self
.config

Loading…
Cancel
Save