Recent

Author Topic: Is there a FPC component to convert Markdown to XHTML?  (Read 5911 times)

bulrush

  • Jr. Member
  • **
  • Posts: 86
Is there a FPC component to convert Markdown to XHTML?
« on: June 27, 2016, 08:09:26 pm »
I was just curious if there was a non-visual component that converted Markdown to XHTML for making EPUB books. Shelling out to pandoc for each of 33 chapters is time-consuming. I tried to do it with regular expressions and discovered that's not the way to do it. :)

Is anyone up for the challenge?
Lazarus 1.6.0, FPC 3.0.0, Win 7 64-bit, current Perl programmer.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Is there a FPC component to convert Markdown to XHTML?
« Reply #1 on: June 27, 2016, 10:24:03 pm »
Might be fun, but I won't give any guarantee. I still need to finish my lightweight mustache implementation. Shouldn't be difficult since the language is line oriented and kinda simple, I haven't checked its regularity so I'm not sure if a regular expression is enough to match the whole language. But a state machine with backtracking stack should do.

bulrush

  • Jr. Member
  • **
  • Posts: 86
Re: Is there a FPC component to convert Markdown to XHTML?
« Reply #2 on: June 28, 2016, 05:21:30 pm »
Here's Multimarkdown: http://fletcher.github.io/MultiMarkdown-5/. I'd start with Multimarkdown because it has more features. MMD is a superset of Markdown.

If you would be so kind, be sure to output XHTML, not HTML, as XHTML is used to make EPUB books. XHTML tag reference: http://www.webreference.com/xml/reference/xhtml.html.

Some variations on Markdown use CSS like this:

Code: Pascal  [Select][+][-]
  1. # header 1 {color:#c0c0c0; font-weight:bold;}

which is converted to XHTML:

Code: Pascal  [Select][+][-]
  1. <h1 style="color:#c0c0c0; font-weight:bold;">header 1</h1>

but I was unable to find a link for that, yet.

Online markdown editor here: http://dillinger.io/. I don't know what flavor of Markdown they use. Another online MD editor: http://markdownlivepreview.com/.

For reference, the Perl module to convert Markdown to XHTML: https://metacpan.org/pod/Text::Markup.

Some people have talked about using a parse tree to convert MD to XHTML. I have never taken a class about parse trees. Is this a good method of converting MD to XHTML? Do you have a link for a beginner to learn how to use parse trees? I do not have the skill to make the component myself but I'd like to learn a bit about parsing.
« Last Edit: June 28, 2016, 05:47:56 pm by bulrush »
Lazarus 1.6.0, FPC 3.0.0, Win 7 64-bit, current Perl programmer.

bulrush

  • Jr. Member
  • **
  • Posts: 86
Re: Is there a FPC component to convert Markdown to XHTML?
« Reply #3 on: June 28, 2016, 05:42:05 pm »
If you get around to doing it I will be glad to help you test it. :)
Lazarus 1.6.0, FPC 3.0.0, Win 7 64-bit, current Perl programmer.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Is there a FPC component to convert Markdown to XHTML?
« Reply #4 on: June 28, 2016, 08:41:35 pm »
Some people have talked about using a parse tree to convert MD to XHTML. I have never taken a class about parse trees. Is this a good method of converting MD to XHTML? Do you have a link for a beginner to learn how to use parse trees? I do not have the skill to make the component myself but I'd like to learn a bit about parsing.
Two of my favorite "books":
Neither of them uses syntax tree (I don't want to use term parse tree as parse tree is closer to the grammar instead of the source code, while syntax tree is the real tree resembling the source code) in the final code, but chapter 16 of the 2nd link explains (with sample code) how it could be implemented. Language processing, be it compilation, transpilation, conversion, whatsoever, can be simply viewed as a tree transformation. In the case of Markdown, if you decide to implement it this way, is simply:
Markdown input as string -> Markdown syntax tree data structure -> (X)HTML syntax tree data structure -> (X)HTML output as string.

M.A.R.C.

  • Jr. Member
  • **
  • Posts: 68
Re: Is there a FPC component to convert Markdown to XHTML?
« Reply #5 on: February 22, 2018, 07:23:34 am »
Only for reference, Here: https://github.com/mriscoc/fpc-markdown there is a basic Markdown to HTML converter native for FPC and with code examples written in Lazarus.

 

TinyPortal © 2005-2018