mok2html 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/COPYING +674 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +21 -0
- data/History.rdoc +35 -0
- data/LICENSE.txt +14 -0
- data/README.rdoc +36 -0
- data/RELEASE +1 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/bin/mok2html +58 -0
- data/lib/mok2html.rb +157 -0
- data/lib/mok2html_element.rb +236 -0
- data/mok2html.gemspec +21 -0
- data/mok2html.yaml.sample +35 -0
- metadata +102 -0
data/Gemfile.lock
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mok2html (0.1.0)
|
5
|
+
mok-parser (>= 0.3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
mimemagic (0.2.1)
|
11
|
+
mok-parser (0.3.0)
|
12
|
+
mimemagic
|
13
|
+
rake (10.1.0)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 1.3)
|
20
|
+
mok2html!
|
21
|
+
rake
|
data/History.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
== 0.1.0 (2013-12-12)
|
2
|
+
* プロジェクト名を raf2html から mok2html に変更
|
3
|
+
|
4
|
+
* new: 新しいQUITE構文の追加
|
5
|
+
* change: Referenceエレメントの拡張子オプション名を extension から reference_extension に変更
|
6
|
+
* change: Quoteエレメントの名前をPreformatに変更
|
7
|
+
|
8
|
+
== 0.0.8 (2013-12-10)
|
9
|
+
* new: Reference の 拡張子書式(.%) に対応(@options[:extension])
|
10
|
+
* new: LabelLink エレメントに対応
|
11
|
+
* new: エレメント(タグ)をカスタマイズできる機能を追加
|
12
|
+
* new: スタイルシート指定のオプション(--css)にショートネーム(-c)を追加
|
13
|
+
* new: javascript を読み込むコマンドラインオプションを追加
|
14
|
+
* new: Quote クラスに出力に google prettify のコードを追加
|
15
|
+
* change: IMAGE エレメントを廃止して、MEDIA エレメントに対応
|
16
|
+
* change: メタデータの項目を変更
|
17
|
+
* change: manuedo の出力フォーマットを変更
|
18
|
+
* change: css, javascript, custom_element オプションのデフォルト値を nil から ""(empty) に変更
|
19
|
+
* fix: Label エレメントのリンクが name ではなく href になっていたのを修正
|
20
|
+
|
21
|
+
== 0.0.7 (2013-12-05)
|
22
|
+
* Variable に対応
|
23
|
+
|
24
|
+
== 0.0.6 (2013-12-05)
|
25
|
+
* 設定ファイル(~/.raf2html.yaml)を追加
|
26
|
+
|
27
|
+
== 0.0.5 (2013-12-04)
|
28
|
+
* kbd書式 ((%...%)) に対応
|
29
|
+
* code書式 (({...})) に対応
|
30
|
+
|
31
|
+
== 0.0.4 (2013-12-03)
|
32
|
+
* minar fix
|
33
|
+
|
34
|
+
== 0.0.3 2013-12-01
|
35
|
+
* raf-parser プロジェクトから独立
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (C) garin <garin54@gmail.com> 2013
|
2
|
+
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
6
|
+
(at your option) any later version.
|
7
|
+
|
8
|
+
This program is distributed in the hope that it will be useful,
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
GNU General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
data/README.rdoc
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= mok2html
|
2
|
+
"mok2html" is mok document convert to HTML.
|
3
|
+
|
4
|
+
== Require
|
5
|
+
* ruby-2.0.0p353 or later
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
// package install
|
9
|
+
$ gem install mok2html
|
10
|
+
|
11
|
+
== Getting Started
|
12
|
+
=== Edit mok document
|
13
|
+
|
14
|
+
$ vi mydoc.mok
|
15
|
+
= This is My document
|
16
|
+
mok is simple document format.
|
17
|
+
|
18
|
+
format manutal : http://garin.jp/doc/mok/mok (this page is japanese)
|
19
|
+
|
20
|
+
=== to HTML
|
21
|
+
$ mok2html mydoc.mok
|
22
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
23
|
+
...
|
24
|
+
<h1>This is My document</h1> ...
|
25
|
+
<p>mok is simple document format.<br /></p>
|
26
|
+
...
|
27
|
+
|
28
|
+
=== Print Help
|
29
|
+
$ mok2html --help
|
30
|
+
|
31
|
+
== Read more
|
32
|
+
Official Web Site : http://garin.jp/doc/mok/mok2html (this page is japanese)
|
33
|
+
|
34
|
+
== Copyright
|
35
|
+
Copyright (c) 2011-2013 garin. See LICENSE.txt for
|
36
|
+
further details.
|
data/RELEASE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2013-12-12
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/mok2html
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# Copyright (C) garin <garin54@gmail.com> 2011-2013
|
4
|
+
# See the included file COPYING for details.
|
5
|
+
$:.unshift File.join(File.dirname(__FILE__), "../lib")
|
6
|
+
require "yaml"
|
7
|
+
require "optparse"
|
8
|
+
require "mok2html"
|
9
|
+
|
10
|
+
# 設定ファイル
|
11
|
+
CONFIG_FILE="~/.mok2html.yaml"
|
12
|
+
config_file_path = File.expand_path(CONFIG_FILE)
|
13
|
+
|
14
|
+
# デフォルトの設定値
|
15
|
+
options = {:css => "", :js => "", :reference_extension => '.html', :media_directory => "", :custom_element => "" , :language => 'ja', :index => true, :quiet => false}
|
16
|
+
|
17
|
+
# 設定ファイルの読み込み
|
18
|
+
if File.exist?(config_file_path)
|
19
|
+
config = YAML.load_file( config_file_path )
|
20
|
+
if config
|
21
|
+
options.each do |key,val|
|
22
|
+
options[key.to_sym] = config[key.to_s] unless config[key.to_s].nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# 使い方
|
28
|
+
def usage(opt)
|
29
|
+
puts opt.help
|
30
|
+
exit 0
|
31
|
+
end
|
32
|
+
|
33
|
+
# コマンドラインオプション
|
34
|
+
opt = OptionParser.new do |opt|
|
35
|
+
opt.banner = "Usage: mok2html [options] file"
|
36
|
+
opt.version = Mok::Mok2Html::VERSION
|
37
|
+
opt.release = Mok::Mok2Html::RELEASE
|
38
|
+
opt.on("-c", "--css file", "HTMLに埋め込むスタイルシートを指定") {|f| options[:css] = f}
|
39
|
+
opt.on("-j", "--javascript file", "HTMLに埋め込むJavaScriptを指定") {|f| options[:js] = f}
|
40
|
+
opt.on("-L", "--language LANG", "言語(デフォルトは #{options[:language]} 。ドキュメント側で指定されていればそちらを優先)"){|l| options[:language] = l}
|
41
|
+
opt.on("--[no-]index", "目次を生成する(デフォルトは生成する)"){|v| options[:index] = v }
|
42
|
+
opt.on("--[no-]metadata", "メタ情報を出力しない(デフォルトは出力する)"){|v| options[:metadata] = v }
|
43
|
+
opt.on("-q","--quiet", "本文だけを出力する(ヘッダやフッタは出力しない)"){ options[:quiet] = true }
|
44
|
+
opt.on("-s","--reference_extension string", "リファレンス記法で「.%」を置換する拡張子(デフォルト .html)"){|s| options[:reference_extension] = s }
|
45
|
+
opt.on("-m", "--media_directory directory", "画像や動画などのメディアファイルを配置する基底ディレクトリ"){|d| options[:media_directory] = d }
|
46
|
+
opt.on("--custom_element file", "HTMLタグをカスタマイズするためのRubyファイル)"){|f| options[:custom_element] = f }
|
47
|
+
opt.on("-V","--parser-version", "使用する mok-parser のバージョンを表示"){
|
48
|
+
puts "mok-parser: #{Mok::VERSION} (#{Mok::RELEASE})"
|
49
|
+
exit 0
|
50
|
+
}
|
51
|
+
end
|
52
|
+
opt.parse!(ARGV)
|
53
|
+
usage(opt) unless ARGV[0]
|
54
|
+
|
55
|
+
# main
|
56
|
+
src = File.open(ARGV[0],"r").readlines
|
57
|
+
mok = Mok::Mok2Html.new(src, options)
|
58
|
+
puts mok.to_html
|
data/lib/mok2html.rb
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) garin <garin54@gmail.com> 2011
|
3
|
+
# See the included file COPYING for details.
|
4
|
+
require "mok2html_element"
|
5
|
+
require "cgi"
|
6
|
+
|
7
|
+
module Mok
|
8
|
+
class Mok2Html
|
9
|
+
VERSION = File.readlines(File.join(File.dirname(__FILE__),"../VERSION"))[0].strip
|
10
|
+
RELEASE = File.readlines(File.join(File.dirname(__FILE__),"../RELEASE"))[0].strip
|
11
|
+
|
12
|
+
def initialize(src, options = {})
|
13
|
+
@debug = true
|
14
|
+
|
15
|
+
# options
|
16
|
+
@css = File.open(File.expand_path(options[:css])).readlines.to_s unless options[:css].empty?
|
17
|
+
@js = File.open(File.expand_path(options[:js])).readlines.to_s unless options[:js].empty?
|
18
|
+
@language = options[:language]
|
19
|
+
@index = options[:index]
|
20
|
+
@metadata = options[:metadata]
|
21
|
+
@quiet = options[:quiet]
|
22
|
+
|
23
|
+
get_customized_element(options[:custom_element]) unless options[:custom_element].empty?
|
24
|
+
@mok = BlockParser.new(options)
|
25
|
+
@metadata = setup_metadata
|
26
|
+
@nodes = @mok.parse src
|
27
|
+
end
|
28
|
+
|
29
|
+
# エレメントのカスタム用ファイルを読み込む
|
30
|
+
def get_customized_element(file)
|
31
|
+
require File.expand_path(file)
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_metadata
|
35
|
+
metadata = @mok.metadata
|
36
|
+
metadata[:language] = @language if metadata[:language].nil?
|
37
|
+
metadata
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_html
|
41
|
+
html = ""
|
42
|
+
html += header unless @quiet
|
43
|
+
html += header_title
|
44
|
+
html += metadata if @metadata
|
45
|
+
html += index if @index
|
46
|
+
html += body
|
47
|
+
html += footnote
|
48
|
+
html += footer unless @quiet
|
49
|
+
html
|
50
|
+
end
|
51
|
+
|
52
|
+
def body
|
53
|
+
@nodes.map do |node| node.apply end.join
|
54
|
+
end
|
55
|
+
|
56
|
+
def index
|
57
|
+
return "" if @mok.index[:head].nil?
|
58
|
+
str = "<div id='mok-index'>"
|
59
|
+
level_pre = 1
|
60
|
+
@mok.index[:head].each_with_index do |h,i|
|
61
|
+
next if h[:level] == 1 or h[:level] == 6
|
62
|
+
|
63
|
+
if h[:level] == 5
|
64
|
+
str += %[<div class="nonum"><a href="#mok-head#{h[:level]}-#{i+1}"><span class="space" />#{h[:title]}</a></div>\n]
|
65
|
+
else
|
66
|
+
str += index_terminate(h[:level], level_pre)
|
67
|
+
str += "<li><a href='#mok-head#{h[:level]}-#{i+1}'>#{h[:index]}#{h[:title]}</a>\n"
|
68
|
+
level_pre = h[:level]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
str += index_terminate(2, level_pre) + "</ul>"
|
72
|
+
str += "</div>"
|
73
|
+
str
|
74
|
+
end
|
75
|
+
|
76
|
+
def index_terminate(level, level_pre)
|
77
|
+
str = ""
|
78
|
+
case level <=> level_pre
|
79
|
+
when 1
|
80
|
+
(level - level_pre).times do
|
81
|
+
str += "<ul>"
|
82
|
+
end
|
83
|
+
when -1
|
84
|
+
(level_pre - level).times do
|
85
|
+
str += "</ul></li>"
|
86
|
+
end
|
87
|
+
else
|
88
|
+
str += "</li>"
|
89
|
+
end
|
90
|
+
str
|
91
|
+
end
|
92
|
+
|
93
|
+
def metadata
|
94
|
+
str = "<div id='mok-metadata'>"
|
95
|
+
str += %[<div>#{CGI.escapeHTML(@metadata[:description])}</div>] unless @metadata[:description].nil?
|
96
|
+
str += %[<ul class="list-inline">]
|
97
|
+
%w{ author create update publisher version tag }.each do |m|
|
98
|
+
str += %[<li><strong>#{m}</strong>:#{CGI.escapeHTML(@metadata[m.to_sym])}</li>] unless @metadata[m.to_sym].nil?
|
99
|
+
end
|
100
|
+
str += "</ul>"
|
101
|
+
str += "</div>"
|
102
|
+
str
|
103
|
+
end
|
104
|
+
|
105
|
+
def footnote
|
106
|
+
return "" if @mok.inline_index[:footnote].nil?
|
107
|
+
str = "<div id='mok-footnote'>"
|
108
|
+
@mok.inline_index[:footnote].each_with_index do |f,i|
|
109
|
+
str += "<a id='mok-footnote-#{i+1}' class='footnote' />"
|
110
|
+
str += "<a href='#mok-footnote-#{i+1}-reverse' class='footnote-reverse'>*#{i+1}</a>"
|
111
|
+
str += " #{f[:content].map{|c| c.apply}}<br />"
|
112
|
+
end
|
113
|
+
str += "</div>"
|
114
|
+
str
|
115
|
+
end
|
116
|
+
|
117
|
+
def header
|
118
|
+
str = <<EOL
|
119
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
120
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
121
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="#{@metadata[:language]}">
|
122
|
+
<head>
|
123
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
124
|
+
EOL
|
125
|
+
str += css
|
126
|
+
str += javascript
|
127
|
+
str += <<EOL
|
128
|
+
<title>#{@metadata[:subject]}</title>
|
129
|
+
</head>
|
130
|
+
<body>
|
131
|
+
EOL
|
132
|
+
end
|
133
|
+
|
134
|
+
def header_title
|
135
|
+
"<h1>#{@metadata[:subject]}</h1>\n"
|
136
|
+
end
|
137
|
+
|
138
|
+
def css
|
139
|
+
str = ""
|
140
|
+
str += %[<style type="text/css"><!--\n#{@css}\n--></style>\n] unless @css.nil?
|
141
|
+
str
|
142
|
+
end
|
143
|
+
|
144
|
+
def javascript
|
145
|
+
str = ""
|
146
|
+
str += %[<script type="text/javascript">#{@js}</script>\n] unless @js.nil?
|
147
|
+
str
|
148
|
+
end
|
149
|
+
|
150
|
+
def footer
|
151
|
+
str = "\n"
|
152
|
+
str += "<div id='rights'>#{@metadata[:rights]}</div>\n" unless @metadata[:rights].nil?
|
153
|
+
str += "</body>\n</html>"
|
154
|
+
str
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) garin <garin54@gmail.com> 2011-2013
|
3
|
+
# See the included file COPYING for details.
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'mok-parser'
|
6
|
+
|
7
|
+
module Mok
|
8
|
+
class Element
|
9
|
+
def newline_to_br(str)
|
10
|
+
str.gsub("\n", "<br />\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
# @inline_parser.parse の配列を文字列に変換する
|
14
|
+
def inline_parse_to_str(array)
|
15
|
+
str = ""
|
16
|
+
array.each do |obj|
|
17
|
+
str += obj.apply
|
18
|
+
end
|
19
|
+
str
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# ----- Blocks
|
24
|
+
class WhiteLine < Element
|
25
|
+
def apply
|
26
|
+
"\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class PlainTextBlock < Element
|
31
|
+
def apply
|
32
|
+
@contents.map {|c| c.apply }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class HeadLine < Element
|
37
|
+
# @contents = [level, title, id, index]
|
38
|
+
def apply
|
39
|
+
return "" if @contents[0] == 1
|
40
|
+
str = ""
|
41
|
+
str += "<h#{@contents[0]} id='mok-head#{@contents[0]}-#{@contents[2]}'>"
|
42
|
+
str += "<a id='#{@contents[1].to_code}'></a>"
|
43
|
+
str += " #{@contents[3]}" unless @contents[0] == 1 or @contents[0] == 5 or @contents[0] == 6
|
44
|
+
str += "#{@contents[1]}</h#{@contents[0]}>\n"
|
45
|
+
str
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Paragraph < Element
|
50
|
+
def apply
|
51
|
+
"<p>#{@contents.map{|c| c.apply}}</p>\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Quote < Element
|
56
|
+
def apply
|
57
|
+
"<blockquote>#{@contents.map{|c|c.apply}}</blockquote>\n"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Preformat < Element
|
62
|
+
def apply
|
63
|
+
%[<pre class="prettyprint linenums">#{CGI.escapeHTML(@contents.join)}</pre>\n]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class ItemList < Element
|
68
|
+
def apply
|
69
|
+
return "" if @contents.empty?
|
70
|
+
type = :dummy
|
71
|
+
str = "<ul>\n"
|
72
|
+
@contents.each do |item|
|
73
|
+
type_pre = type
|
74
|
+
case item
|
75
|
+
when :INDENT
|
76
|
+
type = :indent
|
77
|
+
str += "\n<ul>\n"
|
78
|
+
when :DEDENT
|
79
|
+
type = :dedent
|
80
|
+
str += "</li>\n" if type_pre == :item
|
81
|
+
str += "</ul>\n</li>\n"
|
82
|
+
else
|
83
|
+
type = :item
|
84
|
+
str += "</li>\n" if type_pre == :item
|
85
|
+
str += "<li>#{item.apply}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
str += "\n</li>" if type == :item
|
89
|
+
str += "\n</ul>\n"
|
90
|
+
str
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class NumList < Element
|
95
|
+
def apply
|
96
|
+
str = "<ol>\n"
|
97
|
+
@contents.map do |item|
|
98
|
+
if item == :INDENT
|
99
|
+
str += "<ol>\n"
|
100
|
+
elsif item == :DEDENT
|
101
|
+
str += "</ol>\n"
|
102
|
+
else
|
103
|
+
str += "<li>#{item.apply}</li>\n"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
str += "</ol>\n"
|
107
|
+
str
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class Desc < Element
|
112
|
+
# @contents = [title, lines]
|
113
|
+
def apply
|
114
|
+
str = %[<dl id="#{@contents[0].to_code}">\n<dt>#{@contents[0]}</dt>\n]
|
115
|
+
str += "<dd>#{inline_parse_to_str(@contents[1])}</dd>\n" unless inline_parse_to_str(@contents[1]).empty?
|
116
|
+
str += "</dl>"
|
117
|
+
str
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class Table < Element
|
122
|
+
def apply
|
123
|
+
str = %[<table class="table table-hover">]
|
124
|
+
@contents.each do |line|
|
125
|
+
str += "\n<tr>"
|
126
|
+
line.each do |item|
|
127
|
+
if item =~ /^\s*\*/
|
128
|
+
str += "<th>#{item.sub(/^\s*\*/, "").sub(/\*\s*$/,"")}</th>"
|
129
|
+
else
|
130
|
+
str += "<td>#{item}</td>"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
str += "\n</tr>"
|
134
|
+
end
|
135
|
+
str += "\n</table>"
|
136
|
+
str
|
137
|
+
end
|
138
|
+
end
|
139
|
+
# --- Blocks end
|
140
|
+
|
141
|
+
# --- Inlines
|
142
|
+
class Label < Element
|
143
|
+
# @contents = [label, title]
|
144
|
+
def apply
|
145
|
+
%[<a name="#{@contents[0]}" id="#{@contents[0]}">#{@contents[1]}</a>]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class LabelLink < Element
|
150
|
+
# @contents = [label, title]
|
151
|
+
def apply
|
152
|
+
%[<a href="##{@contents[0]}">#{@contents[1]}</a>]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class Reference < Element
|
157
|
+
def apply
|
158
|
+
%[<a href="#{@contents[1]}" title="#{@contents[1]}">#{@contents[0]}</a>]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
class Plain < Element
|
163
|
+
def apply
|
164
|
+
"#{newline_to_br(CGI.escapeHTML(@contents.join))}"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class Emphasis < Element
|
169
|
+
def apply
|
170
|
+
"<strong>#{@contents.map{|c| c.apply}}</strong>"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
class Italic < Element
|
174
|
+
def apply
|
175
|
+
"<em>#{@contents.map{|c| c.apply}}</em>"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
class Strike < Element
|
179
|
+
def apply
|
180
|
+
"<del>#{@contents.map{|c| c.apply}}</del>"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
class Code < Element
|
184
|
+
def apply
|
185
|
+
"<code>#{@contents.map{|c| c.apply}}</code>"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
class Kbd < Element
|
189
|
+
def apply
|
190
|
+
"<kbd>#{@contents.map{|c| c.apply}}</kbd>"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
class Verb < Element
|
194
|
+
def apply
|
195
|
+
"#{@contents}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
class Manuedo < Element
|
200
|
+
def apply
|
201
|
+
%{<span class="manuedo">[#{@contents.map{|c| c.apply}}]</span>}
|
202
|
+
end
|
203
|
+
end
|
204
|
+
class Ruby < Element
|
205
|
+
def apply
|
206
|
+
"<ruby><rb>#{@contents[0]}</rb><rp>(</rp><rt>#{@contents[1]}</rt><rp>)</rp></ruby>"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
class Variable < Element
|
210
|
+
def apply
|
211
|
+
"#{@contents}"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
class Footnote < Element
|
216
|
+
def apply
|
217
|
+
"<a href='#mok-footnote-#{@contents[1]}' name='mok-footnote-#{@contents[1]}-reverse' title='#{@contents[0].map {|c| c.apply}}' class='footnote-reverse'><sup><small>*#{@contents[1]}</small></sup></a>"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
class Media < Element
|
222
|
+
def apply
|
223
|
+
# @contents = [Name, Mime::MediaType, Mime::SubType]
|
224
|
+
case @contents[1]
|
225
|
+
when 'image'
|
226
|
+
%[<a href="#{@contents[0]}"><img src="#{@contents[0]}" alt="#{@contents[0]}" class="img-rounded img-responsive" /></a>]
|
227
|
+
when 'video'
|
228
|
+
%[<video src="#{@contents[0]}" controls></video>]
|
229
|
+
when 'audio'
|
230
|
+
%[<audio src="#{@contents[0]}" controls></audio>]
|
231
|
+
else
|
232
|
+
%[<a href="#{@contents[0]}">#{@contents[0].split("/").last}</a>]
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
data/mok2html.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "mok2html"
|
5
|
+
spec.version = `cat VERSION`
|
6
|
+
spec.authors = ["garin"]
|
7
|
+
spec.email = ["garin54@gmail.com"]
|
8
|
+
spec.description = %q{mok is simple document format}
|
9
|
+
spec.summary = %q{mok is simple document format}
|
10
|
+
spec.homepage = ""
|
11
|
+
spec.license = "GPLv3"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
spec.add_dependency('mok-parser', '>=0.3.0')
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# = mok2html.yaml.sample
|
2
|
+
# mok2html 設定ファイルのサンプルです
|
3
|
+
#
|
4
|
+
# == 使い方
|
5
|
+
# 自身のホームディレクトリに .mok2html.yaml というファイル名で設置して値を編集します
|
6
|
+
# $ cp mok2html.yaml.sample ~/.mok2html.yaml
|
7
|
+
# $ vi ~/.mok2html.yaml
|
8
|
+
#
|
9
|
+
# == 設定項目
|
10
|
+
# コンバート時にHTMLファイルに埋め込むスタイルシート(デフォルト:"")
|
11
|
+
#css: "~/mok2html.css"
|
12
|
+
|
13
|
+
# コンバート時にHTMLファイルに埋め込むjavascript(デフォルト:"")
|
14
|
+
#js: "~/mok2html.js"
|
15
|
+
|
16
|
+
# リファレンス記法の「.%」を変換する拡張子(デフォルト:.html)
|
17
|
+
#reference_extension: ".html"
|
18
|
+
|
19
|
+
# 画像やビデオ、音声などを配置するディレクトリ(デフォルト:"")
|
20
|
+
#media_directory: "/usr/local/media"
|
21
|
+
|
22
|
+
# HTMLタグをカスタマイズするためのRubyファイル(デフォルト:"")
|
23
|
+
#custom_element: "/home/myname/mok2html/mycustom.rb"
|
24
|
+
|
25
|
+
# ドキュメントのフォーマット(デフォルト:ja)
|
26
|
+
#language: "ja"
|
27
|
+
|
28
|
+
# 目次(index)を作成するかどうか(デフォルト: true)
|
29
|
+
#index: true
|
30
|
+
|
31
|
+
# メタデータを作成するかどうか(デフォルト: true)
|
32
|
+
#metadata: true
|
33
|
+
|
34
|
+
# HTMLヘッダを出力"しない"かどうか(デフォルト: false)
|
35
|
+
#quiet: false
|