nora_mark 0.2beta4 → 0.2beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -4
- data/bin/nora2html +15 -0
- data/lib/nora_mark/html/context.rb +2 -1
- data/lib/nora_mark/html/generator.rb +28 -17
- data/lib/nora_mark/parser.kpeg +15 -8
- data/lib/nora_mark/parser.kpeg.rb +204 -173
- data/lib/nora_mark/version.rb +1 -1
- data/lib/nora_mark.rb +7 -1
- data/spec/nora_mark_spec.rb +20 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70b55ff7edfd0ea3832a9d7f239471c408dc640c
|
4
|
+
data.tar.gz: e3f7e05cdfb71d9681a4ce4dc3a609cde17206e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de1829be0f4054b59effdfa4f46e418865e916ba2d96125682e165b37f4eb7afc18f62b8729bbbf90f565ff58d6bf3e12ca611bf8bda89fa1ccc4f6a9ffc11d8
|
7
|
+
data.tar.gz: cb44418db3abd96505643d739501785595aa94b9eef5b596b6e185ee9ff475677fc323f768c859ae4cd3a532ace6ee243a47c61ccbe118c1064166adc97f25ae
|
data/Rakefile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
5
|
rule(/\.kpeg\.rb/ => proc {|task_name| task_name.sub(/kpeg\.rb$/, 'kpeg')}) do
|
5
6
|
|t|
|
6
7
|
system "kpeg -f #{t.prerequisites[0]}"
|
7
8
|
end
|
8
9
|
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
|
+
|
9
12
|
desc "run rspec"
|
10
|
-
task :test => ["lib/nora_mark/parser.kpeg.rb"]
|
11
|
-
|
12
|
-
end
|
13
|
+
task :test => ["lib/nora_mark/parser.kpeg.rb", :spec]
|
14
|
+
|
data/bin/nora2html
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'nora_mark'
|
2
|
+
require 'optparse'
|
3
|
+
require 'kconv'
|
4
|
+
|
5
|
+
auto_convert_encode = false
|
6
|
+
opt = OptionParser.new
|
7
|
+
opt.on('--kconv') {
|
8
|
+
auto_convert_encode = true
|
9
|
+
}
|
10
|
+
|
11
|
+
args = opt.parse(ARGV)
|
12
|
+
input = args.length > 0 ? File.open(args[0]).read : STDIN.read
|
13
|
+
input = Kconv.toutf8(input) if auto_convert_encode
|
14
|
+
|
15
|
+
puts NoraMark::Document::parse(input).render_parameter(nonpaged: true).html[0]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module NoraMark
|
2
2
|
module Html
|
3
3
|
class Context
|
4
|
-
attr_accessor :title, :head_inserters, :toc, :lang, :stylesheets, :enable_pgroup
|
4
|
+
attr_accessor :title, :head_inserters, :toc, :lang, :stylesheets, :enable_pgroup, :render_parameter
|
5
5
|
def initialize(param = {})
|
6
6
|
@head_inserters = []
|
7
7
|
@toc = []
|
@@ -12,6 +12,7 @@ module NoraMark
|
|
12
12
|
self.paragraph_style= param[:paragraph_style]
|
13
13
|
@pages = Pages.new(param[:sequence_format])
|
14
14
|
@block_delimiter_stack = []
|
15
|
+
@render_parameter = {}
|
15
16
|
head_inserter do
|
16
17
|
ret = ""
|
17
18
|
@stylesheets.each { |s|
|
@@ -25,6 +25,28 @@ module NoraMark
|
|
25
25
|
frontmatter_writer = FrontmatterWriter.new self
|
26
26
|
paragraph_writer = ParagraphWriter.new self
|
27
27
|
abstract_node_writer = AbstractNodeWriter.new self
|
28
|
+
|
29
|
+
newpage_writer = TagWriter.create('div', self,
|
30
|
+
node_preprocessor: proc do |node|
|
31
|
+
node.no_tag = true
|
32
|
+
node
|
33
|
+
end,
|
34
|
+
write_body_preprocessor: proc do |node|
|
35
|
+
title = nil
|
36
|
+
if node.parameters.size > 0 && node.parameters[0].size > 0
|
37
|
+
title = escape_html node.parameters.first
|
38
|
+
end
|
39
|
+
@context.title = title unless title.nil?
|
40
|
+
@context.end_html
|
41
|
+
:done
|
42
|
+
end
|
43
|
+
)
|
44
|
+
@hr_writer = TagWriter.create('hr', self, node_preprocessor: proc do |node|
|
45
|
+
node.body_empty = true
|
46
|
+
add_class node, 'page-break'
|
47
|
+
node
|
48
|
+
end)
|
49
|
+
|
28
50
|
@writers = {
|
29
51
|
Paragraph => paragraph_writer,
|
30
52
|
ParagraphGroup => paragraph_writer,
|
@@ -69,22 +91,7 @@ module NoraMark
|
|
69
91
|
'sect' => section_writer,
|
70
92
|
'section' => section_writer,
|
71
93
|
}),
|
72
|
-
Newpage =>
|
73
|
-
TagWriter.create('div', self,
|
74
|
-
node_preprocessor: proc do |node|
|
75
|
-
node.no_tag = true
|
76
|
-
node
|
77
|
-
end,
|
78
|
-
write_body_preprocessor: proc do |node|
|
79
|
-
title = nil
|
80
|
-
if node.parameters.size > 0 && node.parameters[0].size > 0
|
81
|
-
title = escape_html node.parameters.first
|
82
|
-
end
|
83
|
-
@context.title = title unless title.nil?
|
84
|
-
@context.end_html
|
85
|
-
:done
|
86
|
-
end
|
87
|
-
),
|
94
|
+
Newpage => newpage_writer,
|
88
95
|
Inline =>
|
89
96
|
WriterSelector.new(self,
|
90
97
|
{
|
@@ -162,9 +169,13 @@ module NoraMark
|
|
162
169
|
}
|
163
170
|
end
|
164
171
|
|
165
|
-
def convert(parsed_result)
|
172
|
+
def convert(parsed_result, render_parameter = {})
|
166
173
|
children = parsed_result.content
|
167
174
|
@context.file_basename = parsed_result.document_name
|
175
|
+
@context.render_parameter = render_parameter
|
176
|
+
if render_parameter[:nonpaged]
|
177
|
+
@writers[Newpage] = @hr_writer
|
178
|
+
end
|
168
179
|
children.each {
|
169
180
|
|node|
|
170
181
|
to_html(node)
|
data/lib/nora_mark/parser.kpeg
CHANGED
@@ -42,12 +42,22 @@ CommandName = Word:name IdNames?:idnames ClassNames?:classes { {name: name, ids
|
|
42
42
|
ParameterNormal = < /[^,)]/* > { text }
|
43
43
|
ParameterQuoted = '"' < /[^"]/* > '"' - &/[,)]/ { text }
|
44
44
|
ParameterSingleQuoted = "'" < /[^']/* > "'" - &/[,)]/ { text }
|
45
|
-
Parameter = (ParameterQuoted
|
46
|
-
|
45
|
+
Parameter = (ParameterQuoted
|
46
|
+
| ParameterSingleQuoted
|
47
|
+
| ParameterNormal ):value { value }
|
48
|
+
|
49
|
+
Parameters = Parameter:parameter ',' - Parameters:parameters { [ parameter ] + parameters }
|
50
|
+
| Parameter:parameter { [ parameter ] }
|
51
|
+
|
47
52
|
Command = CommandName:cn ('(' - Parameters:args - ')')? { args ||= []; cn.merge({ args: args }) }
|
48
53
|
|
49
54
|
# paragraph
|
50
55
|
ImplicitParagraph = - !ParagraphDelimiter Comment* DocumentLine:content Comment* EofComment? ~paragraph([],[], [], content)
|
56
|
+
|
57
|
+
# explicit paragraph
|
58
|
+
ExplicitParagraphCommand = Command:c &{ c[:name] == 'p' }
|
59
|
+
ExplicitParagraph = - ExplicitParagraphCommand:c ':' - DocumentContent?:content Le EmptyLine* ~paragraph(c[:ids], c[:classes], c[:args], content)
|
60
|
+
|
51
61
|
Paragraph = ExplicitParagraph | ImplicitParagraph
|
52
62
|
|
53
63
|
# paragraph_group
|
@@ -88,10 +98,6 @@ CommandNameForSpecialLineCommand = NewpageCommand | ExplicitParagraphCommand
|
|
88
98
|
NewpageCommand = Command:command &{ command[:name] == 'newpage' }
|
89
99
|
Newpage = - NewpageCommand:c ':' - DocumentContent?:content - Nl ~newpage(c[:ids],c[:classes],c[:args], content)
|
90
100
|
|
91
|
-
# explicit paragraph
|
92
|
-
ExplicitParagraphCommand = Command:c &{ c[:name] == 'p' }
|
93
|
-
ExplicitParagraph = - ExplicitParagraphCommand:c ':' - DocumentContent?:content Le EmptyLine* ~paragraph(c[:ids], c[:classes], c[:args], content)
|
94
|
-
|
95
101
|
|
96
102
|
# unordered list
|
97
103
|
UnorderedList = UnorderedItem+:items ~unordered_list([],[],[], items)
|
@@ -168,10 +174,11 @@ DocumentLine = DocumentContent:content Le { content }
|
|
168
174
|
|
169
175
|
#page
|
170
176
|
Page = Frontmatter?:frontmatter - (!Newpage Block)*:blocks ~page(([frontmatter] + blocks).select{ |x| !x.nil?})
|
171
|
-
|
177
|
+
Pages = Page:page Newpage:newpage Pages:pages { [ page, newpage ] + pages }
|
178
|
+
| Page:page { [ page ] }
|
172
179
|
|
173
180
|
#root
|
174
|
-
root =
|
181
|
+
root = Pages:pages - EofComment? Eof { pages }
|
175
182
|
|
176
183
|
|
177
184
|
|
@@ -921,56 +921,67 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
921
921
|
return _tmp
|
922
922
|
end
|
923
923
|
|
924
|
-
# Parameters = Parameter:parameter
|
924
|
+
# Parameters = (Parameter:parameter "," - Parameters:parameters { [ parameter ] + parameters } | Parameter:parameter { [ parameter ] })
|
925
925
|
def _Parameters
|
926
926
|
|
927
927
|
_save = self.pos
|
928
|
-
while true #
|
929
|
-
_tmp = apply(:_Parameter)
|
930
|
-
parameter = @result
|
931
|
-
unless _tmp
|
932
|
-
self.pos = _save
|
933
|
-
break
|
934
|
-
end
|
935
|
-
_ary = []
|
936
|
-
while true
|
928
|
+
while true # choice
|
937
929
|
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
end
|
945
|
-
_tmp = apply(:__hyphen_)
|
946
|
-
unless _tmp
|
947
|
-
self.pos = _save2
|
948
|
-
break
|
949
|
-
end
|
950
|
-
_tmp = apply(:_Parameter)
|
951
|
-
unless _tmp
|
952
|
-
self.pos = _save2
|
953
|
-
end
|
930
|
+
_save1 = self.pos
|
931
|
+
while true # sequence
|
932
|
+
_tmp = apply(:_Parameter)
|
933
|
+
parameter = @result
|
934
|
+
unless _tmp
|
935
|
+
self.pos = _save1
|
954
936
|
break
|
955
|
-
end
|
937
|
+
end
|
938
|
+
_tmp = match_string(",")
|
939
|
+
unless _tmp
|
940
|
+
self.pos = _save1
|
941
|
+
break
|
942
|
+
end
|
943
|
+
_tmp = apply(:__hyphen_)
|
944
|
+
unless _tmp
|
945
|
+
self.pos = _save1
|
946
|
+
break
|
947
|
+
end
|
948
|
+
_tmp = apply(:_Parameters)
|
949
|
+
parameters = @result
|
950
|
+
unless _tmp
|
951
|
+
self.pos = _save1
|
952
|
+
break
|
953
|
+
end
|
954
|
+
@result = begin; [ parameter ] + parameters ; end
|
955
|
+
_tmp = true
|
956
|
+
unless _tmp
|
957
|
+
self.pos = _save1
|
958
|
+
end
|
959
|
+
break
|
960
|
+
end # end sequence
|
956
961
|
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
962
|
+
break if _tmp
|
963
|
+
self.pos = _save
|
964
|
+
|
965
|
+
_save2 = self.pos
|
966
|
+
while true # sequence
|
967
|
+
_tmp = apply(:_Parameter)
|
968
|
+
parameter = @result
|
969
|
+
unless _tmp
|
970
|
+
self.pos = _save2
|
971
|
+
break
|
972
|
+
end
|
973
|
+
@result = begin; [ parameter ] ; end
|
974
|
+
_tmp = true
|
975
|
+
unless _tmp
|
976
|
+
self.pos = _save2
|
977
|
+
end
|
965
978
|
break
|
966
|
-
end
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
self.pos = _save
|
971
|
-
end
|
979
|
+
end # end sequence
|
980
|
+
|
981
|
+
break if _tmp
|
982
|
+
self.pos = _save
|
972
983
|
break
|
973
|
-
end # end
|
984
|
+
end # end choice
|
974
985
|
|
975
986
|
set_failed_rule :_Parameters unless _tmp
|
976
987
|
return _tmp
|
@@ -1103,6 +1114,94 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
1103
1114
|
return _tmp
|
1104
1115
|
end
|
1105
1116
|
|
1117
|
+
# ExplicitParagraphCommand = Command:c &{ c[:name] == 'p' }
|
1118
|
+
def _ExplicitParagraphCommand
|
1119
|
+
|
1120
|
+
_save = self.pos
|
1121
|
+
while true # sequence
|
1122
|
+
_tmp = apply(:_Command)
|
1123
|
+
c = @result
|
1124
|
+
unless _tmp
|
1125
|
+
self.pos = _save
|
1126
|
+
break
|
1127
|
+
end
|
1128
|
+
_save1 = self.pos
|
1129
|
+
_tmp = begin; c[:name] == 'p' ; end
|
1130
|
+
self.pos = _save1
|
1131
|
+
unless _tmp
|
1132
|
+
self.pos = _save
|
1133
|
+
end
|
1134
|
+
break
|
1135
|
+
end # end sequence
|
1136
|
+
|
1137
|
+
set_failed_rule :_ExplicitParagraphCommand unless _tmp
|
1138
|
+
return _tmp
|
1139
|
+
end
|
1140
|
+
|
1141
|
+
# ExplicitParagraph = - ExplicitParagraphCommand:c ":" - DocumentContent?:content Le EmptyLine* {paragraph(c[:ids], c[:classes], c[:args], content)}
|
1142
|
+
def _ExplicitParagraph
|
1143
|
+
|
1144
|
+
_save = self.pos
|
1145
|
+
while true # sequence
|
1146
|
+
_tmp = apply(:__hyphen_)
|
1147
|
+
unless _tmp
|
1148
|
+
self.pos = _save
|
1149
|
+
break
|
1150
|
+
end
|
1151
|
+
_tmp = apply(:_ExplicitParagraphCommand)
|
1152
|
+
c = @result
|
1153
|
+
unless _tmp
|
1154
|
+
self.pos = _save
|
1155
|
+
break
|
1156
|
+
end
|
1157
|
+
_tmp = match_string(":")
|
1158
|
+
unless _tmp
|
1159
|
+
self.pos = _save
|
1160
|
+
break
|
1161
|
+
end
|
1162
|
+
_tmp = apply(:__hyphen_)
|
1163
|
+
unless _tmp
|
1164
|
+
self.pos = _save
|
1165
|
+
break
|
1166
|
+
end
|
1167
|
+
_save1 = self.pos
|
1168
|
+
_tmp = apply(:_DocumentContent)
|
1169
|
+
@result = nil unless _tmp
|
1170
|
+
unless _tmp
|
1171
|
+
_tmp = true
|
1172
|
+
self.pos = _save1
|
1173
|
+
end
|
1174
|
+
content = @result
|
1175
|
+
unless _tmp
|
1176
|
+
self.pos = _save
|
1177
|
+
break
|
1178
|
+
end
|
1179
|
+
_tmp = apply(:_Le)
|
1180
|
+
unless _tmp
|
1181
|
+
self.pos = _save
|
1182
|
+
break
|
1183
|
+
end
|
1184
|
+
while true
|
1185
|
+
_tmp = apply(:_EmptyLine)
|
1186
|
+
break unless _tmp
|
1187
|
+
end
|
1188
|
+
_tmp = true
|
1189
|
+
unless _tmp
|
1190
|
+
self.pos = _save
|
1191
|
+
break
|
1192
|
+
end
|
1193
|
+
@result = begin; paragraph(c[:ids], c[:classes], c[:args], content); end
|
1194
|
+
_tmp = true
|
1195
|
+
unless _tmp
|
1196
|
+
self.pos = _save
|
1197
|
+
end
|
1198
|
+
break
|
1199
|
+
end # end sequence
|
1200
|
+
|
1201
|
+
set_failed_rule :_ExplicitParagraph unless _tmp
|
1202
|
+
return _tmp
|
1203
|
+
end
|
1204
|
+
|
1106
1205
|
# Paragraph = (ExplicitParagraph | ImplicitParagraph)
|
1107
1206
|
def _Paragraph
|
1108
1207
|
|
@@ -2042,94 +2141,6 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
2042
2141
|
return _tmp
|
2043
2142
|
end
|
2044
2143
|
|
2045
|
-
# ExplicitParagraphCommand = Command:c &{ c[:name] == 'p' }
|
2046
|
-
def _ExplicitParagraphCommand
|
2047
|
-
|
2048
|
-
_save = self.pos
|
2049
|
-
while true # sequence
|
2050
|
-
_tmp = apply(:_Command)
|
2051
|
-
c = @result
|
2052
|
-
unless _tmp
|
2053
|
-
self.pos = _save
|
2054
|
-
break
|
2055
|
-
end
|
2056
|
-
_save1 = self.pos
|
2057
|
-
_tmp = begin; c[:name] == 'p' ; end
|
2058
|
-
self.pos = _save1
|
2059
|
-
unless _tmp
|
2060
|
-
self.pos = _save
|
2061
|
-
end
|
2062
|
-
break
|
2063
|
-
end # end sequence
|
2064
|
-
|
2065
|
-
set_failed_rule :_ExplicitParagraphCommand unless _tmp
|
2066
|
-
return _tmp
|
2067
|
-
end
|
2068
|
-
|
2069
|
-
# ExplicitParagraph = - ExplicitParagraphCommand:c ":" - DocumentContent?:content Le EmptyLine* {paragraph(c[:ids], c[:classes], c[:args], content)}
|
2070
|
-
def _ExplicitParagraph
|
2071
|
-
|
2072
|
-
_save = self.pos
|
2073
|
-
while true # sequence
|
2074
|
-
_tmp = apply(:__hyphen_)
|
2075
|
-
unless _tmp
|
2076
|
-
self.pos = _save
|
2077
|
-
break
|
2078
|
-
end
|
2079
|
-
_tmp = apply(:_ExplicitParagraphCommand)
|
2080
|
-
c = @result
|
2081
|
-
unless _tmp
|
2082
|
-
self.pos = _save
|
2083
|
-
break
|
2084
|
-
end
|
2085
|
-
_tmp = match_string(":")
|
2086
|
-
unless _tmp
|
2087
|
-
self.pos = _save
|
2088
|
-
break
|
2089
|
-
end
|
2090
|
-
_tmp = apply(:__hyphen_)
|
2091
|
-
unless _tmp
|
2092
|
-
self.pos = _save
|
2093
|
-
break
|
2094
|
-
end
|
2095
|
-
_save1 = self.pos
|
2096
|
-
_tmp = apply(:_DocumentContent)
|
2097
|
-
@result = nil unless _tmp
|
2098
|
-
unless _tmp
|
2099
|
-
_tmp = true
|
2100
|
-
self.pos = _save1
|
2101
|
-
end
|
2102
|
-
content = @result
|
2103
|
-
unless _tmp
|
2104
|
-
self.pos = _save
|
2105
|
-
break
|
2106
|
-
end
|
2107
|
-
_tmp = apply(:_Le)
|
2108
|
-
unless _tmp
|
2109
|
-
self.pos = _save
|
2110
|
-
break
|
2111
|
-
end
|
2112
|
-
while true
|
2113
|
-
_tmp = apply(:_EmptyLine)
|
2114
|
-
break unless _tmp
|
2115
|
-
end
|
2116
|
-
_tmp = true
|
2117
|
-
unless _tmp
|
2118
|
-
self.pos = _save
|
2119
|
-
break
|
2120
|
-
end
|
2121
|
-
@result = begin; paragraph(c[:ids], c[:classes], c[:args], content); end
|
2122
|
-
_tmp = true
|
2123
|
-
unless _tmp
|
2124
|
-
self.pos = _save
|
2125
|
-
end
|
2126
|
-
break
|
2127
|
-
end # end sequence
|
2128
|
-
|
2129
|
-
set_failed_rule :_ExplicitParagraph unless _tmp
|
2130
|
-
return _tmp
|
2131
|
-
end
|
2132
|
-
|
2133
2144
|
# UnorderedList = UnorderedItem+:items {unordered_list([],[],[], items)}
|
2134
2145
|
def _UnorderedList
|
2135
2146
|
|
@@ -3549,54 +3560,74 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
3549
3560
|
return _tmp
|
3550
3561
|
end
|
3551
3562
|
|
3552
|
-
#
|
3553
|
-
def
|
3563
|
+
# Pages = (Page:page Newpage:newpage Pages:pages { [ page, newpage ] + pages } | Page:page { [ page ] })
|
3564
|
+
def _Pages
|
3554
3565
|
|
3555
3566
|
_save = self.pos
|
3556
|
-
while true #
|
3557
|
-
|
3558
|
-
|
3559
|
-
|
3560
|
-
|
3567
|
+
while true # choice
|
3568
|
+
|
3569
|
+
_save1 = self.pos
|
3570
|
+
while true # sequence
|
3571
|
+
_tmp = apply(:_Page)
|
3572
|
+
page = @result
|
3573
|
+
unless _tmp
|
3574
|
+
self.pos = _save1
|
3575
|
+
break
|
3576
|
+
end
|
3577
|
+
_tmp = apply(:_Newpage)
|
3578
|
+
newpage = @result
|
3579
|
+
unless _tmp
|
3580
|
+
self.pos = _save1
|
3581
|
+
break
|
3582
|
+
end
|
3583
|
+
_tmp = apply(:_Pages)
|
3584
|
+
pages = @result
|
3585
|
+
unless _tmp
|
3586
|
+
self.pos = _save1
|
3587
|
+
break
|
3588
|
+
end
|
3589
|
+
@result = begin; [ page, newpage ] + pages ; end
|
3590
|
+
_tmp = true
|
3591
|
+
unless _tmp
|
3592
|
+
self.pos = _save1
|
3593
|
+
end
|
3561
3594
|
break
|
3562
|
-
end
|
3563
|
-
|
3564
|
-
|
3565
|
-
|
3566
|
-
|
3595
|
+
end # end sequence
|
3596
|
+
|
3597
|
+
break if _tmp
|
3598
|
+
self.pos = _save
|
3599
|
+
|
3600
|
+
_save2 = self.pos
|
3601
|
+
while true # sequence
|
3602
|
+
_tmp = apply(:_Page)
|
3603
|
+
page = @result
|
3604
|
+
unless _tmp
|
3605
|
+
self.pos = _save2
|
3606
|
+
break
|
3607
|
+
end
|
3608
|
+
@result = begin; [ page ] ; end
|
3609
|
+
_tmp = true
|
3610
|
+
unless _tmp
|
3611
|
+
self.pos = _save2
|
3612
|
+
end
|
3567
3613
|
break
|
3568
|
-
end
|
3569
|
-
|
3570
|
-
|
3571
|
-
|
3572
|
-
self.pos = _save
|
3573
|
-
end
|
3614
|
+
end # end sequence
|
3615
|
+
|
3616
|
+
break if _tmp
|
3617
|
+
self.pos = _save
|
3574
3618
|
break
|
3575
|
-
end # end
|
3619
|
+
end # end choice
|
3576
3620
|
|
3577
|
-
set_failed_rule :
|
3621
|
+
set_failed_rule :_Pages unless _tmp
|
3578
3622
|
return _tmp
|
3579
3623
|
end
|
3580
3624
|
|
3581
|
-
# root =
|
3625
|
+
# root = Pages:pages - EofComment? Eof { pages }
|
3582
3626
|
def _root
|
3583
3627
|
|
3584
3628
|
_save = self.pos
|
3585
3629
|
while true # sequence
|
3586
|
-
_tmp = apply(:
|
3587
|
-
page = @result
|
3588
|
-
unless _tmp
|
3589
|
-
self.pos = _save
|
3590
|
-
break
|
3591
|
-
end
|
3592
|
-
_ary = []
|
3593
|
-
while true
|
3594
|
-
_tmp = apply(:_NewpagedPage)
|
3595
|
-
_ary << @result if _tmp
|
3596
|
-
break unless _tmp
|
3597
|
-
end
|
3598
|
-
_tmp = true
|
3599
|
-
@result = _ary
|
3630
|
+
_tmp = apply(:_Pages)
|
3600
3631
|
pages = @result
|
3601
3632
|
unless _tmp
|
3602
3633
|
self.pos = _save
|
@@ -3607,11 +3638,11 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
3607
3638
|
self.pos = _save
|
3608
3639
|
break
|
3609
3640
|
end
|
3610
|
-
|
3641
|
+
_save1 = self.pos
|
3611
3642
|
_tmp = apply(:_EofComment)
|
3612
3643
|
unless _tmp
|
3613
3644
|
_tmp = true
|
3614
|
-
self.pos =
|
3645
|
+
self.pos = _save1
|
3615
3646
|
end
|
3616
3647
|
unless _tmp
|
3617
3648
|
self.pos = _save
|
@@ -3622,7 +3653,7 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
3622
3653
|
self.pos = _save
|
3623
3654
|
break
|
3624
3655
|
end
|
3625
|
-
@result = begin;
|
3656
|
+
@result = begin; pages ; end
|
3626
3657
|
_tmp = true
|
3627
3658
|
unless _tmp
|
3628
3659
|
self.pos = _save
|
@@ -3654,9 +3685,11 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
3654
3685
|
Rules[:_ParameterQuoted] = rule_info("ParameterQuoted", "\"\\\"\" < /[^\"]/* > \"\\\"\" - &/[,)]/ { text }")
|
3655
3686
|
Rules[:_ParameterSingleQuoted] = rule_info("ParameterSingleQuoted", "\"'\" < /[^']/* > \"'\" - &/[,)]/ { text }")
|
3656
3687
|
Rules[:_Parameter] = rule_info("Parameter", "(ParameterQuoted | ParameterSingleQuoted | ParameterNormal):value { value }")
|
3657
|
-
Rules[:_Parameters] = rule_info("Parameters", "Parameter:parameter
|
3688
|
+
Rules[:_Parameters] = rule_info("Parameters", "(Parameter:parameter \",\" - Parameters:parameters { [ parameter ] + parameters } | Parameter:parameter { [ parameter ] })")
|
3658
3689
|
Rules[:_Command] = rule_info("Command", "CommandName:cn (\"(\" - Parameters:args - \")\")? { args ||= []; cn.merge({ args: args }) }")
|
3659
3690
|
Rules[:_ImplicitParagraph] = rule_info("ImplicitParagraph", "- !ParagraphDelimiter Comment* DocumentLine:content Comment* EofComment? {paragraph([],[], [], content)}")
|
3691
|
+
Rules[:_ExplicitParagraphCommand] = rule_info("ExplicitParagraphCommand", "Command:c &{ c[:name] == 'p' }")
|
3692
|
+
Rules[:_ExplicitParagraph] = rule_info("ExplicitParagraph", "- ExplicitParagraphCommand:c \":\" - DocumentContent?:content Le EmptyLine* {paragraph(c[:ids], c[:classes], c[:args], content)}")
|
3660
3693
|
Rules[:_Paragraph] = rule_info("Paragraph", "(ExplicitParagraph | ImplicitParagraph)")
|
3661
3694
|
Rules[:_ParagraphGroup] = rule_info("ParagraphGroup", "Paragraph+:p EmptyLine* {paragraph_group([],[],[],p)}")
|
3662
3695
|
Rules[:_BlockHead] = rule_info("BlockHead", "- Command:command - \"{\" - Nl EmptyLine* { command }")
|
@@ -3679,8 +3712,6 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
3679
3712
|
Rules[:_CommandNameForSpecialLineCommand] = rule_info("CommandNameForSpecialLineCommand", "(NewpageCommand | ExplicitParagraphCommand)")
|
3680
3713
|
Rules[:_NewpageCommand] = rule_info("NewpageCommand", "Command:command &{ command[:name] == 'newpage' }")
|
3681
3714
|
Rules[:_Newpage] = rule_info("Newpage", "- NewpageCommand:c \":\" - DocumentContent?:content - Nl {newpage(c[:ids],c[:classes],c[:args], content)}")
|
3682
|
-
Rules[:_ExplicitParagraphCommand] = rule_info("ExplicitParagraphCommand", "Command:c &{ c[:name] == 'p' }")
|
3683
|
-
Rules[:_ExplicitParagraph] = rule_info("ExplicitParagraph", "- ExplicitParagraphCommand:c \":\" - DocumentContent?:content Le EmptyLine* {paragraph(c[:ids], c[:classes], c[:args], content)}")
|
3684
3715
|
Rules[:_UnorderedList] = rule_info("UnorderedList", "UnorderedItem+:items {unordered_list([],[],[], items)}")
|
3685
3716
|
Rules[:_UnorderedItem] = rule_info("UnorderedItem", "\"*:\" - DocumentContent:content Le {ul_item([], [], [], content)}")
|
3686
3717
|
Rules[:_OrderedList] = rule_info("OrderedList", "OrderedItem+:items {ordered_list([],[],[], items)}")
|
@@ -3712,7 +3743,7 @@ class NoraMark::Parser < KPeg::CompiledParser
|
|
3712
3743
|
Rules[:_DocumentContent] = rule_info("DocumentContent", "(Inline | DocumentText)+:content { content }")
|
3713
3744
|
Rules[:_DocumentLine] = rule_info("DocumentLine", "DocumentContent:content Le { content }")
|
3714
3745
|
Rules[:_Page] = rule_info("Page", "Frontmatter?:frontmatter - (!Newpage Block)*:blocks {page(([frontmatter] + blocks).select{ |x| !x.nil?})}")
|
3715
|
-
Rules[:
|
3716
|
-
Rules[:_root] = rule_info("root", "
|
3746
|
+
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 }")
|
3717
3748
|
# :startdoc:
|
3718
3749
|
end
|
data/lib/nora_mark/version.rb
CHANGED
data/lib/nora_mark.rb
CHANGED
@@ -33,10 +33,15 @@ module NoraMark
|
|
33
33
|
|
34
34
|
def html
|
35
35
|
if @html.nil?
|
36
|
-
@html = @html_generator.convert(self)
|
36
|
+
@html = @html_generator.convert(self, @render_parameter)
|
37
37
|
end
|
38
38
|
@html
|
39
39
|
end
|
40
|
+
|
41
|
+
def render_parameter(param = {})
|
42
|
+
@render_parameter.merge! param
|
43
|
+
self
|
44
|
+
end
|
40
45
|
|
41
46
|
def initialize(param = {})
|
42
47
|
@preprocessors = [
|
@@ -44,6 +49,7 @@ module NoraMark
|
|
44
49
|
]
|
45
50
|
@html_generator = Html::Generator.new(param)
|
46
51
|
@document_name = param[:document_name] || "noramark_#{SecureRandom.uuid}"
|
52
|
+
@render_parameter = {}
|
47
53
|
end
|
48
54
|
|
49
55
|
|
data/spec/nora_mark_spec.rb
CHANGED
@@ -946,7 +946,23 @@ EOF
|
|
946
946
|
|
947
947
|
end
|
948
948
|
end
|
949
|
-
|
949
|
+
describe 'nonpaged mode' do
|
950
|
+
it 'should create single html' do
|
951
|
+
text = "some text\nnewpage:\nnext page"
|
952
|
+
noramark = NoraMark::Document.parse(text, lang: 'ja', title:'the document title')
|
953
|
+
converted = noramark.render_parameter(nonpaged: true).html
|
954
|
+
expect(converted.size).to eq 1
|
955
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
956
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
957
|
+
['div.pgroup',
|
958
|
+
['p', 'some text']])
|
959
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
960
|
+
['hr.page-break'])
|
961
|
+
expect(body.element_children[2].selector_and_children).to eq(
|
962
|
+
['div.pgroup',
|
963
|
+
['p', 'next page']])
|
964
|
+
end
|
965
|
+
end
|
950
966
|
describe 'create file' do
|
951
967
|
before { @basedir = File.join(File.dirname(__FILE__), 'created_files') }
|
952
968
|
after { Dir.glob(File.join(@basedir, '*.xhtml')) { |file| File.delete file } }
|
@@ -960,9 +976,9 @@ EOF
|
|
960
976
|
text = "some text\nnewpage:\nnext page"
|
961
977
|
noramark = NoraMark::Document.parse(text, lang: 'ja', title:'the document title', document_name: 'nora-test-file', sequence_format: '%03d' )
|
962
978
|
noramark.html.write_as_files(directory: @basedir)
|
963
|
-
files = Dir.glob(File.join(@basedir, '*.xhtml'))
|
964
|
-
expect(
|
965
|
-
expect(
|
979
|
+
files = Dir.glob(File.join(@basedir, '*.xhtml')).map { |file| File.basename(file) }
|
980
|
+
expect(files).to include 'nora-test-file_001.xhtml'
|
981
|
+
expect(files).to include 'nora-test-file_002.xhtml'
|
966
982
|
end
|
967
983
|
end
|
968
984
|
describe 'parse and create manual' 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.2beta5
|
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-03-
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kpeg
|
@@ -69,7 +69,8 @@ dependencies:
|
|
69
69
|
description: simple and customizable text markup language for EPUB
|
70
70
|
email:
|
71
71
|
- skoji@mac.com
|
72
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- nora2html
|
73
74
|
extensions: []
|
74
75
|
extra_rdoc_files: []
|
75
76
|
files:
|
@@ -80,6 +81,7 @@ files:
|
|
80
81
|
- LICENSE
|
81
82
|
- README.md
|
82
83
|
- Rakefile
|
84
|
+
- bin/nora2html
|
83
85
|
- example/nora-simple.css
|
84
86
|
- example/noramark-reference-ja.nora
|
85
87
|
- example/noramark-reference-ja_00001.xhtml
|