1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/env ruby -Ku
Encoding.default_external = "UTF-8" # wake up, smell the coffee
require 'kramdown'
require 'kramdown-parser-gfm'
options = ''
while /\A-([4bck]+)\z/ === ARGV[0]
ARGV.shift
options << $1
end
if /k/ === options # kramdown
MARKDOWN_BR = "\\\\\n"
end
if /c/ === options # commonmark
MARKDOWN_BR = "\\\n"
end
if /b/ === options # universal HTML
MARKDOWN_BR = "<br/>\n"
end
MARKDOWN_BR ||= " \n" # original Gruber
module Kramdown
module Converter
# Converts an element tree to the kramdown format.
class Kramdown < Base
# Argh
def convert_br(_el, _opts)
MARKDOWN_BR
end
end
end
end
list_indent = 2
list_indent = 4 if /4/ === options
doc = Kramdown::Document.new(ARGF.read, input: 'GFM', gfm_quirks: 'paragraph_end',
list_indent: list_indent)
puts doc.to_kramdown
|