mok2html 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/History.rdoc +7 -0
- data/README.rdoc +2 -2
- data/RELEASE +1 -1
- data/VERSION +1 -1
- data/bin/mok2html +21 -17
- data/lib/mok2html.rb +23 -14
- data/lib/mok2html_element.rb +21 -13
- data/mok2html.gemspec +1 -1
- data/mok2html.yaml.sample +19 -9
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 748882f17a7376e689ded8e875288b57226f6e3e
|
4
|
+
data.tar.gz: 04e6460b9e18cd45ecdce999b8fe1c03a43ac0b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1c0d8f1fed50eabce1b0cac075a7b93f53ab1d4f0b53044f8319c79c9771745bdc37fe22c67ac27145ac57c844be4f725b45e3ea43b01bcd5582e0088e51ea7
|
7
|
+
data.tar.gz: ca3e7f54d8897d52d5b9429895a34c3d43730e58832b4de59cb03db5d0d3065618d5e0dbeb8129ffceb67b2dc217ff042d7ac493813728f2b7e930c29f0ef078
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mok2html (0.1.
|
5
|
-
mok-parser (>= 0.3.
|
4
|
+
mok2html (0.1.1)
|
5
|
+
mok-parser (>= 0.3.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
mimemagic (0.2.1)
|
11
|
-
mok-parser (0.3.
|
11
|
+
mok-parser (0.3.1)
|
12
12
|
mimemagic
|
13
13
|
rake (10.1.0)
|
14
14
|
|
data/History.rdoc
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.1.1 (2013-12-14)
|
2
|
+
* new: 設定ファイルを無効にする --no-config オプションを追加
|
3
|
+
* new: reference_base_directory オプションを追加
|
4
|
+
* change: HTML5に準拠するように出力するHTMLを修正
|
5
|
+
* change: css と javascript のオプションを複数指定できるように変更
|
6
|
+
* change: media_directory オプションを media_base_directory に変更
|
7
|
+
|
1
8
|
== 0.1.0 (2013-12-12)
|
2
9
|
* プロジェクト名を raf2html から mok2html に変更
|
3
10
|
|
data/README.rdoc
CHANGED
@@ -19,10 +19,10 @@ format manutal : http://garin.jp/doc/mok/mok (this page is japanese)
|
|
19
19
|
|
20
20
|
=== to HTML
|
21
21
|
$ mok2html mydoc.mok
|
22
|
-
<!DOCTYPE html
|
22
|
+
<!DOCTYPE html>
|
23
23
|
...
|
24
24
|
<h1>This is My document</h1> ...
|
25
|
-
<p>mok is simple document format.<br
|
25
|
+
<p>mok is simple document format.<br></p>
|
26
26
|
...
|
27
27
|
|
28
28
|
=== Print Help
|
data/RELEASE
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2013-12-
|
1
|
+
2013-12-14
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bin/mok2html
CHANGED
@@ -7,27 +7,25 @@ require "yaml"
|
|
7
7
|
require "optparse"
|
8
8
|
require "mok2html"
|
9
9
|
|
10
|
-
# 設定ファイル
|
11
|
-
CONFIG_FILE="~/.mok2html.yaml"
|
12
|
-
config_file_path = File.expand_path(CONFIG_FILE)
|
13
|
-
|
14
10
|
# デフォルトの設定値
|
15
|
-
options = {:css => "", :js => "", :reference_extension => '.html', :
|
11
|
+
options = {:css => "", :js => "", :reference_extension => '.html', :reference_base_directory => "", :media_base_directory => "", :custom_element => "" , :language => 'ja', :config => '~/.mok2html.yaml', :index => true, :quiet => false}
|
12
|
+
|
13
|
+
# 使い方
|
14
|
+
def usage(opt)
|
15
|
+
puts opt.help
|
16
|
+
exit 0
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
config = YAML.load_file(
|
19
|
+
def set_config_by_file(file, options)
|
20
|
+
p file
|
21
|
+
config = YAML.load_file( File.expand_path(file) )
|
20
22
|
if config
|
23
|
+
p config
|
21
24
|
options.each do |key,val|
|
22
25
|
options[key.to_sym] = config[key.to_s] unless config[key.to_s].nil?
|
23
26
|
end
|
24
27
|
end
|
25
|
-
|
26
|
-
|
27
|
-
# 使い方
|
28
|
-
def usage(opt)
|
29
|
-
puts opt.help
|
30
|
-
exit 0
|
28
|
+
options
|
31
29
|
end
|
32
30
|
|
33
31
|
# コマンドラインオプション
|
@@ -35,14 +33,16 @@ opt = OptionParser.new do |opt|
|
|
35
33
|
opt.banner = "Usage: mok2html [options] file"
|
36
34
|
opt.version = Mok::Mok2Html::VERSION
|
37
35
|
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}
|
36
|
+
opt.on("-c", "--css file[,file,..]", "HTMLに埋め込むスタイルシートを指定") {|f| options[:css] = f}
|
37
|
+
opt.on("-j", "--javascript file[,file,..]", "HTMLに埋め込むJavaScriptを指定") {|f| options[:js] = f}
|
40
38
|
opt.on("-L", "--language LANG", "言語(デフォルトは #{options[:language]} 。ドキュメント側で指定されていればそちらを優先)"){|l| options[:language] = l}
|
39
|
+
opt.on("--[no-]config [file]", "設定ファイルを指定、または設定ファイルを使用しない(デフォルト:~/.mok2html)"){|v| options[:config] = v }
|
41
40
|
opt.on("--[no-]index", "目次を生成する(デフォルトは生成する)"){|v| options[:index] = v }
|
42
41
|
opt.on("--[no-]metadata", "メタ情報を出力しない(デフォルトは出力する)"){|v| options[:metadata] = v }
|
43
42
|
opt.on("-q","--quiet", "本文だけを出力する(ヘッダやフッタは出力しない)"){ options[:quiet] = true }
|
44
43
|
opt.on("-s","--reference_extension string", "リファレンス記法で「.%」を置換する拡張子(デフォルト .html)"){|s| options[:reference_extension] = s }
|
45
|
-
opt.on("-
|
44
|
+
opt.on("-R", "--reference_base_directory directory", "リンク記法((<..>))のファイルを配置する基底ディレクトリ(デフォルト:なし)"){|d| options[:media_base_directory] = d }
|
45
|
+
opt.on("-M", "--media_base_directory directory", "画像や動画などのメディア記法(($..$))のファイルを配置する基底ディレクトリ(デフォルト:なし)"){|d| options[:media_base_directory] = d }
|
46
46
|
opt.on("--custom_element file", "HTMLタグをカスタマイズするためのRubyファイル)"){|f| options[:custom_element] = f }
|
47
47
|
opt.on("-V","--parser-version", "使用する mok-parser のバージョンを表示"){
|
48
48
|
puts "mok-parser: #{Mok::VERSION} (#{Mok::RELEASE})"
|
@@ -50,8 +50,12 @@ opt = OptionParser.new do |opt|
|
|
50
50
|
}
|
51
51
|
end
|
52
52
|
opt.parse!(ARGV)
|
53
|
+
|
53
54
|
usage(opt) unless ARGV[0]
|
54
55
|
|
56
|
+
# config file
|
57
|
+
options = set_config_by_file(options[:config], options) if options[:config]
|
58
|
+
|
55
59
|
# main
|
56
60
|
src = File.open(ARGV[0],"r").readlines
|
57
61
|
mok = Mok::Mok2Html.new(src, options)
|
data/lib/mok2html.rb
CHANGED
@@ -13,8 +13,8 @@ module Mok
|
|
13
13
|
@debug = true
|
14
14
|
|
15
15
|
# options
|
16
|
-
@css =
|
17
|
-
@js =
|
16
|
+
@css = files_to_str(options[:css])
|
17
|
+
@js = files_to_str(options[:js])
|
18
18
|
@language = options[:language]
|
19
19
|
@index = options[:index]
|
20
20
|
@metadata = options[:metadata]
|
@@ -26,6 +26,16 @@ module Mok
|
|
26
26
|
@nodes = @mok.parse src
|
27
27
|
end
|
28
28
|
|
29
|
+
# 複数ファイルの文字列を返す
|
30
|
+
# files: ファイルの配列または","区切り文字列
|
31
|
+
def files_to_str(files = [])
|
32
|
+
files = files.split(",") unless defined? files.each
|
33
|
+
files.map do |f|
|
34
|
+
path = File.expand_path(f.strip)
|
35
|
+
File.open(path).readlines.join + "\n" unless path.empty?
|
36
|
+
end.join
|
37
|
+
end
|
38
|
+
|
29
39
|
# エレメントのカスタム用ファイルを読み込む
|
30
40
|
def get_customized_element(file)
|
31
41
|
require File.expand_path(file)
|
@@ -61,7 +71,7 @@ module Mok
|
|
61
71
|
next if h[:level] == 1 or h[:level] == 6
|
62
72
|
|
63
73
|
if h[:level] == 5
|
64
|
-
str += %[<div class="nonum"><a href="#mok-head#{h[:level]}-#{i+1}"
|
74
|
+
str += %[<div class="nonum"><span class="space"></span><a href="#mok-head#{h[:level]}-#{i+1}">#{CGI.escapeHTML(h[:title])}</a></div>\n]
|
65
75
|
else
|
66
76
|
str += index_terminate(h[:level], level_pre)
|
67
77
|
str += "<li><a href='#mok-head#{h[:level]}-#{i+1}'>#{h[:index]}#{h[:title]}</a>\n"
|
@@ -106,9 +116,9 @@ module Mok
|
|
106
116
|
return "" if @mok.inline_index[:footnote].nil?
|
107
117
|
str = "<div id='mok-footnote'>"
|
108
118
|
@mok.inline_index[:footnote].each_with_index do |f,i|
|
109
|
-
str +=
|
110
|
-
str +=
|
111
|
-
str += " #{f[:content].map{|c| c.apply}}<br
|
119
|
+
str += %[<a id="mok-footnote-#{i+1}" class="footnote"></a>]
|
120
|
+
str += %[<a href="#mok-footnote-#{i+1}-reverse" class="footnote-reverse">*#{i+1}</a>]
|
121
|
+
str += " #{f[:content].map{|c| c.apply}}<br>"
|
112
122
|
end
|
113
123
|
str += "</div>"
|
114
124
|
str
|
@@ -116,34 +126,33 @@ module Mok
|
|
116
126
|
|
117
127
|
def header
|
118
128
|
str = <<EOL
|
119
|
-
<!DOCTYPE html
|
120
|
-
|
121
|
-
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="#{@metadata[:language]}">
|
129
|
+
<!DOCTYPE html>
|
130
|
+
<html lang="#{@metadata[:language]}">
|
122
131
|
<head>
|
123
|
-
|
132
|
+
<meta charset="utf-8">
|
124
133
|
EOL
|
125
134
|
str += css
|
126
135
|
str += javascript
|
127
136
|
str += <<EOL
|
128
|
-
<title>#{@metadata[:subject]}</title>
|
137
|
+
<title>#{CGI.escapeHTML(@metadata[:subject])}</title>
|
129
138
|
</head>
|
130
139
|
<body>
|
131
140
|
EOL
|
132
141
|
end
|
133
142
|
|
134
143
|
def header_title
|
135
|
-
"<h1>#{@metadata[:subject]}</h1>\n"
|
144
|
+
"<h1>#{CGI.escapeHTML(@metadata[:subject])}</h1>\n"
|
136
145
|
end
|
137
146
|
|
138
147
|
def css
|
139
148
|
str = ""
|
140
|
-
str += %[<style type="text/css"><!--\n#{@css}\n--></style>\n] unless @css.
|
149
|
+
str += %[<style type="text/css"><!--\n#{@css}\n--></style>\n] unless @css.empty?
|
141
150
|
str
|
142
151
|
end
|
143
152
|
|
144
153
|
def javascript
|
145
154
|
str = ""
|
146
|
-
str += %[<script type="text/javascript">#{@js}</script>\n] unless @js.
|
155
|
+
str += %[<script type="text/javascript">#{@js}</script>\n] unless @js.empty?
|
147
156
|
str
|
148
157
|
end
|
149
158
|
|
data/lib/mok2html_element.rb
CHANGED
@@ -7,7 +7,7 @@ require 'mok-parser'
|
|
7
7
|
module Mok
|
8
8
|
class Element
|
9
9
|
def newline_to_br(str)
|
10
|
-
str.gsub("\n", "<br
|
10
|
+
str.gsub("\n", "<br>\n")
|
11
11
|
end
|
12
12
|
|
13
13
|
# @inline_parser.parse の配列を文字列に変換する
|
@@ -18,6 +18,11 @@ module Mok
|
|
18
18
|
end
|
19
19
|
str
|
20
20
|
end
|
21
|
+
|
22
|
+
# アンカーのhref用の文字列を作る
|
23
|
+
def anchor_escape(path)
|
24
|
+
CGI.escapeHTML(path.gsub(" ", "%20"))
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
28
|
# ----- Blocks
|
@@ -39,9 +44,9 @@ module Mok
|
|
39
44
|
return "" if @contents[0] == 1
|
40
45
|
str = ""
|
41
46
|
str += "<h#{@contents[0]} id='mok-head#{@contents[0]}-#{@contents[2]}'>"
|
42
|
-
str +=
|
43
|
-
str += " #{@contents[3]}" unless @contents[0] == 1 or @contents[0] == 5 or @contents[0] == 6
|
44
|
-
str += "#{@contents[1]}</h#{@contents[0]}>\n"
|
47
|
+
str += %[<a id="#{@contents[1].to_code}"></a>]
|
48
|
+
str += " #{CGI.escapeHTML(@contents[3])}" unless @contents[0] == 1 or @contents[0] == 5 or @contents[0] == 6
|
49
|
+
str += "#{CGI.escapeHTML(@contents[1])}</h#{@contents[0]}>\n"
|
45
50
|
str
|
46
51
|
end
|
47
52
|
end
|
@@ -111,8 +116,10 @@ module Mok
|
|
111
116
|
class Desc < Element
|
112
117
|
# @contents = [title, lines]
|
113
118
|
def apply
|
114
|
-
str = %[<dl
|
115
|
-
str += "<dd
|
119
|
+
str = %[<dl>\n<dt>#{@contents[0]}</dt>\n]
|
120
|
+
str += "<dd>"
|
121
|
+
str += "#{inline_parse_to_str(@contents[1])}" unless inline_parse_to_str(@contents[1]).empty?
|
122
|
+
str += "</dd>"
|
116
123
|
str += "</dl>"
|
117
124
|
str
|
118
125
|
end
|
@@ -155,7 +162,7 @@ module Mok
|
|
155
162
|
|
156
163
|
class Reference < Element
|
157
164
|
def apply
|
158
|
-
%[<a href="#{@contents[1]}" title="#{@contents[1]}">#{@contents[0]}</a>]
|
165
|
+
%[<a href="#{anchor_escape(@contents[1])}" title="#{@contents[1]}">#{@contents[0]}</a>]
|
159
166
|
end
|
160
167
|
end
|
161
168
|
|
@@ -192,7 +199,7 @@ module Mok
|
|
192
199
|
end
|
193
200
|
class Verb < Element
|
194
201
|
def apply
|
195
|
-
"#{@contents}"
|
202
|
+
"#{CGI.escapeHTML(@contents.join)}"
|
196
203
|
end
|
197
204
|
end
|
198
205
|
|
@@ -204,6 +211,7 @@ module Mok
|
|
204
211
|
class Ruby < Element
|
205
212
|
def apply
|
206
213
|
"<ruby><rb>#{@contents[0]}</rb><rp>(</rp><rt>#{@contents[1]}</rt><rp>)</rp></ruby>"
|
214
|
+
"<ruby>#{@contents[0]}<rp>(</rp><rt>#{@contents[1]}</rt><rp>)</rp></ruby>"
|
207
215
|
end
|
208
216
|
end
|
209
217
|
class Variable < Element
|
@@ -214,7 +222,7 @@ module Mok
|
|
214
222
|
|
215
223
|
class Footnote < Element
|
216
224
|
def apply
|
217
|
-
|
225
|
+
%[<a href="#mok-footnote-#{@contents[1]}" id="mok-footnote-#{@contents[1]}-reverse" title="#{@contents[0].map {|c| CGI.escapeHTML(c.apply)}}" class="footnote-reverse"><sup><small>*#{@contents[1]}</small></sup></a>]
|
218
226
|
end
|
219
227
|
end
|
220
228
|
|
@@ -223,13 +231,13 @@ module Mok
|
|
223
231
|
# @contents = [Name, Mime::MediaType, Mime::SubType]
|
224
232
|
case @contents[1]
|
225
233
|
when 'image'
|
226
|
-
%[<a href="#{@contents[0]}"><img src="#{@contents[0]}" alt="#{@contents[0]}" class="img-rounded img-responsive"
|
234
|
+
%[<a href="#{anchor_escape(@contents[0])}"><img src="#{@contents[0]}" alt="#{@contents[0]}" class="img-rounded img-responsive"></a>]
|
227
235
|
when 'video'
|
228
|
-
%[<video src="#{@contents[0]}" controls></video>]
|
236
|
+
%[<video src="#{anchor_escape(@contents[0])}" controls></video>]
|
229
237
|
when 'audio'
|
230
|
-
%[<audio src="#{@contents[0]}" controls></audio>]
|
238
|
+
%[<audio src="#{anchor_escape(@contents[0])}" controls></audio>]
|
231
239
|
else
|
232
|
-
%[<a href="#{@contents[0]}">#{@contents[0].split("/").last}</a>]
|
240
|
+
%[<a href="#{anchor_escape(@contents[0])}">#{@contents[0].split("/").last}</a>]
|
233
241
|
end
|
234
242
|
end
|
235
243
|
end
|
data/mok2html.gemspec
CHANGED
data/mok2html.yaml.sample
CHANGED
@@ -7,19 +7,29 @@
|
|
7
7
|
# $ vi ~/.mok2html.yaml
|
8
8
|
#
|
9
9
|
# == 設定項目
|
10
|
-
# コンバート時にHTMLファイルに埋め込むスタイルシート(
|
11
|
-
#css:
|
12
|
-
|
13
|
-
#
|
14
|
-
#
|
10
|
+
# コンバート時にHTMLファイルに埋め込むスタイルシート(デフォルト:なし)
|
11
|
+
# css:
|
12
|
+
# - "~/doc/mok/css/bootstrap.css"
|
13
|
+
# - "~/doc/mok/css/prettify.css"
|
14
|
+
# - "~/doc/mok/css/_document.css"
|
15
|
+
|
16
|
+
# コンバート時にHTMLファイルに埋め込むjavascript(デフォルト:なし)
|
17
|
+
# js:
|
18
|
+
# - "~/doc/mok/js/jquery.js"
|
19
|
+
# - "~/doc/mok/js/bootstrap.js"
|
20
|
+
# - "~/doc/mok/js/prettify.js"
|
21
|
+
# - "~/doc/mok/js/prettify_onload.js"
|
15
22
|
|
16
23
|
# リファレンス記法の「.%」を変換する拡張子(デフォルト:.html)
|
17
24
|
#reference_extension: ".html"
|
18
25
|
|
19
|
-
#
|
20
|
-
#
|
26
|
+
# リンク記法((<..>))のファイルを配置する基底ディレクトリ(デフォルト:なし)
|
27
|
+
#reference_base_directory: ""
|
28
|
+
|
29
|
+
# 画像やビデオ、音声などを配置するディレクトリ(デフォルト:なし)
|
30
|
+
#media_base_directory: "/usr/local/media"
|
21
31
|
|
22
|
-
# HTMLタグをカスタマイズするためのRubyファイル(
|
32
|
+
# HTMLタグをカスタマイズするためのRubyファイル(デフォルト:なし)
|
23
33
|
#custom_element: "/home/myname/mok2html/mycustom.rb"
|
24
34
|
|
25
35
|
# ドキュメントのフォーマット(デフォルト:ja)
|
@@ -31,5 +41,5 @@
|
|
31
41
|
# メタデータを作成するかどうか(デフォルト: true)
|
32
42
|
#metadata: true
|
33
43
|
|
34
|
-
# HTMLヘッダを出力
|
44
|
+
# HTMLヘッダを出力((*しない*))かどうか(デフォルト: false)
|
35
45
|
#quiet: false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mok2html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- garin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.3.
|
47
|
+
version: 0.3.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.3.
|
54
|
+
version: 0.3.1
|
55
55
|
description: mok is simple document format
|
56
56
|
email:
|
57
57
|
- garin54@gmail.com
|