Skip to content

Commit

Permalink
began implementing preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanGreenup committed Oct 29, 2024
1 parent 5077fa2 commit b93eeca
Show file tree
Hide file tree
Showing 6 changed files with 476 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
.aider*
175 changes: 175 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ edition = "2021"

[dependencies]
comrak = "0.29.0"
regex = "1.11.1"
rhai = "1.19.0"
56 changes: 45 additions & 11 deletions src/bin/md_example.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
use draftsmith_render::replace_text;

const DOC: &str = r#"
<div class="ugh">
this is inline html
</div>
:::foo
this is an admonition block
:::
# Heading
# Admonitions
<div class="tip">
<p>Also maps closer to tailwind css (easier for me)</p>
</div>
:::tip
This works
:::foo
Also maps closer to tailwind css (easier for me)
:::
```rust
fn main() {
println!("Hello, world!");
}
```
:::
This is some code:
```markdown
:::tip
This works
:::
Also maps closer to tailwind css (easier for me)
:::
:::
```
# Basic Text
Expand Down Expand Up @@ -74,14 +113,9 @@ fn main() {
let doc = DOC;
let orig = "my";
let repl = "your";
let test_string = std::fs::read_to_string("tests/fixtures/input_divs_code_and_inline_code.md").unwrap();
let expected = std::fs::read_to_string("tests/fixtures/expected_output_divs_code_and_inline_code.md").unwrap().trim_end_matches('\n').to_string();
let html = replace_text(&doc, &orig, &repl);

println!("{}", html);
// Output:
//
// <p>This is your input.</p>
// <ol>
// <li>Also <a href="#">your</a> input.</li>
// <li>Certainly <em>your</em> input.</li>
// </ol>
// println!("{}", html);
}
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
mod processor;

use comrak::nodes::NodeValue;
use comrak::{format_html, parse_document, Arena, Options};
use comrak::{ComrakOptions, ExtensionOptions, ParseOptions, RenderOptions};
use processor::Processor;

pub fn add(left: u64, right: u64) -> u64 {
left + right
Expand Down Expand Up @@ -32,6 +35,11 @@ pub fn replace_text(document: &str, orig_string: &str, replacement: &str) -> Str
let mut options = Options::default();
config_opts(&mut options);

// Preprocess the document
let mut processor = Processor::default();
let document = processor.process(document).as_str();


// get the AST
let root = parse_document(&arena, document, &options);

Expand Down
Loading

0 comments on commit b93eeca

Please sign in to comment.