first commit

This commit is contained in:
kitsunecafe 2024-01-29 05:42:38 -05:00
commit c896b9f826
3 changed files with 45 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
/Cargo.lock

10
Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "roxy_markdown_tera_rewriter"
version = "0.1.0"
edition = "2021"
[dependencies]
lol_html = "1.2.0"
regex = "1.10.3"
roxy_core = { git = "https://github.com/kitsunecafe/roxy-core.git" }

33
src/lib.rs Normal file
View File

@ -0,0 +1,33 @@
use regex::Regex;
use lol_html::{element, HtmlRewriter};
use roxy_core::roxy::Parse;
const EXTENSION_RE: &'static Regex = Regex::new("{% extends \"?.+\"? %}");
pub struct MarkdownTeraParser<'a, F: FnMut(&'a [u8]) -> ()> {
rewriter: HtmlRewriter<'a, F>,
output: Vec<u8>
}
impl<'a, O: FnMut(&'a [u8]) -> ()> MarkdownTeraParser<'a, O> {
pub fn new() -> Self {
let mut output = vec![];
Self {
rewriter: HtmlRewriter::new(lol_html::Settings {
element_content_handlers: vec![element!("p", |el| {
if
})],
..Default::default()
}, |c: &[u8]| output.extend_from_slice(c)),
output
}
}
}
// TODO: use an html->dom parser to strip <p> tags around tera placeholders
impl<'a, O: FnMut(&'a [u8]) -> ()> Parse for MarkdownTeraParser<'a, O> {
fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> std::io::Result<()> {
Ok(())
}
}