Project

darkmouun

0.0
The project is in a healthy, maintained state
Darkmouun converts Markdown document to HTML by processing of pre, Mustache template, Kramdown, and post.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 2.0
~> 10.0
~> 3.0

Runtime

 Project Readme

Darkmouun

Overview

Darkmouun is the converter from a markdown text enhanced by kramdown to a HTML document.

Darkmouun can define:

  • Pre-processing (to a markdown document)
  • Extracting templates by Mustache
  • Converting from markdown to HTML by kramdown
  • Post-processing (to a HTML document)

Installation

Add this line to your application's Gemfile:

gem 'darkmouun'

And then execute:

$ bundle

Or install it yourself as:

$ gem install darkmouun

Usage

Darkmouun.document.new takes 3 arguments.

  • 1st arg: Target Markdown file name
  • 2nd arg: Kramdown's parser option (cf. kramdown's usage)
  • 3rd arg: Kramdown's converter name(ex. if converter class name is ItlHtml, converter name is to_itl_html.)

2nd and 3rd argument has default value.

  • 2nd arg: {}
  • 3rd arg: to_html

(Darkmouun instance).convert makes a HTML document from the target markdown document.

You can define pre_process and post_process as a Proc object.

dkmn = Darkmouun.document.new("MARKDOWN DOCUMENT", {:auto_ids => false})
dkmn.pre_process = lambda do |i|
  i.gsub!(/MARKDOWN/, "Markdown")
end
dkmn.post_process = lambda do |i|
  i.gsub!(/DOCUMENT/, "Document")
end
dkmn.convert  #=> "<p>Markdown Document</p>

You can write the parts that Mustache extracts with templates in your markdown document. Template is written as Ruby script, and it is made to define as the subclass of Mustache class.

The part of template extacting in the markdown document starts '<<template_name>>'. Parameters of the template are written below with YAML format.

# Template file 'template_a.rb'

class Template_A < Mustache
  Template = <<EOS
'<p>{{fig1}} + {{fig2}}' is {{calc}}.</p>
EOS

def calc
  (fig1.to_i + fig2.to_i).to_s
end
# converting code

dkmn = Darkmouun.document.new(<<BODY, {:auto_ids => false, :input => 'sekd'}, :se_html)
The calculation:

<<Template_A>>
fig1: 1
fig2: 2
BODY

dkmn.add_templates "#{__dir__}/templates/",  # 1st arg is the directory of templates.
                   'template_a.rb'           # 2nd or later args are the files of templates.

dkmn.convert    #=> <p>The Calculation:</p>
                    <p>1 + 2 is 3.</p>

kramdown extensions

Darkmouun has extended to kramdown. Extensions are below;

  1. Plain span element form. [spanned phrase] is converted to <span>spanned phrase</span>.

  2. Style IAL form. %attritute_name:value; in IAL is converted to style="attribute_name:value;".
    ex. {:%color:#ffffff; %font-weight:bold;} -> style="color:#ffffff; font-weight:bold;"
    ATTENSION: Every attribute must be started from "%" and ended with ";".

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Darkmouun project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.