nora_mark 0.2beta3 → 0.2beta4

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.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -0
  3. data/Gemfile +2 -0
  4. data/README.md +17 -12
  5. data/example/nora-simple.css +52 -0
  6. data/example/noramark-reference-ja.nora +246 -0
  7. data/example/noramark-reference-ja_00001.xhtml +187 -0
  8. data/lib/nora_mark/html/{abstract_item_writer.rb → abstract_node_writer.rb} +3 -3
  9. data/lib/nora_mark/html/context.rb +3 -21
  10. data/lib/nora_mark/html/frontmatter_writer.rb +33 -0
  11. data/lib/nora_mark/html/generator.rb +122 -100
  12. data/lib/nora_mark/html/pages.rb +3 -9
  13. data/lib/nora_mark/html/paragraph_writer.rb +27 -23
  14. data/lib/nora_mark/html/tag_writer.rb +33 -34
  15. data/lib/nora_mark/html/writer_selector.rb +3 -3
  16. data/lib/nora_mark/node.rb +31 -0
  17. data/lib/nora_mark/parser.kpeg +133 -79
  18. data/lib/nora_mark/parser.kpeg.rb +1822 -1526
  19. data/lib/nora_mark/parser.rb +4 -23
  20. data/lib/nora_mark/version.rb +1 -1
  21. data/lib/nora_mark.rb +7 -2
  22. data/nora_mark.gemspec +1 -0
  23. data/spec/epub30-schemas/epub-nav-30.nvdl +16 -0
  24. data/spec/epub30-schemas/epub-nav-30.rnc +10 -0
  25. data/spec/epub30-schemas/epub-nav-30.sch +72 -0
  26. data/spec/epub30-schemas/epub-svg-30.nvdl +15 -0
  27. data/spec/epub30-schemas/epub-svg-30.rnc +15 -0
  28. data/spec/epub30-schemas/epub-svg-30.sch +10 -0
  29. data/spec/epub30-schemas/epub-xhtml-30.nvdl +15 -0
  30. data/spec/epub30-schemas/epub-xhtml-30.rnc +37 -0
  31. data/spec/epub30-schemas/epub-xhtml-30.sch +377 -0
  32. data/spec/epub30-schemas/epub30-catalog.xml +335 -0
  33. data/spec/epub30-schemas/media-overlay-30.nvdl +14 -0
  34. data/spec/epub30-schemas/media-overlay-30.rnc +46 -0
  35. data/spec/epub30-schemas/media-overlay-30.sch +9 -0
  36. data/spec/epub30-schemas/mod/datatypes.rnc +143 -0
  37. data/spec/epub30-schemas/mod/epub-mathml3-30.rnc +74 -0
  38. data/spec/epub30-schemas/mod/epub-prefix-attr.rnc +8 -0
  39. data/spec/epub30-schemas/mod/epub-ssml-attrs.rnc +11 -0
  40. data/spec/epub30-schemas/mod/epub-svg11-30.rnc +12 -0
  41. data/spec/epub30-schemas/mod/epub-svg11-re.sch +7 -0
  42. data/spec/epub30-schemas/mod/epub-switch.rnc +32 -0
  43. data/spec/epub30-schemas/mod/epub-trigger.rnc +17 -0
  44. data/spec/epub30-schemas/mod/epub-type-attr.rnc +7 -0
  45. data/spec/epub30-schemas/mod/epub-xhtml-mathml3-30.rnc +5 -0
  46. data/spec/epub30-schemas/mod/epub-xhtml-svg11-30.rnc +6 -0
  47. data/spec/epub30-schemas/mod/html5/LICENSE +23 -0
  48. data/spec/epub30-schemas/mod/html5/README +21 -0
  49. data/spec/epub30-schemas/mod/html5/html5-aria-30.rnc +105 -0
  50. data/spec/epub30-schemas/mod/html5/html5-attrib-30.rnc +44 -0
  51. data/spec/epub30-schemas/mod/html5/html5-document-30.rnc +44 -0
  52. data/spec/epub30-schemas/mod/html5/html5-edit-30.rnc +24 -0
  53. data/spec/epub30-schemas/mod/html5/html5-embed-30.rnc +155 -0
  54. data/spec/epub30-schemas/mod/html5/html5-forms-30.rnc +431 -0
  55. data/spec/epub30-schemas/mod/html5/html5-grouping-30.rnc +115 -0
  56. data/spec/epub30-schemas/mod/html5/html5-interactive-30.rnc +86 -0
  57. data/spec/epub30-schemas/mod/html5/html5-models-30.rnc +10 -0
  58. data/spec/epub30-schemas/mod/html5/html5-phrasing-30.rnc +134 -0
  59. data/spec/epub30-schemas/mod/html5/html5-script-30.rnc +164 -0
  60. data/spec/epub30-schemas/mod/html5/html5-sections-30.rnc +58 -0
  61. data/spec/epub30-schemas/mod/html5/html5-style-30.rnc +18 -0
  62. data/spec/epub30-schemas/mod/id-unique.sch +10 -0
  63. data/spec/epub30-schemas/mod/mathml/LICENSE +3 -0
  64. data/spec/epub30-schemas/mod/mathml/mathml3-common.rnc +84 -0
  65. data/spec/epub30-schemas/mod/mathml/mathml3-content.rnc +373 -0
  66. data/spec/epub30-schemas/mod/mathml/mathml3-presentation.rnc +536 -0
  67. data/spec/epub30-schemas/mod/mathml/mathml3-strict-content.rnc +60 -0
  68. data/spec/epub30-schemas/mod/security/LICENSE +4 -0
  69. data/spec/epub30-schemas/mod/security/Lenient-Encryption11-ghc.rnc +41 -0
  70. data/spec/epub30-schemas/mod/security/Lenient-Encryption11.rnc +39 -0
  71. data/spec/epub30-schemas/mod/security/Lenient-Signature-exclusiveC14N.rnc +25 -0
  72. data/spec/epub30-schemas/mod/security/Lenient-Signature11-properties-exclusiveC14N.rnc +32 -0
  73. data/spec/epub30-schemas/mod/security/Lenient-Signature11-properties.rnc +30 -0
  74. data/spec/epub30-schemas/mod/security/Lenient-Signature11.rnc +28 -0
  75. data/spec/epub30-schemas/mod/security/Strict-Encryption.rnc +27 -0
  76. data/spec/epub30-schemas/mod/security/Strict-Signature.rnc +22 -0
  77. data/spec/epub30-schemas/mod/security/exc-c14n.rnc +39 -0
  78. data/spec/epub30-schemas/mod/security/security_any.rnc +15 -0
  79. data/spec/epub30-schemas/mod/security/xenc-allowAnyForeign.rnc +25 -0
  80. data/spec/epub30-schemas/mod/security/xenc-schema-11.rnc +96 -0
  81. data/spec/epub30-schemas/mod/security/xenc-schema.rnc +145 -0
  82. data/spec/epub30-schemas/mod/security/xenc11-allowAnyForeign.rnc +19 -0
  83. data/spec/epub30-schemas/mod/security/xmldsig-allowAnyForeign.rnc +47 -0
  84. data/spec/epub30-schemas/mod/security/xmldsig-core-schema.rnc +276 -0
  85. data/spec/epub30-schemas/mod/security/xmldsig-filter2.rnc +16 -0
  86. data/spec/epub30-schemas/mod/security/xmldsig-properties-schema.rnc +34 -0
  87. data/spec/epub30-schemas/mod/security/xmldsig11-allowAnyForeign.rnc +18 -0
  88. data/spec/epub30-schemas/mod/security/xmldsig11-schema.rnc +133 -0
  89. data/spec/epub30-schemas/mod/security/xmlsec-ghc-allowAnyForeign.rnc +21 -0
  90. data/spec/epub30-schemas/mod/security/xmlsec-ghc-schema.rnc +42 -0
  91. data/spec/epub30-schemas/mod/svg11/LICENSE +1 -0
  92. data/spec/epub30-schemas/mod/svg11/README.txt +8 -0
  93. data/spec/epub30-schemas/mod/svg11/svg11-flat.rnc +3999 -0
  94. data/spec/epub30-schemas/ocf-container-30.rnc +16 -0
  95. data/spec/epub30-schemas/ocf-encryption-30.rnc +12 -0
  96. data/spec/epub30-schemas/ocf-signatures-30.rnc +8 -0
  97. data/spec/epub30-schemas/package-30.nvdl +14 -0
  98. data/spec/epub30-schemas/package-30.rnc +91 -0
  99. data/spec/epub30-schemas/package-30.sch +137 -0
  100. data/spec/jing-20091111/bin/jing.jar +0 -0
  101. data/spec/nora_mark_spec.rb +229 -68
  102. data/spec/spec_helper.rb +16 -0
  103. metadata +179 -6
  104. data/lib/nora_mark/html/header_writer.rb +0 -35
  105. data/spec/fixture/test_src_ja.nora +0 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a2886da05fdf6ceef15ef567fe80634a580b381
4
- data.tar.gz: 0a34c663272a064a68d6256f1743008309fcf0ca
3
+ metadata.gz: 19152110e62f57084dafc55a167fff6204065720
4
+ data.tar.gz: a860f6160b5f15d5571cfe8785ae56a107e2d24f
5
5
  SHA512:
6
- metadata.gz: a38237dbfa6e03d97caf7b80c00413b968faf1e1efb731b692212dee2c33a3dfedc769108dc4ad2c7ef70349ed32afd5d3d69ba9ee69ef3b712f91862fd52d97
7
- data.tar.gz: 3cc67438a689ecfaf3ef11e635ee8d09c9d0b8f8ff50ecfbbd61ccfc7cc973081e1a313d921460fcfaf66bde4216467e2de381b2f41b525fa630427f8e60a22b
6
+ metadata.gz: 438c2688705e6d8cdb66d8387b806c6878232e357f026951b9bac73adf5a3334814239af291fdf1308311161b0f0efc1202edec3eb1da283a1c4b799b517c213
7
+ data.tar.gz: 516efbd14c9176760df9a7a40ed0d87b5bf8b4e40157654e1b941caf377ddfcaef76d01fe9d3f3d171978bcff26cdabf0a859cdf35974e1f907cdc027181b450
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ script: bundle exec rake test
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in nora_mark.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # NoraMark
2
+ [<img src="https://secure.travis-ci.org/skoji/noramark.png" />](http://travis-ci.org/skoji/noramark) [![Coverage Status](https://coveralls.io/repos/skoji/noramark/badge.png?branch=master)](https://coveralls.io/r/skoji/noramark?branch=master)
2
3
 
3
4
  NoraMark is a simple text markup language. It is designed to create XHTML files for EPUB books. Its default mode is for Japanese text.
4
5
 
5
6
  **CAUTION This is very early alpha version, so it's not stable at all, even the markup syntax**
6
7
 
7
- In the next release, the library name will change from NoraMark to NoraMark.
8
- In NoraMark release version, the syntax will be more stable.
8
+ In non-beta release version, the syntax will be more stable.
9
+
10
+ ## Requirements
11
+
12
+ * Ruby 2.0.0 or greater
9
13
 
10
14
  ## Installation
11
15
 
@@ -33,10 +37,13 @@ An example of markup text (text is in english, but the paragraph style is japane
33
37
  # line begins with # is a comment.
34
38
  # you don't need to indent noramark text.
35
39
 
40
+ # page/document metadata in YAML frontmatter
41
+ ---
36
42
  lang: ja
37
43
  title: test title
38
- stylesheets: css/normalize.css, css/main.css
39
-
44
+ stylesheets: [css/normalize.css, css/main.css]
45
+ ---
46
+
40
47
  art {
41
48
  h1: header 1
42
49
  article comes here.
@@ -84,9 +91,11 @@ Another example of markup text in non-japanese (paragraph style is default)
84
91
  # line begins with # is a comment.
85
92
  # you don't need to indent noramark text.
86
93
 
94
+ ---
87
95
  lang: en
88
96
  title: test title
89
- stylesheets: css/normalize.css, css/main.css
97
+ stylesheets: [ css/normalize.css, css/main.css]
98
+ ---
90
99
 
91
100
  art {
92
101
  h1: header 1
@@ -127,9 +136,11 @@ Another example of markup text
127
136
 
128
137
  # Markdown-ish heading will creates section
129
138
 
139
+ ---
130
140
  lang: ja
131
141
  title: test title
132
142
  stylesheets: css/normalize.css, css/main.css
143
+ ---
133
144
 
134
145
  =: this is the first heading
135
146
 
@@ -147,7 +158,7 @@ Another example of markup text
147
158
  The converted XHTML file
148
159
 
149
160
  <?xml version="1.0" encoding="UTF-8"?>
150
- <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
161
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="en">
151
162
  <head>
152
163
  <title>test title</title>
153
164
  <link rel="stylesheet" type="text/css" href="css/normalize.css" />
@@ -169,12 +180,6 @@ The converted XHTML file
169
180
  </section>
170
181
  </body>
171
182
  </html>
172
-
173
-
174
-
175
-
176
-
177
-
178
183
 
179
184
 
180
185
  In a near future version, you will be able to add custom commands.
@@ -0,0 +1,52 @@
1
+ body {
2
+ font-family: serif, sans-serif;
3
+ line-height: 1.75;
4
+ text-align: justify;
5
+ }
6
+
7
+ h1, h2, h3, h4, h5, h6 {
8
+ font-family: sans-serif;
9
+ color: #884444;
10
+ }
11
+
12
+ dt {
13
+ font-family: sans-serif;
14
+ color: #404040;
15
+ }
16
+
17
+ p {
18
+ text-indent: 1em;
19
+ margin-top: 0;
20
+ margin-bottom: 0;
21
+ }
22
+ .noindent {
23
+ text-indent: 0;
24
+ }
25
+
26
+ .pgroup {
27
+ margin-top 1em;
28
+ }
29
+
30
+ pre {
31
+ padding: 0.5em;
32
+ background: #dddddd;
33
+ width: 95%;
34
+ margin: 1em auto;
35
+ border: 1px solid #aaaaaa;
36
+ border-radius: 0.5em;
37
+ }
38
+ pre.code-html {
39
+ background: #efefef;
40
+ }
41
+
42
+ h1 {
43
+ border-bottom: 1px solid #444444;
44
+ }
45
+
46
+ h2 {
47
+ border-bottom: 1px solid #888888;
48
+ }
49
+
50
+ h3 {
51
+ border-bottom: 1px solid #aaaaaa;
52
+ }
@@ -0,0 +1,246 @@
1
+ ---
2
+ lang: ja
3
+ stylesheets: nora-simple.css
4
+ title: NoraMark Manual
5
+ ---
6
+
7
+ =: NoraMark Manual
8
+
9
+ [strong{(作成中・記述は未完成です。)}]
10
+
11
+ NoraMarkは、EPUBで利用するXHTMLを生成するためのマークアップとしてデザインされました。次のような特徴があります。
12
+
13
+ *: プレーンテキストの原稿を邪魔しない最小限の記述
14
+ *: しかしマークアップ部分は、通常のテキストと「違って」見える。
15
+ *: ブロック・ライン・インラインごとの基本記法を原則として固定。憶える記法は少なくてすむはず。
16
+ *: 生のHTML記法なしで、多くのタグを記述できる
17
+ *: マークアップに独自コマンドの追加ができる
18
+ *: 文書構造に対する処理を追加できる
19
+ *: パース結果をXMLとして取得できる
20
+
21
+ ==: 必要なもの
22
+
23
+ *: ruby 2.0以上
24
+
25
+ ==: インストール方法
26
+
27
+ Gemfileに次のように書きます
28
+
29
+ code {
30
+ gem 'nora_mark'
31
+ }
32
+
33
+ そして、
34
+ code {
35
+ $ bundle
36
+ }
37
+
38
+ または
39
+
40
+ code {
41
+ gem install nora_mark
42
+ }
43
+
44
+ ==: 使い方
45
+
46
+ code {//ruby
47
+ require 'nora_mark'
48
+
49
+ document = NoraMark::Document.parse(string_or_io, lang: 'ja')
50
+ document.html.write_as_files
51
+ //}
52
+
53
+ ==: マークアップ
54
+
55
+ ===: 通常のテキスト
56
+
57
+ 単なるテキストもHTMLに変換されます。
58
+
59
+ pre(原稿) {//
60
+ 吾輩は猫である。名前はまだ無い。
61
+ どこで生れたかとんと見当けんとうがつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。
62
+ <中略>
63
+ この書生の掌の裏うちでしばらくはよい心持に坐っておったが、しばらくすると非常な速力で運転し始めた。
64
+
65
+ ふと気が付いて見ると書生はいない。たくさんおった兄弟が一疋ぴきも見えぬ。
66
+ //}
67
+
68
+ code(変換結果) {//html
69
+ <div class='pgroup'>
70
+ <p>吾輩は猫である。名前はまだ無い。</p>
71
+ <p>どこで生れたかとんと見当けんとうがつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。</p>
72
+ <p><中略></p>
73
+ <p>この書生の掌の裏うちでしばらくはよい心持に坐っておったが、しばらくすると非常な速力で運転し始めた。</p>
74
+ </div>
75
+ <div class='pgroup'>
76
+ <p>ふと気が付いて見ると書生はいない。たくさんおった兄弟が一疋ぴきも見えぬ。</p>
77
+ </div>
78
+ //}
79
+
80
+ 改行ごとに<p>要素がつくられます。空行で区切られると、<div class='pgroup'>がつくられます。
81
+ 言語が日本語(ja)以外の場合は、次のようになります。
82
+
83
+ pre(原稿) {
84
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit,
85
+ sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
86
+
87
+ Ut enim ad minim veniam, quis nostrud exercitation
88
+ }
89
+
90
+ code(変換結果) {//html
91
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, <br />sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
92
+ <p>Ut enim ad minim veniam, quis nostrud exercitation</p>
93
+ //}
94
+
95
+ ===: 明示的なブロック
96
+
97
+ NoraMarkでは、<コマンド> { ではじまり、} のみの行で終わる範囲を明示的なブロックとみなします。
98
+
99
+ pre(原稿) {//
100
+ d.column {
101
+ この部分は、divで囲まれます。
102
+ }
103
+ //}
104
+
105
+ code(変換結果) {//html
106
+ <div class="column">
107
+ <div class="pgroup">
108
+ <p>この部分は、divで囲まれます。</p>
109
+ </div>
110
+ </div>
111
+ //}
112
+
113
+ 定義済みの明示的ブロックのコマンドは、次のものがあります。
114
+
115
+ ;: d : divを生成します
116
+ ;: sec, section : sectionを生成します
117
+ ;: art, article : articleを生成します
118
+
119
+ このほかに、後述のpreformatブロックがあります。
120
+
121
+ 未定義のコマンドの場合は、対応する名前のタグを生成します。
122
+
123
+ pre(原稿) {//
124
+ blockquote {
125
+ 山路を登りながら、こう考えた。
126
+ 智に働けば角が立つ。情に棹させば流される。意地を通せば窮屈だ。とかくに人の世は住みにくい
127
+ }
128
+ //}
129
+
130
+ code(変換結果) {//html
131
+ <blockquote>
132
+ <div class='pgroup'>
133
+ <p>山路を登りながら、こう考えた。</p>
134
+ <p>智に働けば角が立つ。情に棹させば流される。意地を通せば窮屈だ。とかくに人の世は住みにくい</p>
135
+ </div>
136
+ </blockquote>
137
+ //}
138
+
139
+ ===: インラインコマンド
140
+
141
+ インラインコマンドは、次の形式をしています。
142
+ pre{//
143
+ [<コマンド>{内容}]
144
+ //}
145
+
146
+ 定義済みのインラインコマンドには、次のものがあります。
147
+
148
+ ;:l {
149
+ リンクを定義する。
150
+ pre {//
151
+ [l(http://github.com/skoji/noramark){NoraMarkのレポジトリ}]
152
+ //}
153
+ }
154
+ ;:s {
155
+ spanを定義する。おもにクラスを設定するときに利用する。
156
+ pre {//
157
+ [s.note{spanの中にはいる}]
158
+ //}
159
+ }
160
+ ;:img {
161
+ 画像を定義する。このコマンドにはブレースのセクションがない。
162
+ pre {//
163
+ [img(img/some_image.jpg,alternate text)]
164
+ //}
165
+ }
166
+ ;:tcy {
167
+ class tcyのspanを定義する。縦書きにおける縦中横のスタイルをあてることを想定している。
168
+ pre {//
169
+ FM TOWNSが登場してからすでに[tcy{25}]年がたった。
170
+ //}
171
+ }
172
+ ;:ruby {
173
+ ルビをマークアップする。
174
+ pre {//
175
+ [ruby(とんぼ){蜻蛉}]の[ruby(めがね){眼鏡}]はみずいろめがね
176
+ //}
177
+ }
178
+
179
+ ===: 行コマンド
180
+
181
+ 行コマンドは1行を占有し、次の形式をしています。
182
+ pre{//
183
+ <コマンド>:内容
184
+ //}
185
+
186
+ 定義済みの行コマンドには、次のものがあります。
187
+
188
+ ;: p {
189
+ パラグラフをマークアップする。主に、クラスやIDを付加する目的で使う。
190
+ pre{//
191
+ p.caution: 用量に注意してご利用ください。
192
+ //}
193
+ }
194
+
195
+ ;: image {
196
+ divでラップされたimgをマークアップする。
197
+ pre{//
198
+ image(./path-to-image/img.jpg, 代替テキスト): イメージのキャプション
199
+ //}
200
+ }
201
+
202
+ ;: newpage {
203
+ 新規ページを作成する。通常は、あらたなXHTMLファイルが生成される。
204
+ pre{//
205
+ newpage:
206
+ //}
207
+
208
+ }
209
+
210
+ ===: リスト
211
+
212
+ ====: 箇条書き
213
+
214
+ pre(原稿) {//
215
+ *: *:ではじまる行は、箇条書きになる。
216
+ *: 空行があくまで、箇条書きがつづく。
217
+
218
+ *: 空行があくと、あらたな箇条書きになる。
219
+ //}
220
+
221
+ code(変換結果) {//html
222
+ <ul><li>*:ではじまる行は、箇条書きになる。 </li>
223
+ <li>空行があくまで、箇条書きがつづく。</li>
224
+ </ul>
225
+ <ul><li>空行があくと、あらたな箇条書きになる。</li>
226
+ </ul>
227
+ }
228
+ //}
229
+
230
+ ====: 番号つきリスト
231
+
232
+ ====: 定義リスト
233
+
234
+ ===: 見出し
235
+
236
+ ====: 単独の見出し
237
+
238
+ ====: セクションを生成する見出し
239
+
240
+ ===: Frontmatter
241
+
242
+ ==: カスタマイズ
243
+ ===: 生成ルール追加
244
+ ===: 木構造の操作
245
+
246
+ ==: XML生成
@@ -0,0 +1,187 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
3
+ <head>
4
+ <title>NoraMark Manual</title>
5
+ <link rel="stylesheet" type="text/css" href="nora-simple.css" />
6
+ </head>
7
+ <body>
8
+ <section><h1>NoraMark Manual</h1>
9
+ <div class='pgroup'><p><strong>(作成中・記述は未完成です。)</strong></p>
10
+ </div>
11
+ <div class='pgroup'><p>NoraMarkは、EPUBで利用するXHTMLを生成するためのマークアップとしてデザインされました。次のような特徴があります。</p>
12
+ </div>
13
+ <ul><li>プレーンテキストの原稿を邪魔しない最小限の記述</li>
14
+ <li>しかしマークアップ部分は、通常のテキストと「違って」見える。</li>
15
+ <li>ブロック・ライン・インラインごとの基本記法を原則として固定。憶える記法は少なくてすむはず。</li>
16
+ <li>生のHTML記法なしで、多くのタグを記述できる</li>
17
+ <li>マークアップに独自コマンドの追加ができる</li>
18
+ <li>文書構造に対する処理を追加できる</li>
19
+ <li>パース結果をXMLとして取得できる</li>
20
+ </ul>
21
+ <section><h2>必要なもの</h2>
22
+ <ul><li>ruby 2.0以上</li>
23
+ </ul>
24
+ </section>
25
+ <section><h2>インストール方法</h2>
26
+ <div class='pgroup'><p>Gemfileに次のように書きます</p>
27
+ </div>
28
+ <pre><code>gem 'nora_mark' </code></pre>
29
+ <div class='pgroup'><p>そして、</p>
30
+ </div>
31
+ <pre><code>$ bundle</code></pre>
32
+ <div class='pgroup'><p>または</p>
33
+ </div>
34
+ <pre><code>gem install nora_mark</code></pre>
35
+ </section>
36
+ <section><h2>使い方</h2>
37
+ <pre class='code-ruby' data-code-language='ruby'><code>require 'nora_mark'
38
+ document = NoraMark::Document.parse(string_or_io, lang: 'ja')
39
+ document.html.write_as_files</code></pre>
40
+ </section>
41
+ <section><h2>マークアップ</h2>
42
+ <section><h3>通常のテキスト</h3>
43
+ <div class='pgroup'><p>単なるテキストもHTMLに変換されます。</p>
44
+ </div>
45
+ <pre>吾輩は猫である。名前はまだ無い。
46
+ どこで生れたかとんと見当けんとうがつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。
47
+ <中略>
48
+ この書生の掌の裏うちでしばらくはよい心持に坐っておったが、しばらくすると非常な速力で運転し始めた。
49
+ ふと気が付いて見ると書生はいない。たくさんおった兄弟が一疋ぴきも見えぬ。</pre>
50
+ <pre class='code-html' data-code-language='html'><code>&lt;div class='pgroup'&gt;
51
+ &lt;p&gt;吾輩は猫である。名前はまだ無い。&lt;/p&gt;
52
+ &lt;p&gt;どこで生れたかとんと見当けんとうがつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。&lt;/p&gt;
53
+ &lt;p&gt;<中略>&lt;/p&gt;
54
+ &lt;p&gt;この書生の掌の裏うちでしばらくはよい心持に坐っておったが、しばらくすると非常な速力で運転し始めた。&lt;/p&gt;
55
+ &lt;/div&gt;
56
+ &lt;div class='pgroup'&gt;
57
+ &lt;p&gt;ふと気が付いて見ると書生はいない。たくさんおった兄弟が一疋ぴきも見えぬ。&lt;/p&gt;
58
+ &lt;/div&gt;</code></pre>
59
+ <div class='pgroup'><p>改行ごとに&lt;p&gt;要素がつくられます。空行で区切られると、&lt;div class='pgroup'&gt;がつくられます。</p>
60
+ <p>言語が日本語(ja)以外の場合は、次のようになります。</p>
61
+ </div>
62
+ <pre>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
63
+ sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
64
+ Ut enim ad minim veniam, quis nostrud exercitation </pre>
65
+ <pre class='code-html' data-code-language='html'><code>&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, &lt;br /&gt;sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &lt;/p&gt;
66
+ &lt;p&gt;Ut enim ad minim veniam, quis nostrud exercitation&lt;/p&gt;</code></pre>
67
+ </section>
68
+ <section><h3>明示的なブロック</h3>
69
+ <div class='pgroup'><p>NoraMarkでは、&lt;コマンド&gt; { ではじまり、} のみの行で終わる範囲を明示的なブロックとみなします。</p>
70
+ </div>
71
+ <pre>d.column {
72
+ この部分は、divで囲まれます。
73
+ }</pre>
74
+ <pre class='code-html' data-code-language='html'><code>&lt;div class=&quot;column&quot;&gt;
75
+ &lt;div class=&quot;pgroup&quot;&gt;
76
+ &lt;p&gt;この部分は、divで囲まれます。&lt;/p&gt;
77
+ &lt;/div&gt;
78
+ &lt;/div&gt;</code></pre>
79
+ <div class='pgroup'><p>定義済みの明示的ブロックのコマンドは、次のものがあります。</p>
80
+ </div>
81
+ <dl><dt>d</dt>
82
+ <dd>divを生成します</dd>
83
+ <dt>sec, section</dt>
84
+ <dd>sectionを生成します</dd>
85
+ <dt>art, article</dt>
86
+ <dd>articleを生成します</dd>
87
+ </dl>
88
+ <div class='pgroup'><p>このほかに、後述のpreformatブロックがあります。</p>
89
+ </div>
90
+ <div class='pgroup'><p>未定義のコマンドの場合は、対応する名前のタグを生成します。</p>
91
+ </div>
92
+ <pre>blockquote {
93
+ 山路を登りながら、こう考えた。
94
+ 智に働けば角が立つ。情に棹させば流される。意地を通せば窮屈だ。とかくに人の世は住みにくい
95
+ }</pre>
96
+ <pre class='code-html' data-code-language='html'><code>&lt;blockquote&gt;
97
+ &lt;div class='pgroup'&gt;
98
+ &lt;p&gt;山路を登りながら、こう考えた。&lt;/p&gt;
99
+ &lt;p&gt;智に働けば角が立つ。情に棹させば流される。意地を通せば窮屈だ。とかくに人の世は住みにくい&lt;/p&gt;
100
+ &lt;/div&gt;
101
+ &lt;/blockquote&gt;</code></pre>
102
+ </section>
103
+ <section><h3>インラインコマンド</h3>
104
+ <div class='pgroup'><p>インラインコマンドは、次の形式をしています。</p>
105
+ </div>
106
+ <pre>[&lt;コマンド&gt;{内容}]</pre>
107
+ <div class='pgroup'><p>定義済みのインラインコマンドには、次のものがあります。</p>
108
+ </div>
109
+ <dl><dt>l</dt>
110
+ <dd><div class='pgroup'><p>リンクを定義する。</p>
111
+ </div>
112
+ <pre>[l(http://github.com/skoji/noramark){NoraMarkのレポジトリ}]</pre></dd>
113
+ <dt>s</dt>
114
+ <dd><div class='pgroup'><p>spanを定義する。おもにクラスを設定するときに利用する。</p>
115
+ </div>
116
+ <pre>[s.note{spanの中にはいる}]</pre></dd>
117
+ <dt>img</dt>
118
+ <dd><div class='pgroup'><p>画像を定義する。このコマンドにはブレースのセクションがない。</p>
119
+ </div>
120
+ <pre>[img(img/some_image.jpg,alternate text)]</pre></dd>
121
+ <dt>tcy</dt>
122
+ <dd><div class='pgroup'><p>class tcyのspanを定義する。縦書きにおける縦中横のスタイルをあてることを想定している。</p>
123
+ </div>
124
+ <pre>FM TOWNSが登場してからすでに[tcy{25}]年がたった。</pre></dd>
125
+ <dt>ruby</dt>
126
+ <dd><div class='pgroup'><p>ルビをマークアップする。</p>
127
+ </div>
128
+ <pre>[ruby(とんぼ){蜻蛉}]の[ruby(めがね){眼鏡}]はみずいろめがね</pre></dd>
129
+ </dl>
130
+ </section>
131
+ <section><h3>行コマンド</h3>
132
+ <div class='pgroup'><p>行コマンドは1行を占有し、次の形式をしています。</p>
133
+ </div>
134
+ <pre>&lt;コマンド&gt;:内容</pre>
135
+ <div class='pgroup'><p>定義済みの行コマンドには、次のものがあります。</p>
136
+ </div>
137
+ <dl><dt>p</dt>
138
+ <dd><div class='pgroup'><p>パラグラフをマークアップする。主に、クラスやIDを付加する目的で使う。</p>
139
+ </div>
140
+ <pre>p.caution: 用量に注意してご利用ください。</pre></dd>
141
+ <dt>image</dt>
142
+ <dd><div class='pgroup'><p>divでラップされたimgをマークアップする。</p>
143
+ </div>
144
+ <pre>image(./path-to-image/img.jpg, 代替テキスト): イメージのキャプション</pre></dd>
145
+ <dt>newpage</dt>
146
+ <dd><div class='pgroup'><p>新規ページを作成する。通常は、あらたなXHTMLファイルが生成される。</p>
147
+ </div>
148
+ <pre>newpage:</pre></dd>
149
+ </dl>
150
+ </section>
151
+ <section><h3>リスト</h3>
152
+ <section><h4>箇条書き</h4>
153
+ <pre>*: *:ではじまる行は、箇条書きになる。
154
+ *: 空行があくまで、箇条書きがつづく。
155
+ *: 空行があくと、あらたな箇条書きになる。</pre>
156
+ <pre class='code-html' data-code-language='html'><code>&lt;ul&gt;&lt;li&gt;*:ではじまる行は、箇条書きになる。 &lt;/li&gt;
157
+ &lt;li&gt;空行があくまで、箇条書きがつづく。&lt;/li&gt;
158
+ &lt;/ul&gt;
159
+ &lt;ul&gt;&lt;li&gt;空行があくと、あらたな箇条書きになる。&lt;/li&gt;
160
+ &lt;/ul&gt;
161
+ }</code></pre>
162
+ </section>
163
+ <section><h4>番号つきリスト</h4>
164
+ <section><h4>定義リスト</h4>
165
+ <section><h3>見出し</h3>
166
+ <section><h4>単独の見出し</h4>
167
+ <section><h4>セクションを生成する見出し</h4>
168
+ <section><h3>Frontmatter</h3>
169
+ <section><h2>カスタマイズ</h2>
170
+ <section><h3>生成ルール追加</h3>
171
+ </section>
172
+ <section><h3>木構造の操作</h3>
173
+ <section><h2>XML生成</h2>
174
+ </section>
175
+ </section>
176
+ </section>
177
+ </section>
178
+ </section>
179
+ </section>
180
+ </section>
181
+ </section>
182
+ </section>
183
+ </section>
184
+ </section>
185
+ </section>
186
+ </body>
187
+ </html>
@@ -1,11 +1,11 @@
1
1
  module NoraMark
2
2
  module Html
3
- class AbstractItemWriter
3
+ class AbstractNodeWriter
4
4
  def initialize(generator)
5
5
  @generator = generator
6
6
  end
7
- def write(item)
8
- item[:children].each do |child|
7
+ def write(node)
8
+ node.content.each do |child|
9
9
  @generator.to_html child
10
10
  end
11
11
  end
@@ -8,10 +8,9 @@ module NoraMark
8
8
  @lang = param[:lang] || 'en'
9
9
  @title = param[:title] || 'NoraMark generated document'
10
10
  @stylesheets = param[:stylesheets] || []
11
- @stylesheets_alt = param[:stylesheets_alt] || []
12
11
  @enable_pgroup = param[:enable_pgroup] || true
13
12
  self.paragraph_style= param[:paragraph_style]
14
- @pages = Pages.new(param[:filename_base], param[:sequence_format])
13
+ @pages = Pages.new(param[:sequence_format])
15
14
  @block_delimiter_stack = []
16
15
  head_inserter do
17
16
  ret = ""
@@ -28,8 +27,8 @@ module NoraMark
28
27
  end
29
28
  end
30
29
 
31
- def created_files
32
- @pages.created_files
30
+ def file_basename=(name)
31
+ @pages.file_basename = name
33
32
  end
34
33
 
35
34
  def chop_last_space
@@ -83,23 +82,6 @@ module NoraMark
83
82
  end
84
83
  end
85
84
 
86
- def enter_block(lexed)
87
- @block_delimiter_stack.push(lexed[:delimiter])
88
- end
89
-
90
- def exit_block(lexed)
91
- @block_delimiter_stack.pop
92
- nil
93
- end
94
-
95
- def block_close?(line)
96
- line == (@block_delimiter_stack.last || '') + '}'
97
- end
98
-
99
- def toc=(label)
100
- @toc[-1] = label if @toc.size > 0
101
- end
102
-
103
85
  def <<(text)
104
86
  if @pages.size == 0 || @pages.last.frozen?
105
87
  start_html
@@ -0,0 +1,33 @@
1
+ module NoraMark
2
+ module Html
3
+ class FrontmatterWriter
4
+ include Util
5
+ def initialize(generator)
6
+ @generator = generator
7
+ @context = generator.context
8
+ @writers = {
9
+ stylesheets: proc do |value|
10
+ value = [value] if value.is_a? String
11
+ @context.stylesheets.concat value
12
+ end,
13
+ title: proc do |value|
14
+ @context.title = escape_html value
15
+ end,
16
+ lang: proc do |value|
17
+ @context.lang = escape_html value.strip
18
+ end,
19
+ paragraph_style: proc do |value|
20
+ @context.paragraph_style = value.strip.to_sym
21
+ end
22
+ }
23
+ end
24
+ def write(node)
25
+ node.yaml.each {
26
+ |k,v|
27
+ writer = @writers[k.to_sym]
28
+ writer.call(v) unless writer.nil?
29
+ }
30
+ end
31
+ end
32
+ end
33
+ end