Giter Site home page Giter Site logo

Expose to_html::compile about markdown-rs HOT 8 CLOSED

mousetail avatar mousetail commented on September 26, 2024
Expose to_html::compile

from markdown-rs.

Comments (8)

wooorm avatar wooorm commented on September 26, 2024 1

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.

wooorm avatar wooorm commented on September 26, 2024

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.

mousetail avatar mousetail commented on September 26, 2024

Hmm in that case I'd need a way to access and modify the event list as they are being streamed

from markdown-rs.

ChristianMurphy avatar ChristianMurphy commented on September 26, 2024

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.

mousetail avatar mousetail commented on September 26, 2024

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.

mousetail avatar mousetail commented on September 26, 2024

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.

mousetail avatar mousetail commented on September 26, 2024

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.

wooorm avatar wooorm commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.