arti_mark 0.1.beta3 → 0.1.beta5

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: 2a753ec42964f583942ab77b63d3b65156c06311
4
- data.tar.gz: 399b0886774cdea1efee7c110b756016f379d6ba
3
+ metadata.gz: 8de4cdcdc26e89e9f5c20eb2347e382758f0be30
4
+ data.tar.gz: 34278b22193013b08e276be60301768083e0177b
5
5
  SHA512:
6
- metadata.gz: 9123fd9378a7dd31e676332ab8828f83b6c1fd2d39dea64109af297e7e736438fd65730119d365814b43d44a160b07bb719007c3ab85d7fa5191a1217e277212
7
- data.tar.gz: 2b5d2f0827b7d224487793542fd59f3217daf0403a55d0c6d2da02c7264c8cb2e5be13c45f7e1be70d20b2679304e962227f692a0cac8d089494731374d61729
6
+ metadata.gz: a6a59b4975fc9609e10b30fc517a9b52a22e2369fd9b30cd9dd8f8bc5b956ef44478d613772f6e05ca5d4caac0846ec7aa9db594b6fda9d1e70193a7b92ead78
7
+ data.tar.gz: 17e7938d9294ea3e9f6d9c222676088474cdb09f13fcd071dcb43224ebf46b5354af2a332befa8102df94304643c5607a9792aa07cfa199ec7e4c45b0b8a36c5
@@ -1,12 +1,12 @@
1
- # version 0.1beta1 (pre NoraText)
1
+ # version 0.2beta3 (pre NoraText)
2
2
 
3
3
  * Totally rewrite using kpeg.
4
- * degrage : toc feature removed (for the old toc feature is so poor)
5
- * degrade : removed custom BlockParser. Instead of the feature, easy and powerful customization will be introduced in NoraText 0.1)
4
+ * remove toc feature (for the old toc feature is so poor)
5
+ * removed custom BlockParser. Instead of the feature, easy and powerful customization will be introduced in NoraText 0.2
6
6
  * markup change: alternate block notation starting with 'd{---' has removed
7
7
  * markup change: inline image notation is changed form [img(alt-text){src}] to [img(src, alt)]
8
8
 
9
- * will change the name from ArtiMark to NoraText on next release 0.1rc1
9
+ * will change the name from ArtiMark to NoraText on next release 0.2rc1
10
10
 
11
11
 
12
12
 
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # ArtiMark
2
2
 
3
- ArtiMark is a simple text markup language. It is designed to create XHTML files for EPUB books. It is optimized for Japanese text for the present.
3
+ ArtiMark is a simple text markup language. It is designed to create XHTML files for EPUB books. Its default mode is for Japanese text.
4
4
 
5
- **CAUTION This is very early alpha version, so it's not stable at all.**
5
+ **CAUTION This is very early alpha version, so it's not stable at all, even the markup syntax**
6
+ In the next release, the library name will change from ArtiMark to NoraMark.
7
+ In NoraMark, the syntax will be more stable.
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,16 +24,15 @@ Or install it yourself as:
22
24
 
23
25
  require 'arti_mark'
24
26
 
25
- document = ArtiMark::Document.new()
26
- document.convert(string_or_io)
27
- put document.result[0] # outputs 1st page of converted XHTML file
27
+ document = ArtiMark::Document.parse(string_or_io)
28
+ put document.html[0] # outputs 1st page of converted XHTML file
28
29
 
29
- an example of markup text
30
+ An example of markup text (text is in english, but the paragraph style is japanese)
30
31
 
31
32
  # line begins with # is a comment.
32
33
  # you don't need to indent artimark text.
33
34
 
34
- lang: en
35
+ lang: ja
35
36
  title: test title
36
37
  stylesheets: css/normalize.css, css/main.css
37
38
 
@@ -74,6 +75,106 @@ The converted XHTML file
74
75
  </div>
75
76
  </div>
76
77
  </article>
78
+ </body>
79
+ </html>
80
+
81
+ Another example of markup text in non-japanese (paragraph style is default)
82
+
83
+ # line begins with # is a comment.
84
+ # you don't need to indent artimark text.
85
+
86
+ lang: en
87
+ title: test title
88
+ stylesheets: css/normalize.css, css/main.css
89
+
90
+ art {
91
+ h1: header 1
92
+ article comes here.
93
+ linebreak will produce br.
94
+
95
+ blank line will procude paragraph.
96
+
97
+ d.column {
98
+ This block will produce div.column.
99
+ Inline commands like [link(http://github.com/skoji/arti_mark/){this}] and [s.strong{this}] is available.
100
+ }
101
+ }
102
+
103
+ The converted XHTML file
104
+
105
+ <?xml version="1.0" encoding="UTF-8"?>
106
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
107
+ <head>
108
+ <title> test title</title>
109
+ <link rel="stylesheet" type="text/css" href="css/normalize.css" />
110
+ <link rel="stylesheet" type="text/css" href="css/main.css" />
111
+ </head>
112
+ <body>
113
+ <article>
114
+ <h1>header 1</h1>
115
+ <p>article comes here.<br />linebreak will produce paragraph.</p>
116
+ <p>blank line will produce paragraph</p>
117
+ <div class='column'>
118
+ <p>This block will produce div.column.<br />Inline commands like <a href='http://github.com/skoji/arti_mark/'>this</a> and <span class='strong'>this</span> is available.</p>
119
+ </div>
120
+ </article>
121
+ </body>
122
+ </html>
123
+
124
+
125
+ Another example of markup text
126
+
127
+ # Markdown-ish heading will creates section
128
+
129
+ lang: ja
130
+ title: test title
131
+ stylesheets: css/normalize.css, css/main.css
132
+
133
+ =: this is the first heading
134
+
135
+ This line is in a section.
136
+ This line is in a section.
137
+
138
+ ==: this is the second heading
139
+
140
+ This section is nested.
141
+
142
+ =: this is the third heading
143
+
144
+ will terminate lower level section
145
+
146
+ The converted XHTML file
147
+
148
+ <?xml version="1.0" encoding="UTF-8"?>
149
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
150
+ <head>
151
+ <title>test title</title>
152
+ <link rel="stylesheet" type="text/css" href="css/normalize.css" />
153
+ <link rel="stylesheet" type="text/css" href="css/main.css" />
154
+ </head>
155
+ <body>
156
+ <section><h1>this is the first heading</h1>
157
+ <div class='pgroup'><p>This line is in a section.</p>
158
+ <p>This line is in a section.</p>
159
+ </div>
160
+ <section><h2>this is the second heading</h2>
161
+ <div class='pgroup'><p>This section is nested.</p>
162
+ </div>
163
+ </section>
164
+ </section>
165
+ <section><h1>this is the third heading</h1>
166
+ <div class='pgroup'><p>will terminate lower level section</p>
167
+ </div>
168
+ </section>
169
+ </body>
170
+ </html>
171
+
172
+
173
+
174
+
175
+
176
+
177
+
77
178
 
78
179
  In a near future version, you will be able to add custom commands.
79
180
 
@@ -1,51 +1,46 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require "arti_mark/version"
3
- require "arti_mark/command_lexer"
4
- require "arti_mark/base_parser"
5
- require 'arti_mark/common_block_parser'
6
- require "arti_mark/paragraph_parser"
7
- require "arti_mark/div_parser"
8
- require "arti_mark/article_parser"
9
- require "arti_mark/section_parser"
10
- require "arti_mark/head_parser"
11
- require "arti_mark/block_image_parser"
12
- require "arti_mark/list_parser"
13
- require "arti_mark/ordered_list_parser"
14
- require "arti_mark/unordered_list_parser"
15
- require "arti_mark/definition_list_parser"
16
- require "arti_mark/universal_block_parser"
17
- require 'arti_mark/syntax'
18
-
19
2
  require 'arti_mark/html/generator'
20
3
  require 'arti_mark/parser'
21
4
 
22
5
  module ArtiMark
23
6
  class Document
24
- def initialize(param = {})
25
- @preprocessors = [
26
- Proc.new { |text| text.gsub(/\r?\n(\r?\n)+/, "\n\n") },
27
- Proc.new { |text| text.strip.gsub(/ /, ' ') } # convert Japanese full-width spece to normal space
28
- ]
29
- @generator = Html::Generator.new(param)
30
- end
7
+ private_class_method :new
8
+
9
+ def self.parse(string_or_io, param = {})
10
+ instance = new param
11
+ src = string_or_io.respond_to?(:read) ? string_or_io.read : string_or_io
12
+ yield instance if block_given?
13
+ instance.instance_eval do
14
+ @preprocessors.each do
15
+ |pr|
16
+ src = pr.call(src)
17
+ end
18
+ @parser = Parser.new(src)
19
+ if (!@parser.parse)
20
+ raise @parser.raise_error
21
+ end
22
+ end
23
+ instance
24
+ end
31
25
 
32
26
  def preprocessor(&block)
33
27
  @preprocessors << block
34
28
  end
35
29
 
36
- def convert(text)
37
- @preprocessors.each {
38
- |pr|
39
- text = pr.call(text)
40
- }
41
- @parser = Parser.new(text)
42
- if (!@parser.parse)
43
- puts @parser.show_error
44
- exit -1
30
+ def html
31
+ if @html.nil?
32
+ @html = @html_generator.convert(@parser.result)
45
33
  end
46
- @generator.convert(@parser.result)
47
-
34
+ @html
48
35
  end
36
+
37
+ def initialize(param = {})
38
+ @preprocessors = [
39
+ Proc.new { |text| text.gsub(/\r?\n(\r?\n)+/, "\n\n") },
40
+ ]
41
+ @html_generator = Html::Generator.new(param)
42
+ end
43
+
49
44
 
50
45
  end
51
46
  end
@@ -0,0 +1,14 @@
1
+ module ArtiMark
2
+ module Html
3
+ class AbstractItemWriter
4
+ def initialize(generator)
5
+ @generator = generator
6
+ end
7
+ def write(item)
8
+ item[:children].each do |child|
9
+ @generator.to_html child
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,98 +1,119 @@
1
1
  module ArtiMark
2
- module Html
3
- class Context
4
- attr_accessor :title, :head_inserters, :toc, :lang, :stylesheets, :enable_pgroup
5
- def initialize(param = {})
6
- @head_inserters = []
7
- @toc = []
8
- @lang = param[:lang] || 'en'
9
- @title = param[:title] || 'ArtiMark generated document'
10
- @stylesheets = param[:stylesheets] || []
11
- @stylesheets_alt = param[:stylesheets_alt] || []
12
- @enable_pgroup = param[:enable_pgroup] || true
13
- @pages = Result.new
14
- @block_delimiter_stack = []
15
- head_inserter do
16
- ret = ""
17
- @stylesheets.each { |s|
18
- if s.is_a? String
19
- ret << "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{s}\" />\n"
20
- elsif s.is_a? Array
21
- ret << "<link rel=\"stylesheet\" type=\"text/css\" media=\"#{s[1]}\" href=\"#{s[0]}\" />\n"
22
- else
23
- raise "Can't use #{s} as a stylesheet"
24
- end
25
- }
26
- ret
2
+ module Html
3
+ class Context
4
+ attr_accessor :title, :head_inserters, :toc, :lang, :stylesheets, :enable_pgroup
5
+ def initialize(param = {})
6
+ @head_inserters = []
7
+ @toc = []
8
+ @lang = param[:lang] || 'en'
9
+ @title = param[:title] || 'ArtiMark generated document'
10
+ @stylesheets = param[:stylesheets] || []
11
+ @stylesheets_alt = param[:stylesheets_alt] || []
12
+ @enable_pgroup = param[:enable_pgroup] || true
13
+ self.paragraph_style= param[:paragraph_style]
14
+ @pages = Pages.new(param[:filename_base], param[:sequence_format])
15
+ @block_delimiter_stack = []
16
+ head_inserter do
17
+ ret = ""
18
+ @stylesheets.each { |s|
19
+ if s.is_a? String
20
+ ret << "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{s}\" />\n"
21
+ elsif s.is_a? Array
22
+ ret << "<link rel=\"stylesheet\" type=\"text/css\" media=\"#{s[1]}\" href=\"#{s[0]}\" />\n"
23
+ else
24
+ raise "Can't use #{s} as a stylesheet"
25
+ end
26
+ }
27
+ ret
28
+ end
27
29
  end
28
- end
29
- def chop_last_space
30
- @pages.last.sub!(/[[:space:]]+$/, '')
31
- end
32
30
 
33
- def head_inserter(&block)
34
- head_inserters << block
35
- end
31
+ def created_files
32
+ @pages.created_files
33
+ end
34
+
35
+ def chop_last_space
36
+ @pages.last.sub!(/[[:space:]]+$/, '')
37
+ end
36
38
 
37
- def start_html(title = nil)
38
- @title = title if !title.nil?
39
- if @pages.size >0 && !@pages.last.frozen?
40
- end_html
39
+ def paragraph_style=(style)
40
+ return if style.nil?
41
+ raise "paragrapy_style accepts only :default or :use_paragraph_group but is #{style}" if style != :default && style != :use_paragraph_group
42
+ @paragraph_style = style
43
+ end
44
+
45
+ def paragraph_style
46
+ if @paragraph_style
47
+ @paragraph_style
48
+ elsif @lang.split('-')[0] == 'ja'
49
+ :use_paragraph_group
50
+ else
51
+ :default
52
+ end
53
+ end
54
+ def head_inserter(&block)
55
+ head_inserters << block
41
56
  end
42
- page = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
43
- page << "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"#{@lang}\" xml:lang=\"#{@lang}\">\n"
44
- page << "<head>\n"
45
- page << "<title>#{@title}</title>\n"
46
- @head_inserters.each {
47
- |f|
48
- page << f.call
49
- }
50
- page << "</head>\n"
51
- page << "<body>\n"
52
- @pages << page
53
- @toc << title
54
- end
55
57
 
56
- def end_html
57
- page = @pages.last
58
- if !page.frozen?
59
- page << "</body>\n"
60
- page << "</html>\n"
61
- page.freeze
58
+ def start_html(title = nil)
59
+ @title = title if !title.nil?
60
+ if @pages.size >0 && !@pages.last.frozen?
61
+ end_html
62
+ end
63
+ page = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
64
+ page << "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"#{@lang}\" xml:lang=\"#{@lang}\">\n"
65
+ page << "<head>\n"
66
+ page << "<title>#{@title}</title>\n"
67
+ @head_inserters.each {
68
+ |f|
69
+ page << f.call
70
+ }
71
+ page << "</head>\n"
72
+ page << "<body>\n"
73
+ @pages << page
74
+ @toc << title
62
75
  end
63
- end
64
76
 
65
- def enter_block(lexed)
66
- @block_delimiter_stack.push(lexed[:delimiter])
67
- end
77
+ def end_html
78
+ page = @pages.last
79
+ if !page.frozen?
80
+ page << "</body>\n"
81
+ page << "</html>\n"
82
+ page.freeze
83
+ end
84
+ end
68
85
 
69
- def exit_block(lexed)
70
- @block_delimiter_stack.pop
71
- nil
72
- end
86
+ def enter_block(lexed)
87
+ @block_delimiter_stack.push(lexed[:delimiter])
88
+ end
73
89
 
74
- def block_close?(line)
75
- line == (@block_delimiter_stack.last || '') + '}'
76
- end
90
+ def exit_block(lexed)
91
+ @block_delimiter_stack.pop
92
+ nil
93
+ end
77
94
 
78
- def toc=(label)
79
- @toc[-1] = label if @toc.size > 0
80
- end
95
+ def block_close?(line)
96
+ line == (@block_delimiter_stack.last || '') + '}'
97
+ end
81
98
 
82
- def <<(text)
83
- if @pages.size == 0 || @pages.last.frozen?
84
- start_html
99
+ def toc=(label)
100
+ @toc[-1] = label if @toc.size > 0
85
101
  end
86
- @pages.last << text
87
- end
88
102
 
89
- def result
90
- if !@pages.last.frozen?
91
- end_html
103
+ def <<(text)
104
+ if @pages.size == 0 || @pages.last.frozen?
105
+ start_html
106
+ end
107
+ @pages.last << text
92
108
  end
93
109
 
94
- @pages
110
+ def result
111
+ if !@pages.last.frozen?
112
+ end_html
113
+ end
114
+
115
+ @pages
116
+ end
95
117
  end
96
118
  end
97
119
  end
98
- end