schizm 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schizm/match.rb +24 -9
- data/lib/schizm/parse.rb +98 -37
- data/res/scss/style.scss +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2123141f335e7349ec095d5b078acc21f09ed75
|
4
|
+
data.tar.gz: 7751549bb232c6cd6d9d4e63e5a3fd5d3a659574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5c82e3b896e625eaf65d54dbef821c192f9bbd742beeb1f2a4d0e73e42a258caf9766ca7c96efb2d3db7dd4f13948c0e85c289a20f8f89c948fb04bd2f79d5c
|
7
|
+
data.tar.gz: a2919358945784a928cc2d48201e23013ae5ce72983a2bf4e644c055dd1d4381db3877707f84c959dae8ae4bfff209766ef82f55ca7759680d927bddc38afff4
|
data/lib/schizm/match.rb
CHANGED
@@ -33,6 +33,12 @@ module Schizm
|
|
33
33
|
# Source path, extension put in match group 1.
|
34
34
|
SOURCE_PATH = /^.*\.(c|cc|cpp|cxx|inl|tcc)$/
|
35
35
|
|
36
|
+
# Single quotes.
|
37
|
+
QUOTE1_STRING = /'((?:[^\\']*(?:\\.)*)*)'/u
|
38
|
+
|
39
|
+
# Double quotes.
|
40
|
+
QUOTE2_STRING = /"((?:[^\\"]*(?:\\.)*)*)"/u
|
41
|
+
|
36
42
|
# Space sequence.
|
37
43
|
SPACE = /\p{Space}+/u
|
38
44
|
|
@@ -100,13 +106,22 @@ module Schizm
|
|
100
106
|
CHAR_ESCAPE = /\\(.)/u
|
101
107
|
|
102
108
|
# Link definition, content put in match group 1, params put in match group 2.
|
103
|
-
LINK_DEF = /^\(
|
109
|
+
LINK_DEF = /^\[(#{DELIM_BRACKS})\]:[ ]*(.*)[ ]*\n/u
|
104
110
|
|
105
111
|
# Link reference, content put in match group 1, params put in match group 2.
|
106
|
-
|
112
|
+
LINK_REF_BRACKS = /\[(#{DELIM_BRACKS})\]\[(#{DELIM_BRACKS})\]/um
|
113
|
+
|
114
|
+
# Link reference, content put in match group 1, params put in match group 2.
|
115
|
+
LINK_REF_PARENS = /\[(#{DELIM_BRACKS})\]\((#{DELIM_PARENS})\)/um
|
116
|
+
|
117
|
+
# Image definition, entry put in match group 1, params put in match group 2.
|
118
|
+
IMAGE_DEF = /^!\[(#{DELIM_BRACKS})\]:[ ]*(.*)[ ]*\n/u
|
119
|
+
|
120
|
+
# Image reference, alt put in match group 1, params put in match group 2.
|
121
|
+
IMAGE_REF_PARENS = /!\[(#{DELIM_BRACKS})\]\((#{DELIM_PARENS})\)/u
|
107
122
|
|
108
|
-
#
|
109
|
-
|
123
|
+
# Image reference, alt put in match group 1, params put in match group 2.
|
124
|
+
IMAGE_REF_BRACKS = /!\[(#{DELIM_BRACKS})\]\[(#{DELIM_BRACKS})\]/u
|
110
125
|
|
111
126
|
# Center math, content put in match group 1.
|
112
127
|
CENTER_MATH = /[$][$]((?:[^\\$]*(?:\\.)*)*)[$][$]/um
|
@@ -162,16 +177,16 @@ module Schizm
|
|
162
177
|
ENTER_BUG = /^[ ]{0,3}[(][?][)]/u
|
163
178
|
|
164
179
|
# Enter olist element.
|
165
|
-
ENTER_OLIST = /^[ ]{0,3}
|
180
|
+
ENTER_OLIST = /^[ ]{0,3}--?[#]/u
|
166
181
|
|
167
182
|
# Enter ulist element.
|
168
|
-
ENTER_ULIST = /^[ ]{0,3}
|
183
|
+
ENTER_ULIST = /^[ ]{0,3}--?[%]/u
|
169
184
|
|
170
185
|
# Enter tlist element, content put in match group 1.
|
171
186
|
ENTER_TLIST = /^[ ]{0,3}\[([x ])\]/u
|
172
187
|
|
173
188
|
# Enter dlist element, content put in match group 1.
|
174
|
-
ENTER_DLIST = /^[ ]{0,3}
|
189
|
+
ENTER_DLIST = /^[ ]{0,3}(.*?)::/u
|
175
190
|
|
176
191
|
# Enter code block.
|
177
192
|
ENTER_CODE = /^[ ]{4,}(?=\p{Graph})/u
|
@@ -186,11 +201,11 @@ module Schizm
|
|
186
201
|
[/\(r\)/ui, 174], # Registered.
|
187
202
|
[/\+-/u, 177], # Plus minus.
|
188
203
|
[/==/u, 8801], # Identical.
|
189
|
-
[
|
204
|
+
[/=~/u, 8773], # Congruent.
|
190
205
|
[/!=/u, 8800], # Not equal.
|
191
206
|
[/<=/u, 8804], # Less equal.
|
192
207
|
[/>=/u, 8805], # Greater equal.
|
193
|
-
[
|
208
|
+
[/~=/u, 8776], # Approximately.
|
194
209
|
[/--/u, 8211], # En dash.
|
195
210
|
[/---/u, 8212], # Em dash.
|
196
211
|
[/\.{3}/u, 8230], # Ellipsis.
|
data/lib/schizm/parse.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# Copyright (c) 2017 M. Grady Saunders
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Redistribution and use in source and binary forms, with or without
|
4
4
|
# modification, are permitted provided that the following conditions
|
5
5
|
# are met:
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# 1. Redistributions of source code must retain the above
|
8
8
|
# copyright notice, this list of conditions and the following
|
9
9
|
# disclaimer.
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# 2. Redistributions in binary form must reproduce the above
|
12
12
|
# copyright notice, this list of conditions and the following
|
13
13
|
# disclaimer in the documentation and/or other materials
|
14
14
|
# provided with the distribution.
|
15
|
-
#
|
15
|
+
#
|
16
16
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
17
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
18
18
|
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
@@ -61,6 +61,18 @@ module Parse
|
|
61
61
|
return @@links
|
62
62
|
end
|
63
63
|
|
64
|
+
@@images =
|
65
|
+
Hash.new do |hash, where|
|
66
|
+
hash[where] =
|
67
|
+
Hash.new do |hash, entry|
|
68
|
+
hash[entry] = Hash.new
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.images
|
73
|
+
return @@images
|
74
|
+
end
|
75
|
+
|
64
76
|
# Hash attribute reference.
|
65
77
|
class HashAttr
|
66
78
|
def initialize hash, attr
|
@@ -116,7 +128,7 @@ module Parse
|
|
116
128
|
max_glyph = glyph
|
117
129
|
end
|
118
130
|
end
|
119
|
-
sscan.pointer =
|
131
|
+
sscan.pointer =
|
120
132
|
sscan.pointer + max_glyph_len
|
121
133
|
return false if max_glyph_len == 0
|
122
134
|
return true
|
@@ -128,23 +140,31 @@ module Parse
|
|
128
140
|
when sscan.skip(HTML_ENTITY) then sscan[0]
|
129
141
|
when sscan.skip(HTML_ESCAPE) then sscan[0].codepoints[0]
|
130
142
|
when sscan.skip(CHAR_ESCAPE) then sscan[0].codepoints[0]
|
131
|
-
when sscan.skip(
|
132
|
-
attrs = Hash.new
|
133
|
-
attrs["target"] = "_blank"
|
143
|
+
when sscan.skip(LINK_REF_PARENS)
|
134
144
|
shown = String.new(sscan[1]).unescape("]")
|
135
145
|
param = String.new(sscan[2]).unescape(")")
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
attrs["href"] =
|
143
|
-
|
146
|
+
attrs = Hash.new
|
147
|
+
sscan2 = StringScanner.new(param)
|
148
|
+
until sscan2.eos?
|
149
|
+
case
|
150
|
+
when sscan2.skip(QUOTE1_STRING) then attrs["title"] = String.new(sscan2[1]).unescape("'")
|
151
|
+
when sscan2.skip(QUOTE2_STRING) then attrs["title"] = String.new(sscan2[1]).unescape("\"").gsub(/"/u, "'")
|
152
|
+
when sscan2.skip(/\p{Graph}+/u) then attrs["href"] = sscan2[0]
|
153
|
+
when sscan2.skip(/\p{Space}+/u) then nil
|
154
|
+
end
|
144
155
|
end
|
145
156
|
Markup.new("a")
|
157
|
+
.add_attrs("target" => "_blank")
|
146
158
|
.add_attrs(attrs)
|
147
159
|
.add_elems(line_elems(where, shown))
|
160
|
+
when sscan.skip(LINK_REF_BRACKS)
|
161
|
+
shown = String.new(sscan[1]).unescape("]")
|
162
|
+
param = String.new(sscan[2]).unescape("]")
|
163
|
+
Markup.new("a")
|
164
|
+
.add_attrs("target" => "_blank")
|
165
|
+
.add_attrs("title" => HashAttr.new(@@links[where][param], "title"))
|
166
|
+
.add_attrs("href" => HashAttr.new(@@links[where][param], "href"))
|
167
|
+
.add_elems(line_elems(where, shown))
|
148
168
|
when sscan.skip(CENTER_MATH)
|
149
169
|
Markup.new("script")
|
150
170
|
.add_attrs(CENTER_MATH_ATTRS)
|
@@ -194,11 +214,11 @@ module Parse
|
|
194
214
|
until sscan.eos?
|
195
215
|
elems.add_elems(
|
196
216
|
case
|
197
|
-
when
|
198
|
-
when
|
199
|
-
when
|
217
|
+
when sscan.skip(EMPTY_LINE) then nil
|
218
|
+
when sscan.skip(EOB_MARKER) then nil
|
219
|
+
when sscan.skip(HRULE)
|
200
220
|
Markup.new "hr"
|
201
|
-
when
|
221
|
+
when sscan.skip(HEADING_ATX)
|
202
222
|
type = String.new sscan[1]
|
203
223
|
text = String.new sscan[2]
|
204
224
|
slug = text.slugify
|
@@ -211,7 +231,7 @@ module Parse
|
|
211
231
|
when 5 then "h5"
|
212
232
|
when 6 then "h6"
|
213
233
|
end).add_elems(line_elems(where, text))
|
214
|
-
when
|
234
|
+
when sscan.skip(HEADING_SETEXT)
|
215
235
|
type = String.new sscan[2]
|
216
236
|
text = String.new sscan[1]
|
217
237
|
slug = text.slugify
|
@@ -222,30 +242,72 @@ module Parse
|
|
222
242
|
end).add_attrs("id" => slug)
|
223
243
|
.add_attrs("class" => "title")
|
224
244
|
.add_elems(line_elems(where, text))
|
225
|
-
when
|
226
|
-
entry = String.new(sscan[1]).unescape("
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
245
|
+
when sscan.skip(LINK_DEF)
|
246
|
+
entry = String.new(sscan[1]).unescape("]")
|
247
|
+
sscan2 = StringScanner.new(sscan[2])
|
248
|
+
until sscan2.eos?
|
249
|
+
case
|
250
|
+
when sscan2.skip(QUOTE1_STRING) then @@links[where][entry]["title"] = String.new(sscan2[1]).unescape("'")
|
251
|
+
when sscan2.skip(QUOTE2_STRING) then @@links[where][entry]["title"] = String.new(sscan2[1]).unescape("\"").gsub(/"/u, "'")
|
252
|
+
when sscan2.skip(/\p{Graph}+/u) then @@links[where][entry]["href"] = sscan2[0]
|
253
|
+
when sscan2.skip(/\p{Space}+/u) then nil
|
254
|
+
end
|
255
|
+
end
|
231
256
|
nil
|
232
|
-
when
|
257
|
+
when sscan.skip(IMAGE_DEF)
|
258
|
+
entry = String.new(sscan[1]).unescape("]")
|
259
|
+
sscan2 = StringScanner.new(sscan[2])
|
260
|
+
until sscan2.eos?
|
261
|
+
case
|
262
|
+
when sscan2.skip(/w=(\d+)/u) then @@images[where][entry]["width"] = sscan2[1]
|
263
|
+
when sscan2.skip(/h=(\d+)/u) then @@images[where][entry]["height"] = sscan2[1]
|
264
|
+
when sscan2.skip(/\p{Graph}+/u) then @@images[where][entry]["src"] = sscan2[0]
|
265
|
+
when sscan2.skip(/\p{Space}+/u) then nil
|
266
|
+
end
|
267
|
+
end
|
268
|
+
when sscan.skip(/^[ ]{0,3}#{IMAGE_REF_PARENS}$/u)
|
269
|
+
alt = String.new(sscan[1]).unescape("]")
|
270
|
+
param = String.new(sscan[2]).unescape(")")
|
271
|
+
sscan2 = StringScanner.new(param)
|
272
|
+
attrs = Hash.new
|
273
|
+
until sscan2.eos?
|
274
|
+
case
|
275
|
+
when sscan2.skip(/w=(\d+)/u) then attrs["width"] = sscan2[1]
|
276
|
+
when sscan2.skip(/h=(\d+)/u) then attrs["height"] = sscan2[1]
|
277
|
+
when sscan2.skip(/\p{Graph}+/u) then attrs["src"] = sscan2[0]
|
278
|
+
when sscan2.skip(/\p{Space}+/u) then nil
|
279
|
+
end
|
280
|
+
end
|
281
|
+
Markup.new("img")
|
282
|
+
.add_attrs("alt" => alt)
|
283
|
+
.add_attrs(attrs)
|
284
|
+
when sscan.skip(/^[ ]{0,3}#{IMAGE_REF_BRACKS}$/u)
|
285
|
+
alt = String.new(sscan[1]).unescape("]")
|
286
|
+
entry = String.new(sscan[2]).unescape("]")
|
287
|
+
Markup.new("img")
|
288
|
+
.add_attrs("alt" => alt)
|
289
|
+
.add_attrs("src" => HashAttr.new(@@images[where][entry], "src"))
|
290
|
+
.add_attrs("width" => HashAttr.new(@@images[where][entry], "width"))
|
291
|
+
.add_attrs("height" => HashAttr.new(@@images[where][entry], "height"))
|
292
|
+
when sscan.skip(/^#{CHUNK_LABEL}/u)
|
233
293
|
div = nil
|
234
294
|
chunk = Chunk.hash[where][String.new(sscan[1]).unescape("]")]
|
235
295
|
case
|
236
|
-
when
|
296
|
+
when sscan.skip(/[ ]*->[ ]*(.*?)\n/u)
|
237
297
|
chunk.target = sscan[1].strip
|
238
|
-
when
|
298
|
+
when sscan.skip(/[ ]*::[ ]*(.*?)\n/u)
|
239
299
|
case sscan[1].strip
|
240
300
|
when "Share" then chunk.share = true
|
241
301
|
when "Local" then chunk.share = false
|
242
302
|
else raise "Unknown attribute."
|
243
303
|
end
|
244
|
-
|
304
|
+
=begin
|
305
|
+
when sscan.skip(/[ ]*\#=[ ]*(.*?)\n/u)
|
245
306
|
sscan[1].split(' ').each_with_index do |param, index|
|
246
307
|
chunk.params[param][:index] = index
|
247
308
|
end
|
248
|
-
|
309
|
+
=end
|
310
|
+
when sscan.skip(/[ ]*\+=[ ]*(?:#{CHUNK_BLOCK})?\n/u)
|
249
311
|
label = sscan[1]
|
250
312
|
block = sscan.scan_until(END_INDENT)
|
251
313
|
block = String.new(block).erase(INDENT).trim
|
@@ -287,7 +349,7 @@ module Parse
|
|
287
349
|
])
|
288
350
|
end
|
289
351
|
div
|
290
|
-
when
|
352
|
+
when sscan.skip(ENTER_ASIDE)
|
291
353
|
text = sscan.scan_until END_INDENT
|
292
354
|
text = String.new(text).erase INDENT
|
293
355
|
Markup.new("div")
|
@@ -300,7 +362,7 @@ module Parse
|
|
300
362
|
.add_attrs("class" => "genericons-neue genericons-neue-info")),
|
301
363
|
page_elems(where, text)
|
302
364
|
])
|
303
|
-
when
|
365
|
+
when sscan.skip(ENTER_ALERT)
|
304
366
|
text = sscan.scan_until END_INDENT
|
305
367
|
text = String.new(text).erase INDENT
|
306
368
|
Markup.new("div")
|
@@ -313,7 +375,7 @@ module Parse
|
|
313
375
|
.add_attrs("class" => "genericons-neue genericons-neue-notice")),
|
314
376
|
page_elems(where, text)
|
315
377
|
])
|
316
|
-
when
|
378
|
+
when sscan.skip(ENTER_BUG)
|
317
379
|
text = sscan.scan_until END_INDENT
|
318
380
|
text = String.new(text).erase INDENT
|
319
381
|
Markup.new("div")
|
@@ -326,7 +388,7 @@ module Parse
|
|
326
388
|
.add_attrs("class" => "genericons-neue genericons-neue-bug")),
|
327
389
|
page_elems(where, text)
|
328
390
|
])
|
329
|
-
when
|
391
|
+
when sscan.skip(ENTER_QUOTE)
|
330
392
|
text = sscan.scan_until END_INDENT
|
331
393
|
text = String.new(text).erase INDENT
|
332
394
|
Markup.new("blockquote")
|
@@ -371,7 +433,6 @@ module Parse
|
|
371
433
|
while sscan.skip ENTER_DLIST
|
372
434
|
term = sscan[1]
|
373
435
|
text = sscan.scan_until END_INDENT
|
374
|
-
term = String.new(term).unescape("]")
|
375
436
|
text = String.new(text).erase INDENT
|
376
437
|
list.add_elems(Markup.new("dt").add_elems(line_elems(where, term)))
|
377
438
|
list.add_elems(Markup.new("dd").add_elems(page_elems(where, text)))
|
data/res/scss/style.scss
CHANGED