LegNeato / mdbook-typst

An mdBook backend to output Typst markup, pdf, png, or svg
51 stars 3 forks source link

hr support #13

Open cittadhammo opened 1 week ago

cittadhammo commented 1 week ago

hr in markdown are *** on a new line.

In typst they could be

#let hrule = line(length: 100%)
#let hrule = align(center, line(length: 60%))

#hrule

https://github.com/typst/typst/discussions/3708

LegNeato commented 1 week ago

Sounds good! I can poke at these in a couple of weeks when I get back from vacation unless you get to it first. Thank you for the bug reports and suggestions!

cittadhammo commented 1 week ago

Yes, I gave it some thought and started looking at your code. The AI said to implement a custom case to catch any hr in the markdown in there:

image

with something like:

 // Add this case to handle horizontal rules
            (_, Some(ParserEvent::Mdbook(MdbookEvent::MarkdownContentEvent(MdEvent::Start(MdTag::HorizontalRule)))) ) => {
                // Convert hr to Typst
                return Some(ParserEvent::Typst(TypstEvent::Raw(
                    r#"#hr()"#.into(), // Assuming this is how you'd denote a horizontal line in Typst
                )));
            }

But I have to say that your code is almost incomprehensible to me plus the layer of that pullup project which is something else you need to understand (events and what not)

If you have some guidance to start learning how it works, I could have a go, but it looks quite advanced to me. I am used to JS and Node projects.

LegNeato commented 1 week ago

Yeah, the code is pretty ugly because 1) it is broken up into reusable parts (maybe too much!) and 2) everything is iterators, which makes it efficient via stream processing but makes the control flow hard to follow.