Shoes3 / ebook

An interactive eBook written in Shoes.
2 stars 0 forks source link

shoes to markdown #2

Open ccoupe opened 7 years ago

ccoupe commented 7 years ago

@passenger94 , Do you still have the script to convert the Shoes manual to redcloth md?. For the manual, I see a two stage conversion '.funky_shoes' ->.md and then we can feed that to our kramdown -> ebook thing,

passenger94 commented 7 years ago
# encoding: UTF-8

require 'redcarpet'

markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, fenced_code_blocks: true, 
                                                            no_intra_emphasis: true, 
                                                            autolink: true)

TOPDIR = "path/to/shoes/topdir"
body_html = body_mrkdown = ""

File.open("#{TOPDIR}/static/manual-en.txt", 'r') { |f|
    body_mrkdown = f.read.gsub(/`([\w\-\.\?;=⌘\/]+)`/, '<span style="color:red">\\1</span>')     # word red
        .gsub(/\{{3}(?:\s*\#![^\n]+)?(.+?)\}{3}/m, "```ruby\\1```")                         # code
        .gsub(/\^(.+?)\^/m, '\\1').gsub(/\[\[BR\]\]/i, "\n")                                # ^....^
        .gsub(/'''(.+)'''/, '**\\1**')                                                      # bold
        .gsub(/\[\[(\S+?)\]\]/, '<span style="color:blue">\\1</span>')                      # internal link TODO
        .gsub(/\[\[(\S+?) (.+?)\]\]/, '[\\2](\\1)')                                         # external link
        .gsub(/\!(\{([^}\n]+)\})?([^!\n]+\.\w+)\!/, "![\\2](#{TOPDIR}static/\\3)")          # image
        .gsub(/={4}/, '####').gsub(/={3}/, '###').gsub(/={2}/, '##').gsub(/={1} (.+) ={1}/, '#\\1#') # titles

    body_html = markdown.render(body_mrkdown)
}
# body_mrkdown = f.read.gsub(/`{1}(.+)`{1}/, '<span style="color:red">\\1</span>')     # word red 

html = <<-EOH
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <title>Shoes Manual's red carpet</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>

<body>
    #{body_html}
</body>

</html>
EOH

File.open("#{TOPDIR}/shoesManual_redcarpet01.md", 'w') { |f|
    f << body_mrkdown.gsub("#{TOPDIR}/dist/static", '/static')
}

File.open("#{TOPDIR}/shoesManual_redcarpet01.html", 'w') { |f|
    f << html
}

Markdown is here : https://github.com/passenger94/shoes3/blob/manual_mardown/shoesManual_redcarpet01.md

ccoupe commented 7 years ago

Thank you.