nora_mark 0.2beta5 → 0.2beta6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70b55ff7edfd0ea3832a9d7f239471c408dc640c
4
- data.tar.gz: e3f7e05cdfb71d9681a4ce4dc3a609cde17206e8
3
+ metadata.gz: ade2dd5b4cdd69d794a353b7753554cee5d147d8
4
+ data.tar.gz: e98bc05bb7a68cb64de1d10ecd213d6a4891fd1c
5
5
  SHA512:
6
- metadata.gz: de1829be0f4054b59effdfa4f46e418865e916ba2d96125682e165b37f4eb7afc18f62b8729bbbf90f565ff58d6bf3e12ca611bf8bda89fa1ccc4f6a9ffc11d8
7
- data.tar.gz: cb44418db3abd96505643d739501785595aa94b9eef5b596b6e185ee9ff475677fc323f768c859ae4cd3a532ace6ee243a47c61ccbe118c1064166adc97f25ae
6
+ metadata.gz: 9a04a47daf848c44003e0acaa6c69da73e64c8c1aaa4f445ff36f5bd550f7e37297533c04c572bb1f6110deeb0a3492793cfc80d38f35946a65ff6a5079dc5f7
7
+ data.tar.gz: 3e009acb8be92588512b73554abd8f54b126e7ba5c57392d503ad0c609c9f1dbd151e0a07b5fad7d45d231cc9214837cbe6662d1c0133f294a8c11fb2517f363
data/README.md CHANGED
@@ -32,6 +32,17 @@ Or install it yourself as:
32
32
  document = NoraMark::Document.parse(string_or_io)
33
33
  put document.html[0] # outputs 1st page of converted XHTML file
34
34
 
35
+ From commandline:
36
+
37
+ $ nora2html < text.nora > result.xhtml
38
+
39
+ Note: nora2html replace ``newpage:`` command to ``<hr class="page-break" />`` and output all pages in one xhtml.
40
+ Main purpose of ``nora2html`` is to validate your markup.
41
+
42
+ I am planning to release nora2epub and other external tools.
43
+
44
+ ## Markup
45
+
35
46
  An example of markup text (text is in english, but the paragraph style is japanese)
36
47
 
37
48
  # line begins with # is a comment.
@@ -43,6 +43,20 @@ gem install nora_mark
43
43
 
44
44
  ==: 使い方
45
45
 
46
+ ===: コマンドラインから
47
+
48
+ code {
49
+ $ nora2html < source.nora > output.xhtml
50
+ }
51
+
52
+ 入力はutf-8のみ受け付けます。日本語のテキストであれば、kconvオプションでうまくうごくかもしれません。
53
+
54
+ code {
55
+ $ nora2html --kconv < source.nora > output.xhtml
56
+ }
57
+
58
+ [s.strong{nora2htmlは、newpageコマンドを<hr />タグに置き換え、すべてのページをひとつのxhtmlとして出力します}]
59
+ ===: コードから
46
60
  code {//ruby
47
61
  require 'nora_mark'
48
62
 
@@ -34,10 +34,20 @@
34
34
  <pre><code>gem install nora_mark</code></pre>
35
35
  </section>
36
36
  <section><h2>使い方</h2>
37
+ <section><h3>コマンドラインから</h3>
38
+ <pre><code>$ nora2html &lt; source.nora &gt; output.xhtml</code></pre>
39
+ <div class='pgroup'><p>入力はutf-8のみ受け付けます。日本語のテキストであれば、kconvオプションでうまくうごくかもしれません。</p>
40
+ </div>
41
+ <pre><code>$ nora2html --kconv &lt; source.nora &gt; output.xhtml</code></pre>
42
+ <div class='pgroup'><p><span class='strong'>nora2htmlは、newpageコマンドを&lt;hr /&gt;タグに置き換え、すべてのページをひとつのxhtmlとして出力します</span></p>
43
+ </div>
44
+ </section>
45
+ <section><h3>コードから</h3>
37
46
  <pre class='code-ruby' data-code-language='ruby'><code>require 'nora_mark'
38
47
  document = NoraMark::Document.parse(string_or_io, lang: 'ja')
39
48
  document.html.write_as_files</code></pre>
40
49
  </section>
50
+ </section>
41
51
  <section><h2>マークアップ</h2>
42
52
  <section><h3>通常のテキスト</h3>
43
53
  <div class='pgroup'><p>単なるテキストもHTMLに変換されます。</p>
@@ -11,7 +11,7 @@ module NoraMark
11
11
 
12
12
  def self.parse(string_or_io, param = {})
13
13
  instance = new param
14
- src = string_or_io.respond_to?(:read) ? string_or_io.read : string_or_io
14
+ src = (string_or_io.respond_to?(:read) ? string_or_io.read : string_or_io).encode 'utf-8'
15
15
  yield instance if block_given?
16
16
  instance.instance_eval do
17
17
  @preprocessors.each do
@@ -21,6 +21,7 @@
21
21
  %% page = ast Page(content)
22
22
 
23
23
  # literals
24
+ BOM = /\uFEFF/
24
25
  Eof = !.
25
26
  Space = ' ' | '\t'
26
27
  EofComment = Space* "#" (!Eof .)*
@@ -178,7 +179,7 @@ Pages = Page:page Newpage:newpage Pages:pages { [ page, newpage ] + pages }
178
179
  | Page:page { [ page ] }
179
180
 
180
181
  #root
181
- root = Pages:pages - EofComment? Eof { pages }
182
+ root = BOM? Pages:pages - EofComment? Eof { pages }
182
183
 
183
184
 
184
185
 
@@ -262,6 +262,13 @@ class NoraMark::Parser < KPeg::CompiledParser
262
262
  end
263
263
  include ::NoraMarkConstruction
264
264
 
265
+ # BOM = /\uFEFF/
266
+ def _BOM
267
+ _tmp = scan(/\A(?-mix:\uFEFF)/)
268
+ set_failed_rule :_BOM unless _tmp
269
+ return _tmp
270
+ end
271
+
265
272
  # Eof = !.
266
273
  def _Eof
267
274
  _save = self.pos
@@ -3622,11 +3629,21 @@ class NoraMark::Parser < KPeg::CompiledParser
3622
3629
  return _tmp
3623
3630
  end
3624
3631
 
3625
- # root = Pages:pages - EofComment? Eof { pages }
3632
+ # root = BOM? Pages:pages - EofComment? Eof { pages }
3626
3633
  def _root
3627
3634
 
3628
3635
  _save = self.pos
3629
3636
  while true # sequence
3637
+ _save1 = self.pos
3638
+ _tmp = apply(:_BOM)
3639
+ unless _tmp
3640
+ _tmp = true
3641
+ self.pos = _save1
3642
+ end
3643
+ unless _tmp
3644
+ self.pos = _save
3645
+ break
3646
+ end
3630
3647
  _tmp = apply(:_Pages)
3631
3648
  pages = @result
3632
3649
  unless _tmp
@@ -3638,11 +3655,11 @@ class NoraMark::Parser < KPeg::CompiledParser
3638
3655
  self.pos = _save
3639
3656
  break
3640
3657
  end
3641
- _save1 = self.pos
3658
+ _save2 = self.pos
3642
3659
  _tmp = apply(:_EofComment)
3643
3660
  unless _tmp
3644
3661
  _tmp = true
3645
- self.pos = _save1
3662
+ self.pos = _save2
3646
3663
  end
3647
3664
  unless _tmp
3648
3665
  self.pos = _save
@@ -3666,6 +3683,7 @@ class NoraMark::Parser < KPeg::CompiledParser
3666
3683
  end
3667
3684
 
3668
3685
  Rules = {}
3686
+ Rules[:_BOM] = rule_info("BOM", "/\\uFEFF/")
3669
3687
  Rules[:_Eof] = rule_info("Eof", "!.")
3670
3688
  Rules[:_Space] = rule_info("Space", "(\" \" | \"\\\\t\")")
3671
3689
  Rules[:_EofComment] = rule_info("EofComment", "Space* \"\#\" (!Eof .)*")
@@ -3744,6 +3762,6 @@ class NoraMark::Parser < KPeg::CompiledParser
3744
3762
  Rules[:_DocumentLine] = rule_info("DocumentLine", "DocumentContent:content Le { content }")
3745
3763
  Rules[:_Page] = rule_info("Page", "Frontmatter?:frontmatter - (!Newpage Block)*:blocks {page(([frontmatter] + blocks).select{ |x| !x.nil?})}")
3746
3764
  Rules[:_Pages] = rule_info("Pages", "(Page:page Newpage:newpage Pages:pages { [ page, newpage ] + pages } | Page:page { [ page ] })")
3747
- Rules[:_root] = rule_info("root", "Pages:pages - EofComment? Eof { pages }")
3765
+ Rules[:_root] = rule_info("root", "BOM? Pages:pages - EofComment? Eof { pages }")
3748
3766
  # :startdoc:
3749
3767
  end
@@ -1,3 +1,3 @@
1
1
  module NoraMark
2
- VERSION = "0.2beta5"
2
+ VERSION = "0.2beta6"
3
3
  end
@@ -36,6 +36,26 @@ describe NoraMark do
36
36
  ['p', 'ここから、次のパラグラフです。']]
37
37
  )
38
38
  end
39
+ it 'should convert simple paragraph with BOM' do
40
+ text = "\uFEFFここから、パラグラフがはじまります。\n「二行目です。」\n三行目です。\n\n\n ここから、次のパラグラフです。"
41
+ noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
42
+ converted = noramark.html
43
+ body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
44
+ expect(body.element_children.size).to eq 2
45
+ expect(body.element_children[0].selector_and_children).to eq(
46
+ ['div.pgroup',
47
+ ['p', 'ここから、パラグラフがはじまります。'],
48
+ ['p.noindent', '「二行目です。」'],
49
+ ['p', '三行目です。']
50
+ ]
51
+ )
52
+
53
+ expect(body.element_children[1].selector_and_children).to eq(
54
+ ['div.pgroup',
55
+ ['p', 'ここから、次のパラグラフです。']]
56
+ )
57
+ end
58
+
39
59
  it 'should convert simple paragraph in english mode' do
40
60
  text = "paragraph begins.\n2nd line.\n 3rd line.\n\n\n next paragraph."
41
61
  noramark = NoraMark::Document.parse(text, lang: 'en', title: 'the title')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nora_mark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2beta5
4
+ version: 0.2beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - KOJIMA Satoshi