Skip to content

Commit

Permalink
feat(converter): adapt to latest rust-norg parser changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NTBBloodbath committed Oct 6, 2024
1 parent 6bf119c commit f5d7613
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/converter.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// TODO(ntbbloodbath): move this converter to a separate rust library called norg-converter

use rust_norg::{
parse_tree, NestableDetachedModifier, NorgAST, NorgASTFlat, ParagraphSegmentToken,
parse_tree, NestableDetachedModifier, NorgAST, NorgASTFlat, ParagraphSegment, ParagraphSegmentToken
};

/// Converts a ParagraphSegment into a String
fn paragraph_to_string(segment: &[ParagraphSegmentToken]) -> String {
fn paragraph_to_string(segment: &[ParagraphSegment]) -> String {
let mut paragraph = String::new();
segment.iter().for_each(|node| match node {
ParagraphSegmentToken::Text(s) => paragraph.push_str(s),
ParagraphSegmentToken::Whitespace => paragraph.push(' '),
ParagraphSegmentToken::Special(c) | ParagraphSegmentToken::Escape(c) => paragraph.push(*c),
ParagraphSegment::Token(t) => {
match t {
ParagraphSegmentToken::Text(s) => paragraph.push_str(s),
ParagraphSegmentToken::Whitespace => paragraph.push(' '),
ParagraphSegmentToken::Special(c) | ParagraphSegmentToken::Escape(c) => paragraph.push(*c),
}
},
// TODO(ntbbloodbath): add support for AttachedModifierOpener and AttachedModifierCloser
_ => println!("{:?}", node)
});

paragraph
Expand Down Expand Up @@ -148,6 +154,14 @@ impl NorgToHtml for NorgAST {
}
verbatim_tag
}
NorgAST::CarryoverTag { .. } => { // FIXME: add Carryover tags support
println!("CarryoverTag: {:?}", self);
"".to_string()
}
NorgAST::InfirmTag { .. } => {
println!("InfirmTag: {:?}", self);
"".to_string()
}
_ => {
println!("{:?}", self);
todo!() // Fail on stuff that we cannot parse yet
Expand Down

0 comments on commit f5d7613

Please sign in to comment.