Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Dancer2 Module for Generating HTML from markdown

by nysus (Vicar)
on Nov 04, 2018 at 00:50 UTC ( #1225182=CUFP: print w/replies, xml ) Need Help??

I wrote a new module for converting markdown files to HTML for use with Dancer2. No perl code is necessary to use! Just make some entries in your config.yml file and you are done. I think it'll be very useful. For example, you can now just throw your copy into a repo with markdown files and clone it to your local hard drive and you are done ever having to mess with HTML.

It has two basic modes of operation right now: convert a single markdown file to a single HTML document or convert all markdown files in a directory to an HTML document. It can can also automatically generate a table of contents for the file that links to the headers in the content.

I've used it to generate a pretty nifty looking tutorial that's super easy to navigate with a table of contents that's actually useful. It's all on one page so no annoying clicking around.

See it on CPAN and the GitHub repo.

I plan on making it have tight integration with GitHub in the near future. I also plan on creating yet another local POD viewer with it as well.

I'd appreciate feedback and ideas for further improvements. Thanks!

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Dancer2 Module for Generating HTML from markdown

Replies are listed 'Best First'.
Re: Dancer2 Module for Generating HTML from markdown
by 1nickt (Abbot) on Nov 05, 2018 at 13:46 UTC

    Hi, Dancer2 is written with Moo. Part of the impetus for creating Dancer was that Catalyst has too heavy a dependency list, including Moose. Why on earth would you introduce Moose as a dependency in a Dancer2 plugin?


    The way forward always starts with a minimal test.

      OK, I dug harder into the Text::Markdown::Hoedown module which uses XS to load some C module that converts markdown to HTML. I was able to figure out how to get it to work with with "fenced" code (code surrounded by a pair to triplet backticks), which is what the GitHub markdown dialect recognizes. I'll release the next version of the module without Markdent, no Moose required.

      Now I can get complaints from people who only like pure perl modules. :)

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        For those interested, back of the envelope calculations in my head say the Hoedown module converts about 5 times faster than Markdent based on my page load times on uncached content.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

        "Now I can get complaints from people who only like pure perl modules."

        Nah, just from those who don't like having to install Dist::Zilla and a thousand plugins for installation ;)

        ps. I'm not knocking Dist::Zilla, I just personally find that it adds a ton of bloat to more-often-than-not a very small distribution.

      The module uses Markdent to parse the markdown files which requires Moose. Converted files are cached so Moose is only called when a file is updated so there is no real performance hit. Although it will require more dependencies, of course. I looked at other options other than Markdent but couldn't find one that supported the GitHub dialect of markdown out of the box.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1225182]
Approved by beech
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2020-05-31 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (173 votes). Check out past polls.

    Notices?