Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions: md2tex and mdbook-latex #12

Open
enaut opened this issue Jul 1, 2020 · 0 comments
Open

Suggestions: md2tex and mdbook-latex #12

enaut opened this issue Jul 1, 2020 · 0 comments

Comments

@enaut
Copy link
Contributor

enaut commented Jul 1, 2020

Hey,

I've selected this as my rustlearn project - I do know several other programming languages, some quite proficient.
I was toying around with this project and copying things into my own project and so on.

Things that I think should be conceptually different:

  • md2tex should be a relatively dumb markdown to tex converter.
    Meaning the following things should be done in mdbook-latex:
    • conversion of URL's
    • adjustment of heading levels
    • copying and converting images
    • adding all the header and footer latex
    • any other preprocessing
  • mdbook-latex should do all the preprocessing and send an Iterator<Event> to md2tex this would remove the parsing and back to string and parsing again from Fix images 2 #10
  • mdbook-latex should do this for every chapter separately and be responsible for putting the chapters together. That way the heading-levels don't get as messed up as they do now... mentioned in Successful Build of rust-lang/book with xelatex #11
  • A first level heading inside a .md file should be one level below it's parent chapter level.

As you cannot AFAIK create a Parser from Events and the Parser is more or less just an Iterator. I'd suggest to change the function signatures so that there is a function that takes an Iterator of events and generates the tex code. That way you can still give it a parser, but also a Vec or something similar I moved the parser-creation to a sepparate function for backwards-compatibility (pullrequest: lbeckman314/md2tex/pull/4):

/// Converts markdown string to tex string. (But I'd not use this function in mdbook-latex)
pub fn markdown_to_tex(markdown: String) -> String {
    let mut options = Options::all();

    let parser = Parser::new_ext(&markdown, options);

    return parser_to_tex(parser); // optionally this could add a very simple header and footer so that the resulting .tex does compile.
}

/// Takes a pulldown_cmark::Parser or any iterator containing `pulldown_cmark::Event` and transforms it to a string
pub fn parser_to_tex<'a, P>(parser: P, headingoffset: u32) -> String
where
    P: 'a + Iterator<Item = Event<'a>>,
{
    [...]

With these changes I think md2tex would be way more flexible and mdbook-latex would be better at correctness and extendability.

I'm going to do some of it anyways to learn rust - should I send pullrequests? If so do you agree with the changes above? what are your 2¢? - what do you want pullrequests for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant