nora_mark 0.2beta13 → 0.2beta14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/nora2html +15 -2
- data/example/noramark-reference-ja_00001.xhtml +31 -31
- data/lib/nora_mark/document.rb +5 -2
- data/lib/nora_mark/html/default_transformer.rb +10 -1
- data/lib/nora_mark/html/generator.rb +5 -1
- data/lib/nora_mark/html/tag_writer.rb +2 -2
- data/lib/nora_mark/html/util.rb +2 -1
- data/lib/nora_mark/node.rb +1 -0
- data/lib/nora_mark/rake_task.rb +58 -0
- data/lib/nora_mark/version.rb +1 -1
- data/spec/nora_mark_spec.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76d472396b1e19fe29839504931e2a0bf98232c9
|
4
|
+
data.tar.gz: de110cb90daac76340084bec401ac96178586911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c763fb0bdb6865ae5eba947996575f393ebad661b7911f6995e24b66d4141d7ef77845e18120fd45849cf3728c8e6b635716625ef4a76402efcb1b9194bd4996
|
7
|
+
data.tar.gz: b398c5108846f929f5e963ddcd0d627cc7d300d3c6da03a4d1dcbcd1b99433d4fb3f4c8694ffb56d999fe0ae7ce5893ced967f1a2f032808d9bda37a78c72d57
|
data/bin/nora2html
CHANGED
@@ -8,8 +8,21 @@ opt.on('--kconv') {
|
|
8
8
|
auto_convert_encode = true
|
9
9
|
}
|
10
10
|
|
11
|
-
|
11
|
+
opt.parse(ARGV)
|
12
|
+
|
13
|
+
transformer_name = File.join(
|
14
|
+
File.dirname(ARGV[0]),
|
15
|
+
File.basename(ARGV[0], '.txt') + '-transform.rb') if !ARGV[0].nil?
|
16
|
+
|
17
|
+
if !transformer_name.nil? and File.exist? transformer_name
|
18
|
+
transformer = File.open(transformer_name).read
|
19
|
+
end
|
20
|
+
|
12
21
|
input = ARGF.read
|
13
22
|
input = Kconv.toutf8(input) if auto_convert_encode
|
14
23
|
|
15
|
-
|
24
|
+
doc = NoraMark::Document::parse(input)
|
25
|
+
|
26
|
+
doc.add_transformer(text: transformer) unless transformer.nil?
|
27
|
+
|
28
|
+
puts doc.render_parameter(nonpaged: true).html[0]
|
@@ -24,7 +24,7 @@
|
|
24
24
|
<section><h3 id='heading_index_4'>Gemfile</h3>
|
25
25
|
<div class='pgroup'><p>Gemfileに次のように書きます</p>
|
26
26
|
</div>
|
27
|
-
<pre><code>gem
|
27
|
+
<pre><code>gem 'nora_mark' </code>
|
28
28
|
</pre>
|
29
29
|
<div class='pgroup'><p>そして、</p>
|
30
30
|
</div>
|
@@ -48,9 +48,9 @@
|
|
48
48
|
</div>
|
49
49
|
</section>
|
50
50
|
<section><h3 id='heading_index_8'>コードから</h3>
|
51
|
-
<pre class='code-ruby' data-code-language='ruby'><code>require
|
51
|
+
<pre class='code-ruby' data-code-language='ruby'><code>require 'nora_mark'
|
52
52
|
|
53
|
-
document = NoraMark::Document.parse(string_or_io, lang:
|
53
|
+
document = NoraMark::Document.parse(string_or_io, lang: 'ja')
|
54
54
|
document.html.write_as_files</code>
|
55
55
|
</pre>
|
56
56
|
</section>
|
@@ -60,9 +60,9 @@ document.html.write_as_files</code>
|
|
60
60
|
<ol><li>normark-mode.elをEmacsのload-pathが通った場所に配置してください。</li>
|
61
61
|
<li><code>~/.emacs.d/init.el</code>に次の記述をしてください。</li>
|
62
62
|
</ol>
|
63
|
-
<pre class='code-emacs-lisp' data-code-language='emacs-lisp'><code>(require
|
64
|
-
(setq auto-mode-alist (cons
|
65
|
-
(setq auto-mode-alist (cons
|
63
|
+
<pre class='code-emacs-lisp' data-code-language='emacs-lisp'><code>(require 'noramark-mode)
|
64
|
+
(setq auto-mode-alist (cons '("\\.nora$" . noramark-mode) auto-mode-alist))
|
65
|
+
(setq auto-mode-alist (cons '("-nora\\.txt$" . noramark-mode) auto-mode-alist))</code>
|
66
66
|
</pre>
|
67
67
|
</section>
|
68
68
|
</section>
|
@@ -79,18 +79,18 @@ document.html.write_as_files</code>
|
|
79
79
|
ふと気が付いて見ると書生はいない。たくさんおった兄弟が一疋ぴきも見えぬ。</pre>
|
80
80
|
</div>
|
81
81
|
<div class='pre'><p class='caption'>変換結果</p>
|
82
|
-
<pre class='code-html' data-code-language='html'><code><div class
|
82
|
+
<pre class='code-html' data-code-language='html'><code><div class='pgroup'>
|
83
83
|
<p>吾輩は猫である。名前はまだ無い。</p>
|
84
84
|
<p>どこで生れたかとんと見当けんとうがつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。</p>
|
85
85
|
<p><中略></p>
|
86
86
|
<p>この書生の掌の裏うちでしばらくはよい心持に坐っておったが、しばらくすると非常な速力で運転し始めた。</p>
|
87
87
|
</div>
|
88
|
-
<div class
|
88
|
+
<div class='pgroup'>
|
89
89
|
<p>ふと気が付いて見ると書生はいない。たくさんおった兄弟が一疋ぴきも見えぬ。</p>
|
90
90
|
</div></code>
|
91
91
|
</pre>
|
92
92
|
</div>
|
93
|
-
<div class='pgroup'><p>改行ごとに<code><p></code>要素がつくられます。空行で区切られると<code><div class
|
93
|
+
<div class='pgroup'><p>改行ごとに<code><p></code>要素がつくられます。空行で区切られると<code><div class='pgroup'></code>がつくられます。</p>
|
94
94
|
</div>
|
95
95
|
<div class='pgroup'><p>言語が日本語(ja)以外の場合は、次のようになります。</p>
|
96
96
|
</div>
|
@@ -163,7 +163,7 @@ Ut enim ad minim veniam, quis nostrud exercitation </pre>
|
|
163
163
|
</div>
|
164
164
|
<div class='pre'><p class='caption'>変換結果</p>
|
165
165
|
<pre class='code-html' data-code-language='html'><code><blockquote>
|
166
|
-
<div class
|
166
|
+
<div class='pgroup'>
|
167
167
|
<p>山路を登りながら、こう考えた。</p>
|
168
168
|
<p>智に働けば角が立つ。情に棹させば流される。意地を通せば窮屈だ。とかくに人の世は住みにくい</p>
|
169
169
|
</div>
|
@@ -236,7 +236,7 @@ puts "Hello, World."
|
|
236
236
|
</pre>
|
237
237
|
</div>
|
238
238
|
<div class='pre'><p class='caption'>変換結果</p>
|
239
|
-
<pre class='code-html' data-code-language='html'><code><pre class
|
239
|
+
<pre class='code-html' data-code-language='html'><code><pre class='code-ruby' data-code-language='ruby'><code>
|
240
240
|
puts "Hello, World."
|
241
241
|
</code></pre></code>
|
242
242
|
</pre>
|
@@ -245,23 +245,23 @@ puts "Hello, World."
|
|
245
245
|
<section><h5 id='heading_index_15'>キャプションの指定</h5>
|
246
246
|
<div class='pre'><p class='caption'>原稿</p>
|
247
247
|
<pre>code(ソースコードはこちら) {
|
248
|
-
puts
|
248
|
+
puts 'Hello, World'
|
249
249
|
}</pre>
|
250
250
|
</div>
|
251
251
|
<div class='pgroup'><p>または、こんな書き方もできます。</p>
|
252
252
|
</div>
|
253
253
|
<div class='pre'><p class='caption'>原稿</p>
|
254
254
|
<pre>```(ソースコードはこちら)
|
255
|
-
puts
|
255
|
+
puts 'Hello, World'
|
256
256
|
```</pre>
|
257
257
|
</div>
|
258
258
|
<div class='pgroup'><p>こんな風になります。</p>
|
259
259
|
</div>
|
260
260
|
<div class='pre'><p class='caption'>変換結果</p>
|
261
|
-
<pre class='code-html' data-code-language='html'><code><div class
|
262
|
-
<p class
|
261
|
+
<pre class='code-html' data-code-language='html'><code><div class='pre'>
|
262
|
+
<p class='caption'>原稿はこちら</p>
|
263
263
|
<pre><code>
|
264
|
-
puts
|
264
|
+
puts 'Hello, World'
|
265
265
|
</code></pre>
|
266
266
|
</div></code>
|
267
267
|
</pre>
|
@@ -280,7 +280,7 @@ puts 'Hello, World'
|
|
280
280
|
</div>
|
281
281
|
<pre>[l(http://github.com/skoji/noramark){NoraMarkのレポジトリ}]</pre>
|
282
282
|
<div class='pre'><p class='caption'>変換結果</p>
|
283
|
-
<pre class='code-html' data-code-language='html'><code><a href
|
283
|
+
<pre class='code-html' data-code-language='html'><code><a href='http://github.com/skoji/noramark'>NoraMarkのレポジトリ</a></code>
|
284
284
|
</pre>
|
285
285
|
</div>
|
286
286
|
</dd>
|
@@ -289,7 +289,7 @@ puts 'Hello, World'
|
|
289
289
|
</div>
|
290
290
|
<pre>[sp.note{spanの中にはいる}]</pre>
|
291
291
|
<div class='pre'><p class='caption'>変換結果</p>
|
292
|
-
<pre class='code-html' data-code-language='html'><code><span class
|
292
|
+
<pre class='code-html' data-code-language='html'><code><span class='note">spanの中に入る</span></code>
|
293
293
|
</pre>
|
294
294
|
</div>
|
295
295
|
</dd>
|
@@ -298,7 +298,7 @@ puts 'Hello, World'
|
|
298
298
|
</div>
|
299
299
|
<pre>[img(img/some_image.jpg,alternate text)]</pre>
|
300
300
|
<div class='pre'><p class='caption'>変換結果</p>
|
301
|
-
<pre class='code-html' data-code-language='html'><code><img src
|
301
|
+
<pre class='code-html' data-code-language='html'><code><img src='img/some_image.jpg' alt='alternate text' /></code>
|
302
302
|
</pre>
|
303
303
|
</div>
|
304
304
|
</dd>
|
@@ -307,7 +307,7 @@ puts 'Hello, World'
|
|
307
307
|
</div>
|
308
308
|
<pre>FM TOWNSが登場してからすでに[tcy{25}]年がたった。</pre>
|
309
309
|
<div class='pre'><p class='caption'>変換結果</p>
|
310
|
-
<pre class='code-html' data-code-language='html'><code><p>FM TOWNSが登場してからすでに<span class
|
310
|
+
<pre class='code-html' data-code-language='html'><code><p>FM TOWNSが登場してからすでに<span class='tcy'>25</span>年がたった。</p></code>
|
311
311
|
</pre>
|
312
312
|
</div>
|
313
313
|
</dd>
|
@@ -350,7 +350,7 @@ puts 'Hello, World'
|
|
350
350
|
</div>
|
351
351
|
<pre>p.caution: 用量に注意してご利用ください。</pre>
|
352
352
|
<div class='pre'><p class='caption'>変換結果</p>
|
353
|
-
<pre class='code-html' data-code-language='html'><code><p class
|
353
|
+
<pre class='code-html' data-code-language='html'><code><p class='caution'>用量に注意してご利用ください。</p></code>
|
354
354
|
</pre>
|
355
355
|
</div>
|
356
356
|
<dl><dt>image</dt>
|
@@ -358,8 +358,8 @@ puts 'Hello, World'
|
|
358
358
|
</div>
|
359
359
|
<pre>image(path-to-image/img.jpg, 代替テキスト): イメージのキャプション</pre>
|
360
360
|
<div class='pre'><p class='caption'>変換結果</p>
|
361
|
-
<pre class='code-html' data-code-language='html'><code><figure class
|
362
|
-
<img src
|
361
|
+
<pre class='code-html' data-code-language='html'><code><figure class='img-wrap'>
|
362
|
+
<img src='path-to-image/img.jpg' alt='代替テキスト' />
|
363
363
|
<figcaption>イメージのキャプション</figcaption>
|
364
364
|
</figure></code>
|
365
365
|
</pre>
|
@@ -478,7 +478,7 @@ li: 第三の要素
|
|
478
478
|
</div>
|
479
479
|
<div class='pre'><p class='caption'>変換結果</p>
|
480
480
|
<pre class='code-html' data-code-language='html'><code><h1>単独の見出し</h1>
|
481
|
-
<div class
|
481
|
+
<div class='pgroup'>
|
482
482
|
<p>ここに本文</p>
|
483
483
|
</div></code>
|
484
484
|
</pre>
|
@@ -494,7 +494,7 @@ li: 第三の要素
|
|
494
494
|
<div class='pre'><p class='caption'>変換結果</p>
|
495
495
|
<pre class='code-html' data-code-language='html'><code><section>
|
496
496
|
<h1>見出し</h1>
|
497
|
-
<div class
|
497
|
+
<div class='pgroup'>
|
498
498
|
<p>本文</p>
|
499
499
|
</div>
|
500
500
|
</section></code>
|
@@ -513,19 +513,19 @@ li: 第三の要素
|
|
513
513
|
<div class='pre'><p class='caption'>変換結果</p>
|
514
514
|
<pre class='code-html' data-code-language='html'><code><section>
|
515
515
|
<h1>見出し</h1>
|
516
|
-
<div class
|
516
|
+
<div class='pgroup'>
|
517
517
|
<p>本文</p>
|
518
518
|
</div>
|
519
519
|
<section>
|
520
520
|
<h2>小見出し</h2>
|
521
|
-
<div class
|
521
|
+
<div class='pgroup'>
|
522
522
|
<p>次の本文</p>
|
523
523
|
</div>
|
524
524
|
</section>
|
525
525
|
</section>
|
526
526
|
<section>
|
527
527
|
<h1>新しい章</h1>
|
528
|
-
<div class
|
528
|
+
<div class='pgroup'>
|
529
529
|
<p>新しい章の本文</p>
|
530
530
|
</div>
|
531
531
|
</section></code>
|
@@ -544,15 +544,15 @@ li: 第三の要素
|
|
544
544
|
<div class='pre'><p class='caption'>変換結果</p>
|
545
545
|
<pre class='code-html' data-code-language='html'><code><section>
|
546
546
|
<h1>第一のセクション</h1>
|
547
|
-
<div class
|
547
|
+
<div class='pgroup'>
|
548
548
|
<p>ここは第一のセクション</p>
|
549
549
|
</div>
|
550
550
|
<section>第二のセクション</h1>
|
551
|
-
<div class
|
551
|
+
<div class='pgroup'>
|
552
552
|
<p>ここは第二のセクション</p>
|
553
553
|
</div>
|
554
554
|
</section>
|
555
|
-
<div class
|
555
|
+
<div class='pgroup'>
|
556
556
|
<p>ここは再び第一のセクション</p>
|
557
557
|
</div>
|
558
558
|
</section></code>
|
data/lib/nora_mark/document.rb
CHANGED
@@ -59,9 +59,12 @@ module NoraMark
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
frontmatter = instance.root.find_node :type => :Frontmatter
|
62
|
-
if (frontmatter
|
63
|
-
|
62
|
+
if (frontmatter)
|
63
|
+
if (frontmatter.yaml['generator'])
|
64
|
+
NoraMark::Extensions.register_generator(frontmatter.yaml['generator'].to_sym)
|
65
|
+
end
|
64
66
|
end
|
67
|
+
|
65
68
|
instance
|
66
69
|
end
|
67
70
|
|
@@ -31,6 +31,12 @@ module NoraMark
|
|
31
31
|
(@node.attrs ||= {}).merge!({href: [@node.params[0].text]})
|
32
32
|
end
|
33
33
|
|
34
|
+
replace 'noescape' do
|
35
|
+
node = text(@node.text)
|
36
|
+
node.noescape = true
|
37
|
+
node
|
38
|
+
end
|
39
|
+
|
34
40
|
modify 'ruby' do
|
35
41
|
@node.append_child inline 'rp', '('
|
36
42
|
@node.append_child inline 'rt', escape_html(@node.params[0].text.strip)
|
@@ -50,10 +56,13 @@ module NoraMark
|
|
50
56
|
end
|
51
57
|
|
52
58
|
replace 'image' do
|
59
|
+
imagenode = inline('img', nil,
|
60
|
+
body_empty: true,
|
61
|
+
attrs: {src: [ @node.params[0].text.strip], alt: [ (@node.params[1].text ||'').strip ] })
|
53
62
|
newnode = block('figure',
|
54
63
|
class_if_empty:'img-wrap',
|
55
64
|
ids: @node.ids,
|
56
|
-
children: [
|
65
|
+
children: [ imagenode],
|
57
66
|
template: @node)
|
58
67
|
if !@node.children_empty?
|
59
68
|
if @node.n[:caption_before]
|
@@ -103,7 +103,11 @@ module NoraMark
|
|
103
103
|
|
104
104
|
def to_html(node)
|
105
105
|
if node.kind_of? Text
|
106
|
-
|
106
|
+
if node.noescape
|
107
|
+
@context << node.content
|
108
|
+
else
|
109
|
+
@context << escape_html(node.content)
|
110
|
+
end
|
107
111
|
else
|
108
112
|
writer = @writers[node.class]
|
109
113
|
if writer.nil?
|
@@ -31,11 +31,11 @@ module NoraMark
|
|
31
31
|
if vals.nil?
|
32
32
|
''
|
33
33
|
elsif !vals.is_a? Array
|
34
|
-
" #{name}='#{name}'"
|
34
|
+
" #{name}='#{escape_html(name)}'"
|
35
35
|
elsif vals.size == 0
|
36
36
|
''
|
37
37
|
else
|
38
|
-
" #{name}='#{vals.join(' ')}'"
|
38
|
+
" #{name}='#{escape_html(vals.join(' '))}'"
|
39
39
|
end
|
40
40
|
end.join('')
|
41
41
|
end
|
data/lib/nora_mark/html/util.rb
CHANGED
data/lib/nora_mark/node.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'nora_mark'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
|
4
|
+
module NoraMark
|
5
|
+
class RakeTask < ::Rake::TaskLib
|
6
|
+
attr_accessor :lang, :page_number_digits
|
7
|
+
def initialize(lang: 'en')
|
8
|
+
@preprocessors = []
|
9
|
+
@transformers = []
|
10
|
+
yield self if block_given?
|
11
|
+
@lang ||= lang
|
12
|
+
@page_number_digits ||= 5
|
13
|
+
define
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_preprocessor(&block)
|
17
|
+
@preprocessors << block;
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_transformer(&block)
|
21
|
+
@transformers << block;
|
22
|
+
end
|
23
|
+
|
24
|
+
def define
|
25
|
+
desc "rule for *-nora.txt to *-nora_xxx.html. Use *-nora-transform.rb on same directory as transformer"
|
26
|
+
rule( /-((nora)|(arti))_[0-9]{#{page_number_digits}}\.xhtml/ =>
|
27
|
+
proc {|task_name|
|
28
|
+
task_name.sub(/^(.+?-((nora)|(arti)))_[0-9]{#{page_number_digits}}\.xhtml/, '\1.txt')
|
29
|
+
}) do
|
30
|
+
|t|
|
31
|
+
|
32
|
+
dir = File.dirname File.expand_path(t.source)
|
33
|
+
transformer_name = File.join dir, File.basename(t.source, '.txt') + '-transform.rb'
|
34
|
+
nora =
|
35
|
+
NoraMark::Document.parse(
|
36
|
+
File.open(t.source),
|
37
|
+
:lang => @lang,
|
38
|
+
:sequence_format => "%0#{page_number_digits}d",
|
39
|
+
:document_name=>t.name.sub(/_[0-9]{3}\.xhtml/, '')) do
|
40
|
+
|doc|
|
41
|
+
@preprocessors.each do
|
42
|
+
|prepro|
|
43
|
+
doc.preprocessor(&prepro)
|
44
|
+
end
|
45
|
+
@transformers.each do
|
46
|
+
|transformer|
|
47
|
+
doc.add_transformer(&transformer)
|
48
|
+
end
|
49
|
+
if File.exist? transformer_name
|
50
|
+
doc.add_transformer(text: File.open(transformer_name).read)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
nora.html.write_as_files
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/nora_mark/version.rb
CHANGED
data/spec/nora_mark_spec.rb
CHANGED
@@ -709,6 +709,17 @@ describe NoraMark::Document do
|
|
709
709
|
['p', ['code.the-class', 'this is inside code and `backquote will not be parsed`'], '. you see?']
|
710
710
|
])
|
711
711
|
end
|
712
|
+
it 'handle non-escaped inline' do
|
713
|
+
text = "the text following will not be escaped: [noescape{©}]"
|
714
|
+
noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
|
715
|
+
converted = noramark.html
|
716
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
717
|
+
expect(body.element_children[0].selector_and_children)
|
718
|
+
.to eq(
|
719
|
+
['div.pgroup',
|
720
|
+
['p', 'the text following will not be escaped: ©']
|
721
|
+
])
|
722
|
+
end
|
712
723
|
end
|
713
724
|
describe 'list' do
|
714
725
|
it 'handle ordered list ' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nora_mark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2beta14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KOJIMA Satoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kpeg
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/nora_mark/parser.kpeg
|
135
135
|
- lib/nora_mark/parser.kpeg.rb
|
136
136
|
- lib/nora_mark/parser.rb
|
137
|
+
- lib/nora_mark/rake_task.rb
|
137
138
|
- lib/nora_mark/transformer.rb
|
138
139
|
- lib/nora_mark/version.rb
|
139
140
|
- lib/tilt/nora_mark.rb
|