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

Is it possible to generate an HTML AST from Markdown? #926

Open
njlr opened this issue Jun 27, 2024 · 1 comment
Open

Is it possible to generate an HTML AST from Markdown? #926

njlr opened this issue Jun 27, 2024 · 1 comment

Comments

@njlr
Copy link

njlr commented Jun 27, 2024

I would like to parse some Markdown, convert it to HTML, embed that in some other HTML and render it all to an HTML string.

Something like this:

// Not real code

let markdown = Markdown.Parse(content)
let markdownHtml = Markdown.toHtmlElement markdown

let page = 
  html
    []
    [
      div [] [ str "This is my header" ]
      markdownHtml
      div [] [ str "This is my footer" ]
    ]

printfn "%s" (Html.toString html)

From the docs, I can see that FSharp.Formatting supports the markdown parsing bit, and can convert to an HTML string, but does it allow one to work with the HTML AST?

The HTML model appears to be internal.

@nhirschey
Copy link
Collaborator

nhirschey commented Jun 27, 2024

No, not the HTML model. But you can use FSharp.Formatting's internal representation, the literate document type. Once you have the literate document you can manipulate it as you see fit (as you could with an HTML AST).

See https://fsprojects.github.io/FSharp.Formatting/markdown.html

F# has other purpose-built HTML libraries and my recollection from old issues about it is that dsyme wanted this library to have an HTML model that a) didn't depend on anybody else and b) didn't have anybody else depending on it. That's why it's internal.

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

2 participants