Skip to content

Customize parsed markup output. #251

Closed

Description

@matthid

Sometimes you want to be able to change the output of the html generation: https://github.com/matthid/FSharp.Formatting/tree/prismjs_support

But a lot of this is hard-coded: https://github.com/tpetricek/FSharp.Formatting/blob/master/src/FSharp.Markdown/HtmlFormatting.fs

So I'm suggesting to replace this code with RazorEngine templates. This way it would be easier for users to replace the templates. Would you accept this change?
If there is still interest in a RazorEngine alternative we would want to keep the generation code as I don't think we can do the same with other template engines.

I can already think of some problems:

  • *.cshtml templates are written in C# so the code will not be "nice and clean" because of F# interop
  • It complicates things.
  • There will a lot of new small templates, which all needs to be compiled which will lead to longer run-times (cold start)

But there would be some benefits:

  • Users can edit single templates without the need to fork, edit and build FSharp.Formatting.
  • One can use their own strategy to colorize code-blocks.
  • Other outputs than Latex and Html are possible (by just using your own templates)
  • no direct mathjax dependency for formulas

What do you think? I'm thinking about this some time now, but I'm not sure if it's worth the effort.

Activity

  1. tpetricek commented on Jan 15, 2015

    @tpetricek
    Member

    Hmm, this is a tricky question. I would really like to keep the "Markdown" part of F# Formatting as simple as possible - currently, we're using Razor in the "Literate" programming part and in the "MetadataFormat" project, but not in the pure Markdown.

    The fact that we parse Markdown into an AST means that you can quite easily customize the output just by doing an AST transformation (the documentation has an example) and e.g. replace all code blocks with HTML blocks (formatted using your preferred tool) without touching the rest of the document. I think this approach would work just fine in the scenario that you linked above (primjs_support).

    That said, this could certainly be implemented as an extension on top of F# Formatting (it could use F# Formatting for parsing, but then implements new rendering). So, I think you can do this as a separate project - and I'd be happy to link to it, in case people want to customize formatting using Razor.

  2. matthid commented on Jan 15, 2015

    @matthid
    MemberAuthor

    I think this would work well for "Markdown" and "Literate", but for "MetadataFormat" I would need an additional API to replace the Markdown.WriteHtml calls in https://github.com/tpetricek/FSharp.Formatting/blob/master/src/FSharp.MetadataFormat/Main.fs#L490-L497.
    I agree that a separate project might be a better approach overall, thanks for the suggestion.

  3. tpetricek commented on Jan 16, 2015

    @tpetricek
    Member

    Hmm, I wanted to restructure MetadataFormat (for a long time) so that it works in similar way as Literate/Markdown - that is, there are two steps. One that builds some domain model (which you can then process) and a separate step that does the formatting.

    If you feel like getting into this dirty business, let me know :-). I think the start is to split the one massive file to extract the "domain model", "parsing" and "formatting" into 3 separate files. And then we can see how to improve it...

  4. matthid commented on Jan 17, 2015

    @matthid
    MemberAuthor

    Yeah maybe sometime in the future (but unlikely if no immediate need pops up) I can tackle that.

    I found an "OK" solution in the mean time:
    https://github.com/matthid/ircdotnet/blob/ci_docs_and_build/generateDocs.fsx#L54-81
    https://github.com/matthid/ircdotnet/blob/ci_docs_and_build/generateDocs.fsx#L131-171

    Because of the <see cref=""> feature I'm not using the markup parser in the docs anyway (MetadataFormat).
    Thanks for your hints, now I can finally (after merging #240) go back to the official NuGet build 👍 .

    Btw: I saw a discussion somewhere about moving away from the FSharp.Formatting name. I would like to "+1" that. Now seems to be a perfect time since C# dlls are properly supported.

    Closing this for now, thanks again.

  5. added a commit that references this issue on Apr 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions