mdbook-typst icon indicating copy to clipboard operation
mdbook-typst copied to clipboard

hr support

Open cittadhammo opened this issue 1 year ago • 3 comments

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

cittadhammo avatar Sep 22 '24 14:09 cittadhammo

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!

LegNeato avatar Sep 22 '24 15:09 LegNeato

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.

cittadhammo avatar Sep 22 '24 15:09 cittadhammo

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.

LegNeato avatar Sep 22 '24 15:09 LegNeato

It's unfortunate that typst doesn't appear to have a function for this. Seems like an obvious feature to have a semantic rule rather than having to draw one with a line. Perhaps I'll put up a patch to add it. At the very least, I can put the event in pullup so that semantics I preserved until the very last bit and let the user decide how it's rendered.

LegNeato avatar Oct 25 '24 21:10 LegNeato

This should be fixed in v0.1.7. Let me know if it is not!

Note that there is a new config option for specifying what you want HR to output.

LegNeato avatar Oct 29 '24 02:10 LegNeato