Comments (8)
I don't think what you want with events is easy.
You really should use an AST. The simplest is to use JavaScript.
from markdown-rs.
Hey!
should fix it
No it doesn’t. That doesn’t take an AST.
What you are looking for is discussed in several open issues. GH-27. GH-32.
from markdown-rs.
Hmm in that case I'd need a way to access and modify the event list as they are being streamed
from markdown-rs.
No, the tickets @wooorm reference are about supporting working with the syntax tree.
The API you want to make public doesn't fix the problem you want to solve, the issues above do.
from markdown-rs.
I don't need a full plugin system, I just need to get between these two lines:
pub fn to_html_with_options(value: &str, options: &Options) -> Result<String, message::Message> {
let (events, parse_state) = parser::parse(value, &options.parse)?;
// do something with events
Ok(to_html::compile(
&events,
parse_state.bytes,
&options.compile,
))
}
In fact working with events is easier than working with the syntax tree since I can just modify the events I care about without needing to recursively nest a heterogeneous tree (which would either be very vebose or require a lot of macros)
A full plugin system would also solve it but since all the elements I need are already natively supported and I don't need any custom HTML it may not be necessary.
from markdown-rs.
I fully understand that just exposing the to_html
API won't be enough now, just thinking about what the new simplest way to make it work is
from markdown-rs.
Something like this should work: (Psuedocode)
let mut text = parse_state.bytes.to_vec();
let mut new_events = vec![];
let mut event_iter = events.into_iter();
while let Some(event) = event_iter.next() {
if let Name::CodeFenced = event.name { // should also check if event.kind == EventKind::Start
if let Some(Name::CodeFencedFence) = event_iter.next().map(|t|t.name) {
// loop until you get a code fenced end event
// check if the name matches your filter
// if so, push the extra strings necessary to text
}
}
// if anything doesn't match, push all the original events to new_events
}
Ok(to_html::compile(
&new_events,
text,
&options.compile,
))
(I'm just arguing for the sake of arguing now, I'll probably just use a different library. Just want to prove it's possible)
from markdown-rs.
Everything is possible but many things are bad. The internal events are not meant to be touched. Either make the plugin system as discussed in the mentioned issues. Or use the JS ecosystem. Or even use client side JS. Or use rust HTML rewriter crates.
from markdown-rs.
Related Issues (20)
- Clarification about MdxJsxFlow/TextElement (discrepancy between MDX Playground?) HOT 3
- Prevent lettered list ? HOT 3
- Panic when testing XSS fussing HOT 8
- Add support for nested fenced code blocks HOT 4
- mdast Inline code should strip prefix+suffix space HOT 7
- MathJax delimiters HOT 5
- Q: support for auto-coloring Rust code? HOT 3
- Installing as a binary HOT 4
- setting the links to nofollow HOT 1
- Incorrect parsing of list + decoration + hard break HOT 1
- Windows absolute image paths not working HOT 1
- The spread and ordered fields in list and list items nodes should be optional HOT 2
- InvalidFormat Error HOT 3
- Markdoc for Markdown-RS HOT 2
- Unable to parse inline JSX element with MDX expression child HOT 5
- Panic with setext heading containing text and JSX tag without matching close
- Panic on markdown::to_html("- ") HOT 1
- HTML output of input with frontmatter strip first newline in first paragraph HOT 1
- The number of newlines after a list alters output of `to_html` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markdown-rs.