schizm 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/schizm/match.rb +42 -18
- data/lib/schizm/parse.rb +38 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e2929e0a7f68d25c528e1d9b9d0701a22d58994
|
4
|
+
data.tar.gz: 623845d2684c673a9ccb76d8f81f354ea984e0a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f7659693638560c2aef258fa915cc76c261c5627c6fc4e26792a8e19e732943e6158b3da6d71d1c85f44a7f0d838e99b240f1cad8076e447093d66841d85190
|
7
|
+
data.tar.gz: ec67ab6941bb54b8294f6a2e2d4f75ec4f489b32c3a452e3892e45c377fac6b651c085db5869e834259362637e9ad74a7641c820981a2fd0754e66606d0e8cea
|
data/lib/schizm/match.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
|
@@ -33,12 +33,6 @@ 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
|
-
|
42
36
|
# Space sequence.
|
43
37
|
SPACE = /\p{Space}+/u
|
44
38
|
|
@@ -99,7 +93,7 @@ module Schizm
|
|
99
93
|
# HTML entity.
|
100
94
|
HTML_ENTITY = /&(?:\w+|\#\d+|\#x\h+);/
|
101
95
|
|
102
|
-
# HTML special characters.
|
96
|
+
# HTML special characters.
|
103
97
|
HTML_ESCAPE = /[\p{^ASCII}&<>]/u
|
104
98
|
|
105
99
|
# Character escape, put in match group 1.
|
@@ -108,12 +102,12 @@ module Schizm
|
|
108
102
|
# Link definition, content put in match group 1, params put in match group 2.
|
109
103
|
LINK_DEF = /^\[(#{DELIM_BRACKS})\]:[ ]*(.*)[ ]*\n/u
|
110
104
|
|
111
|
-
# Link reference, content put in match group 1, params put in match group 2.
|
112
|
-
LINK_REF_BRACKS = /\[(#{DELIM_BRACKS})\]\[(#{DELIM_BRACKS})\]/um
|
113
|
-
|
114
105
|
# Link reference, content put in match group 1, params put in match group 2.
|
115
106
|
LINK_REF_PARENS = /\[(#{DELIM_BRACKS})\]\((#{DELIM_PARENS})\)/um
|
116
107
|
|
108
|
+
# Link reference, content put in match group 1, params put in match group 2.
|
109
|
+
LINK_REF_BRACKS = /\[(#{DELIM_BRACKS})\](?:\[(#{DELIM_BRACKS})\])?/um
|
110
|
+
|
117
111
|
# Image definition, entry put in match group 1, params put in match group 2.
|
118
112
|
IMAGE_DEF = /^!\[(#{DELIM_BRACKS})\]:[ ]*(.*)[ ]*\n/u
|
119
113
|
|
@@ -121,7 +115,7 @@ module Schizm
|
|
121
115
|
IMAGE_REF_PARENS = /!\[(#{DELIM_BRACKS})\]\((#{DELIM_PARENS})\)/u
|
122
116
|
|
123
117
|
# Image reference, alt put in match group 1, params put in match group 2.
|
124
|
-
IMAGE_REF_BRACKS = /!\[(#{DELIM_BRACKS})\]
|
118
|
+
IMAGE_REF_BRACKS = /!\[(#{DELIM_BRACKS})\](?:\[(#{DELIM_BRACKS})\])?/u
|
125
119
|
|
126
120
|
# Center math, content put in match group 1.
|
127
121
|
CENTER_MATH = /[$][$]((?:[^\\$]*(?:\\.)*)*)[$][$]/um
|
@@ -250,6 +244,38 @@ module Schizm
|
|
250
244
|
[/\|==>/u, 10503] # Right double arrow from bar.
|
251
245
|
]
|
252
246
|
|
247
|
+
CPP_INT_DIGITS_02 = /0[Bb][0-1]+/
|
248
|
+
|
249
|
+
CPP_INT_DIGITS_16 = /0[Xx][0-9A-Fa-f]+/
|
250
|
+
|
251
|
+
CPP_INT_DIGITS_10 = /[1-9][0-9]*|0(?![0-9])/
|
252
|
+
|
253
|
+
CPP_INT_DIGITS_08 = /0[0-7]+/
|
254
|
+
|
255
|
+
CPP_INT_DIGITS = Regexp.union [
|
256
|
+
CPP_INT_DIGITS_02,
|
257
|
+
CPP_INT_DIGITS_16,
|
258
|
+
CPP_INT_DIGITS_10,
|
259
|
+
CPP_INT_DIGITS_08
|
260
|
+
]
|
261
|
+
|
262
|
+
CPP_INT = /#{CPP_INT_DIGITS}(?:[Uu][Ll]{0,2}|[Ll]{1,2}|_[0-9A-Za-z_]+)?/
|
263
|
+
|
264
|
+
CPP_FLT_DIGITS_10 = /(?:\.[0-9]+|[0-9]+\.[0-9]*|[0-9]+(?=[Ee]))(?:[Ee][+-]?[0-9]+)?/
|
265
|
+
|
266
|
+
CPP_FLT_DIGITS_16 = /(?:0[Xx]1\.[0-9A-Fa-f]+[Pp][+-][0-9]+)/
|
267
|
+
|
268
|
+
CPP_FLT_DIGITS = Regexp.union [
|
269
|
+
CPP_FLT_DIGITS_10,
|
270
|
+
CPP_FLT_DIGITS_16
|
271
|
+
]
|
272
|
+
|
273
|
+
CPP_FLT = /#{CPP_FLT_DIGITS}(?:[Ii]?[FfLl]|_[A-Za-z0-9_]+)?/
|
274
|
+
|
275
|
+
CPP_NUMBER = /[+-]?(?:#{CPP_FLT}|#{CPP_INT})/
|
276
|
+
|
277
|
+
CPP_STRING = /(?:u8?|[ULR])?(["'])((?:[^\\\1]*(?:\\.)*)*)\1/u
|
278
|
+
|
253
279
|
# Syntax highlighting.
|
254
280
|
HIGHLIGHT_CPP = [
|
255
281
|
["hi-comment", /\/\/.*$/u],
|
@@ -260,9 +286,7 @@ module Schizm
|
|
260
286
|
["hi-type-spec", /(?:constexpr|const|volatile|static|mutable|thread_local|register|extern|inline|noexcept)\b/u],
|
261
287
|
["hi-flow", /(?:new|delete|do|while|for|if|else|try|throw|catch|switch|case|default|break|continue|goto|return)\b/u],
|
262
288
|
["hi-op", /(?:(?:and|or|xor|not)(?:_eq)?|bitand|bitor|compl|(?:(?:const|dynamic|static|reinterpret)_cast))\b/u],
|
263
|
-
["hi-value", /(?:true|false|this|nullptr|NULL)\b/u],
|
264
|
-
["hi-value", /'[^'\\]*(?:\\.[^'\\]*)*'/u], # Single quote
|
265
|
-
["hi-value", /"[^"\\]*(?:\\.[^"\\]*)*"/u], # Double quote
|
289
|
+
["hi-value", /(?:true|false|this|nullptr|NULL|#{CPP_NUMBER}|#{CPP_STRING})\b/u],
|
266
290
|
["hi-other", /(?:alignas|alignof|sizeof|decltype|template|typename|typedef|using|concept|requires|operator)\b/u],
|
267
291
|
["hi-other", /(?:namespace|class|struct|enum|public|protected|private|friend|final|virtual|override)\b/u],
|
268
292
|
["hi-ident", /[a-zA-Z]\w*/u],
|
data/lib/schizm/parse.rb
CHANGED
@@ -141,30 +141,33 @@ module Parse
|
|
141
141
|
when sscan.skip(HTML_ESCAPE) then sscan[0].codepoints[0]
|
142
142
|
when sscan.skip(CHAR_ESCAPE) then sscan[0].codepoints[0]
|
143
143
|
when sscan.skip(LINK_REF_PARENS)
|
144
|
-
|
145
|
-
|
144
|
+
text = String.new(sscan[1]).unescape("]")
|
145
|
+
info = String.new(sscan[2]).unescape(")")
|
146
|
+
sscan2 = StringScanner.new(info)
|
146
147
|
attrs = Hash.new
|
147
|
-
|
148
|
+
attrs["target"] = "_blank"
|
148
149
|
until sscan2.eos?
|
149
150
|
case
|
150
|
-
when sscan2.skip(
|
151
|
-
when sscan2.skip(
|
151
|
+
when sscan2.skip(/'((?:[^\\']*(?:\\.)*)*)'/u) then attrs["title"] = sscan2[1]
|
152
|
+
when sscan2.skip(/"((?:[^\\"]*(?:\\.)*)*)"/u) then attrs["title"] = sscan2[1]
|
152
153
|
when sscan2.skip(/\p{Graph}+/u) then attrs["href"] = sscan2[0]
|
153
154
|
when sscan2.skip(/\p{Space}+/u) then nil
|
154
155
|
end
|
155
156
|
end
|
156
157
|
Markup.new("a")
|
157
|
-
.add_attrs("target" => "_blank")
|
158
158
|
.add_attrs(attrs)
|
159
|
-
.add_elems(line_elems(where,
|
159
|
+
.add_elems(line_elems(where, text))
|
160
160
|
when sscan.skip(LINK_REF_BRACKS)
|
161
|
-
|
162
|
-
|
161
|
+
text =
|
162
|
+
name = String.new(sscan[1]).unescape("]")
|
163
|
+
name = String.new(sscan[2]).unescape("]") if sscan[2]
|
164
|
+
attrs = Hash.new
|
165
|
+
attrs["target"] = "_blank"
|
166
|
+
attrs["title"] = HashAttr.new @@links[where][name], "title"
|
167
|
+
attrs["href"] = HashAttr.new @@links[where][name], "href"
|
163
168
|
Markup.new("a")
|
164
|
-
.add_attrs(
|
165
|
-
.
|
166
|
-
.add_attrs("href" => HashAttr.new(@@links[where][param], "href"))
|
167
|
-
.add_elems(line_elems(where, shown))
|
169
|
+
.add_attrs(attrs)
|
170
|
+
.add_elems(line_elems(where, text))
|
168
171
|
when sscan.skip(CENTER_MATH)
|
169
172
|
Markup.new("script")
|
170
173
|
.add_attrs(CENTER_MATH_ATTRS)
|
@@ -221,7 +224,6 @@ module Parse
|
|
221
224
|
when sscan.skip(HEADING_ATX)
|
222
225
|
type = String.new sscan[1]
|
223
226
|
text = String.new sscan[2]
|
224
|
-
slug = text.slugify
|
225
227
|
Markup.new(
|
226
228
|
case type.size
|
227
229
|
when 1 then "h1"
|
@@ -243,33 +245,34 @@ module Parse
|
|
243
245
|
.add_attrs("class" => "title")
|
244
246
|
.add_elems(line_elems(where, text))
|
245
247
|
when sscan.skip(LINK_DEF)
|
246
|
-
|
248
|
+
name = String.new(sscan[1]).unescape("]")
|
247
249
|
sscan2 = StringScanner.new(sscan[2])
|
248
250
|
until sscan2.eos?
|
249
251
|
case
|
250
|
-
when sscan2.skip(
|
251
|
-
when sscan2.skip(
|
252
|
-
when sscan2.skip(/\p{Graph}+/u) then @@links[where][
|
252
|
+
when sscan2.skip(/'((?:[^\\']*(?:\\.)*)*)'/u) then @@links[where][name]["title"] = sscan2[1]
|
253
|
+
when sscan2.skip(/"((?:[^\\"]*(?:\\.)*)*)"/u) then @@links[where][name]["title"] = sscan2[1]
|
254
|
+
when sscan2.skip(/\p{Graph}+/u) then @@links[where][name]["href"] = sscan2[0]
|
253
255
|
when sscan2.skip(/\p{Space}+/u) then nil
|
254
256
|
end
|
255
257
|
end
|
256
258
|
nil
|
257
259
|
when sscan.skip(IMAGE_DEF)
|
258
|
-
|
260
|
+
name = String.new(sscan[1]).unescape("]")
|
259
261
|
sscan2 = StringScanner.new(sscan[2])
|
260
262
|
until sscan2.eos?
|
261
263
|
case
|
262
|
-
when sscan2.skip(/w=(\d+)/u) then @@images[where][
|
263
|
-
when sscan2.skip(/h=(\d+)/u) then @@images[where][
|
264
|
-
when sscan2.skip(/\p{Graph}+/u) then @@images[where][
|
264
|
+
when sscan2.skip(/w=(\d+)/u) then @@images[where][name]["width"] = sscan2[1]
|
265
|
+
when sscan2.skip(/h=(\d+)/u) then @@images[where][name]["height"] = sscan2[1]
|
266
|
+
when sscan2.skip(/\p{Graph}+/u) then @@images[where][name]["src"] = sscan2[0]
|
265
267
|
when sscan2.skip(/\p{Space}+/u) then nil
|
266
268
|
end
|
267
269
|
end
|
268
270
|
when sscan.skip(/^[ ]{0,3}#{IMAGE_REF_PARENS}$/u)
|
269
|
-
|
270
|
-
|
271
|
-
sscan2 = StringScanner.new(
|
271
|
+
text = String.new(sscan[1]).unescape("]")
|
272
|
+
info = String.new(sscan[2]).unescape(")")
|
273
|
+
sscan2 = StringScanner.new(info)
|
272
274
|
attrs = Hash.new
|
275
|
+
attrs["alt"] = text
|
273
276
|
until sscan2.eos?
|
274
277
|
case
|
275
278
|
when sscan2.skip(/w=(\d+)/u) then attrs["width"] = sscan2[1]
|
@@ -278,17 +281,17 @@ module Parse
|
|
278
281
|
when sscan2.skip(/\p{Space}+/u) then nil
|
279
282
|
end
|
280
283
|
end
|
281
|
-
Markup.new("img")
|
282
|
-
.add_attrs("alt" => alt)
|
283
|
-
.add_attrs(attrs)
|
284
|
+
Markup.new("img").add_attrs(attrs)
|
284
285
|
when sscan.skip(/^[ ]{0,3}#{IMAGE_REF_BRACKS}$/u)
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
286
|
+
text =
|
287
|
+
name = String.new(sscan[1]).unescape("]")
|
288
|
+
name = String.new(sscan[2]).unescape("]") if sscan[2]
|
289
|
+
attrs = Hash.new
|
290
|
+
attrs["alt"] = text
|
291
|
+
attrs["src"] = HashAttr.new @@images[where][name], "src"
|
292
|
+
attrs["width"] = HashAttr.new @@images[where][name], "width"
|
293
|
+
attrs["height"] = HashAttr.new @@images[where][name], "height"
|
294
|
+
Markup.new("img").add_attrs(attrs)
|
292
295
|
when sscan.skip(/^#{CHUNK_LABEL}/u)
|
293
296
|
div = nil
|
294
297
|
chunk = Chunk.hash[where][String.new(sscan[1]).unescape("]")]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schizm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M. Grady Saunders
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: mgradysaunders@gmail.com
|