schizm 0.0.1 → 0.0.2
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/chunk.rb +129 -101
- data/lib/schizm/env.rb +49 -14
- data/lib/schizm/env_colors.rb +28 -0
- data/lib/schizm/markup.rb +152 -120
- data/lib/schizm/match.rb +45 -0
- data/lib/schizm/parse.rb +350 -344
- data/lib/schizm/string.rb +179 -150
- data/res/fonts/{fira-code-bold.otf → Fira-Code-Bold.otf} +0 -0
- data/res/fonts/{fira-code-license → Fira-Code-LICENSE} +0 -0
- data/res/fonts/{fira-code-light.otf → Fira-Code-Light.otf} +0 -0
- data/res/fonts/{fira-code-medium.otf → Fira-Code-Medium.otf} +0 -0
- data/res/fonts/{fira-code-regular.otf → Fira-Code-Regular.otf} +0 -0
- data/res/fonts/{fira-code.css → Fira-Code.css} +4 -4
- data/res/fonts/{genericons-neue-license → Genericons-Neue-LICENSE} +0 -0
- data/res/fonts/{genericons-neue.css → Genericons-Neue.css} +0 -0
- data/res/fonts/{genericons-neue.eot → Genericons-Neue.eot} +0 -0
- data/res/fonts/{genericons-neue.ttf → Genericons-Neue.ttf} +0 -0
- data/res/fonts/{genericons-neue.woff2 → Genericons-Neue.woff2} +0 -0
- data/res/fonts/{social-logos-license → Social-Logos-LICENSE} +0 -0
- data/res/fonts/{social-logos.css → Social-Logos.css} +0 -0
- data/res/fonts/{social-logos.eot → Social-Logos.eot} +0 -0
- data/res/fonts/{social-logos.ttf → Social-Logos.ttf} +0 -0
- data/res/fonts/{social-logos.woff2 → Social-Logos.woff2} +0 -0
- data/res/schizm.liquid +4 -4
- data/res/scss/style.scss +1 -1
- metadata +17 -17
data/lib/schizm/markup.rb
CHANGED
@@ -1,157 +1,189 @@
|
|
1
|
+
# Copyright (c) 2017 M. Grady Saunders
|
2
|
+
#
|
3
|
+
# Redistribution and use in source and binary forms, with or without
|
4
|
+
# modification, are permitted provided that the following conditions
|
5
|
+
# are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above
|
8
|
+
# copyright notice, this list of conditions and the following
|
9
|
+
# disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above
|
12
|
+
# copyright notice, this list of conditions and the following
|
13
|
+
# disclaimer in the documentation and/or other materials
|
14
|
+
# provided with the distribution.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
18
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
20
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
24
|
+
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
1
28
|
require_relative 'string'
|
2
29
|
|
3
30
|
module Schizm
|
4
31
|
|
5
|
-
|
32
|
+
class Markup
|
6
33
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
34
|
+
def initialize tag = nil
|
35
|
+
@tag = tag
|
36
|
+
@attrs = {}
|
37
|
+
@elems = []
|
38
|
+
end
|
12
39
|
|
13
|
-
|
14
|
-
|
15
|
-
|
40
|
+
attr_reader :tag
|
41
|
+
attr_accessor :attrs
|
42
|
+
attr_accessor :elems
|
16
43
|
|
17
|
-
|
18
|
-
|
19
|
-
|
44
|
+
def [] key
|
45
|
+
return @attrs[key]
|
46
|
+
end
|
20
47
|
|
21
|
-
|
22
|
-
|
23
|
-
|
48
|
+
def []= key, value
|
49
|
+
return @attrs[key] = value
|
50
|
+
end
|
24
51
|
|
25
|
-
|
26
|
-
|
27
|
-
|
52
|
+
def get_attr name
|
53
|
+
return @attrs[key] if @attrs.has_key? name
|
54
|
+
return nil
|
55
|
+
end
|
28
56
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
57
|
+
def has_attr? name
|
58
|
+
return @attrs.has_key? name
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_attrs pairs
|
62
|
+
pairs.each do |key, value|
|
63
|
+
@attrs[key] = value
|
34
64
|
end
|
65
|
+
return self
|
66
|
+
end
|
35
67
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
when ::Integer
|
45
|
-
self << '&#' << param.to_s << ';'
|
46
|
-
when ::String
|
47
|
-
target = @elems.last
|
48
|
-
target = @elems unless target.is_a? ::String
|
49
|
-
target << param
|
50
|
-
else
|
51
|
-
@elems << param
|
68
|
+
def << param
|
69
|
+
case param
|
70
|
+
when nil
|
71
|
+
# Ignore silently.
|
72
|
+
when ::Array
|
73
|
+
for entry in param
|
74
|
+
self << entry
|
52
75
|
end
|
53
|
-
|
76
|
+
when ::Integer
|
77
|
+
self << '&#' << param.to_s << ';'
|
78
|
+
when ::String
|
79
|
+
target = @elems.last
|
80
|
+
target = @elems unless target.is_a? ::String
|
81
|
+
target << param
|
82
|
+
else
|
83
|
+
@elems << param
|
54
84
|
end
|
85
|
+
return self
|
86
|
+
end
|
55
87
|
|
56
|
-
|
57
|
-
|
58
|
-
|
88
|
+
def add_elems param
|
89
|
+
return self << param
|
90
|
+
end
|
59
91
|
|
60
|
-
|
61
|
-
|
62
|
-
|
92
|
+
def last
|
93
|
+
return @elems.last
|
94
|
+
end
|
63
95
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
96
|
+
def yield_each *tags, &block
|
97
|
+
if @tag and tags.include? @tag.to_s
|
98
|
+
yield self
|
99
|
+
end
|
100
|
+
for elem in @elems
|
101
|
+
elem.yield_each *tags, &block if elem.is_a? Markup
|
71
102
|
end
|
103
|
+
end
|
72
104
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
nil
|
105
|
+
def find_first_of *tags, &block
|
106
|
+
if @tag and tags.include? @tag.to_s
|
107
|
+
return self if not block or (block.call(self) == true)
|
108
|
+
end
|
109
|
+
for elem in @elems
|
110
|
+
temp = elem.find_first_of *tags, &block if elem.is_a? Markup
|
111
|
+
return temp if temp
|
82
112
|
end
|
113
|
+
nil
|
114
|
+
end
|
83
115
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
else
|
95
|
-
text << elem.to_plain_text
|
96
|
-
end
|
116
|
+
def to_plain_text
|
117
|
+
text = String.new
|
118
|
+
@elems.each do |elem|
|
119
|
+
case elem
|
120
|
+
when Markup
|
121
|
+
if elem.tag == "script" and
|
122
|
+
(elem["type"] == "math/tex; mode=inline" or
|
123
|
+
elem["type"] == "math/tex; mode=display")
|
124
|
+
temp = elem.elems[0].dump
|
125
|
+
text << String.new(temp[1..(temp.size-2)]).html
|
97
126
|
else
|
98
|
-
text << elem.
|
127
|
+
text << elem.to_plain_text
|
99
128
|
end
|
129
|
+
else
|
130
|
+
text << elem.to_s if elem.respond_to? :to_s
|
100
131
|
end
|
101
|
-
text
|
102
132
|
end
|
133
|
+
text
|
134
|
+
end
|
103
135
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
136
|
+
def to_s
|
137
|
+
s = String.new
|
138
|
+
unless @tag == nil
|
139
|
+
s << "<" << @tag
|
140
|
+
@attrs.each do |k, v|
|
141
|
+
if k and k.to_s != ""
|
142
|
+
s << " #{k.to_s}" if v == nil
|
143
|
+
s << " #{k.to_s}=\"#{v.to_s}\"" if v != nil and v.to_s != ""
|
113
144
|
end
|
114
|
-
s << ">"
|
115
|
-
end
|
116
|
-
@elems.each do |elem|
|
117
|
-
s << elem.to_s if elem.respond_to? :to_s
|
118
|
-
end
|
119
|
-
unless @tag == nil
|
120
|
-
s << "</" << @tag << ">"
|
121
145
|
end
|
122
|
-
s
|
146
|
+
s << ">"
|
123
147
|
end
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
return elem.to_plain_text if elem
|
130
|
-
return ""
|
148
|
+
@elems.each do |elem|
|
149
|
+
s << elem.to_s if elem.respond_to? :to_s
|
150
|
+
end
|
151
|
+
unless @tag == nil
|
152
|
+
s << "</" << @tag << ">"
|
131
153
|
end
|
154
|
+
s
|
155
|
+
end
|
132
156
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
text = elem.to_plain_text if elem
|
137
|
-
return text.truncate size if text
|
138
|
-
return ""
|
157
|
+
def guess_title
|
158
|
+
elem = find_first_of "h1" do |temp|
|
159
|
+
true if temp.has_attr? "class" and temp["class"] == "title"
|
139
160
|
end
|
161
|
+
return elem.to_plain_text if elem
|
162
|
+
return ""
|
163
|
+
end
|
140
164
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
165
|
+
def guess_description
|
166
|
+
size = 80
|
167
|
+
elem = find_first_of "p"
|
168
|
+
text = elem.to_plain_text if elem
|
169
|
+
return text.truncate size if text
|
170
|
+
return ""
|
171
|
+
end
|
172
|
+
|
173
|
+
def guess_parts
|
174
|
+
tab = " "
|
175
|
+
parts = "parts:\n"
|
176
|
+
yield_each "h2" do |elem|
|
177
|
+
if elem.get_attr "class" == "title" and
|
178
|
+
elem.get_attr "id" != nil
|
179
|
+
parts.concat "#{tab}-\n"
|
180
|
+
parts.concat "#{tab}#{tab}id: \"#{elem.get_attr "id"}\"\n"
|
181
|
+
parts.concat "#{tab}#{tab}title: \"#{elem.to_plain_text}\"\n"
|
151
182
|
end
|
152
|
-
parts
|
153
183
|
end
|
154
|
-
|
184
|
+
parts
|
155
185
|
end
|
156
186
|
|
157
|
-
end
|
187
|
+
end # class Markup
|
188
|
+
|
189
|
+
end # module Schizm
|
data/lib/schizm/match.rb
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
# Copyright (c) 2017 M. Grady Saunders
|
2
|
+
#
|
3
|
+
# Redistribution and use in source and binary forms, with or without
|
4
|
+
# modification, are permitted provided that the following conditions
|
5
|
+
# are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above
|
8
|
+
# copyright notice, this list of conditions and the following
|
9
|
+
# disclaimer.
|
10
|
+
#
|
11
|
+
# 2. Redistributions in binary form must reproduce the above
|
12
|
+
# copyright notice, this list of conditions and the following
|
13
|
+
# disclaimer in the documentation and/or other materials
|
14
|
+
# provided with the distribution.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
18
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
20
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
24
|
+
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
1
28
|
module Schizm
|
2
29
|
|
3
30
|
# Header path, extension put in match group 1.
|
@@ -208,4 +235,22 @@ module Schizm
|
|
208
235
|
[/\|==>/u, 10503] # Right double arrow from bar.
|
209
236
|
]
|
210
237
|
|
238
|
+
CPP_HIGHLIGHT = [
|
239
|
+
["hi-comment", /\/\/.*$/u],
|
240
|
+
["hi-comment", /\/\*.*?\*\//um],
|
241
|
+
["hi-preproc", /\#(?:ifn?def|endif|if|else|elif|define|pragma|include)\b.*?(?<=[^\\])(?:\n|\z)/um],
|
242
|
+
["hi-type", /(?:auto|bool|char|short|long|int|(?:un)?signed|float|double|void)\b/u],
|
243
|
+
["hi-type", /(?:size|ptrdiff|char(?:16|32)|wchar|u?int(?:_least|_fast)?(?:8|16|32|64))_t\b/u],
|
244
|
+
["hi-type-spec", /(?:constexpr|const|volatile|static|mutable|thread_local|register|extern|inline|noexcept)\b/u],
|
245
|
+
["hi-flow", /(?:new|delete|do|while|for|if|else|try|throw|catch|switch|case|default|break|continue|goto|return)\b/u],
|
246
|
+
["hi-op", /(?:(?:and|or|xor|not)(?:_eq)?|bitand|bitor|compl|(?:(?:const|dynamic|static|reinterpret)_cast))\b/u],
|
247
|
+
["hi-value", /(?:true|false|this|nullptr|NULL)\b/u],
|
248
|
+
["hi-value", /'[^'\\]*(?:\\.[^'\\]*)*'/u], # Single quote
|
249
|
+
["hi-value", /"[^"\\]*(?:\\.[^"\\]*)*"/u], # Double quote
|
250
|
+
["hi-other", /(?:alignas|alignof|sizeof|decltype|template|typename|typedef|using|concept|requires|operator)\b/u],
|
251
|
+
["hi-other", /(?:namespace|class|struct|enum|public|protected|private|friend|final|virtual|override)\b/u],
|
252
|
+
["hi-ident", /[a-zA-Z]\w*/u],
|
253
|
+
[nil, /[^\w\s]+/um]
|
254
|
+
]
|
255
|
+
|
211
256
|
end # module Schizm
|