first commit
This commit is contained in:
commit
c896b9f826
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
/Cargo.lock
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal 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
33
src/lib.rs
Normal 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(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue