Make it possible to write articles with Markdown

Let's make it possible to write articles with Markdown. Giblog defaults to Giblog notation, but you can also make it compatible with Markdown. If the extension is "md", let's write it in markdown notation.

Install Markdown module

Perl has several modules on CPAN that convert Markdown input to HTML. Here, let's use Text::Markdown::Hoedown, which has a description similar to the markdown notation of Github.

cpan Text::Markdown::Hoedown

or

cpanm Text::Markdown::Hoedown

If you have cpanm installed, install it with cpanm, and if you only have cpan, install it with cpan.

Modification of the program for writing articles in Markdown

To add / change Giblog functions, modify the build command "lib / Giblog / Command / build.pm". It is safe to back up this file in case the fix accidentally stops working.

Now let's add a feature that can be edited with Markdown to the build command. First, look for the part where the method called parse_giblog_syntax is called.

package Giblog::Command::build;

use base'Giblog::Command';

use strict;
use warnings;
use utf8;

use File::Basename'basename';

sub run {
  # ...

    #Parse Giblog syntax
    $api->parse_giblog_syntax($data);
  
  # ...
}

If the extension of the file is "md", this part is interpreted as Markdown and HTML is output.

sub run {
  # ...

    #Parse Markdown syntax
    if ($data->{file} = ~ /\.md$/) {
      require Text::Markdown::Hoedown;
      
      #Convert extenstion from md to html
      $data->{file} = ~ s /\.md$/.html/;
      
      #Convert Markdown to HTML
      $data->{content} = Text::Markdown::Hoedown::markdown ($data->{content});
    }
    else {
      #Parse Giblog syntax
      $api->parse_giblog_syntax($data);
    }
  
  # ...
}

I'm using the require statement to dynamically load Text::Markdown::Hoedown.

If the file extension is "md", I am writing a process to modify it to html for output.

I am writing a process to change the content from Markdown to HTML using the markdown function.

Let's write an article with Markdown by setting the extension of the file in templates to "md". If the output is HTML, you're successful.