livetext 0.9.11 → 0.9.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +2 -2
- data/lib/cmdargs.rb +93 -0
- data/lib/errors.rb +15 -0
- data/lib/formatline.rb +59 -88
- data/lib/functions.rb +6 -2
- data/lib/handler/icanhaz.rb +35 -0
- data/lib/handler.rb +1 -0
- data/lib/helpers.rb +194 -0
- data/lib/html.rb +32 -0
- data/lib/livetext/importable.rb +2 -0
- data/lib/livetext.rb +35 -152
- data/lib/parser/file.rb +8 -0
- data/lib/parser/general.rb +38 -0
- data/lib/parser/import.rb +15 -0
- data/lib/parser/mixin.rb +38 -0
- data/lib/parser/set.rb +145 -0
- data/lib/parser/string.rb +70 -0
- data/lib/parser.rb +5 -0
- data/lib/processor.rb +23 -27
- data/lib/standard.rb +164 -346
- data/lib/userapi.rb +3 -5
- data/livetext.gemspec +1 -2
- data/plugin/bookish.rb +26 -22
- data/plugin/calibre.rb +1 -1
- data/plugin/livemagick.rb +10 -10
- data/plugin/markdown.rb +13 -11
- data/plugin/pyggish.rb +94 -84
- data/plugin/tutorial.rb +10 -5
- data/test/all.rb +3 -0
- data/test/snapshots/OMIT.txt +11 -0
- data/test/{data → snapshots}/basic_formatting/expected-error.txt +0 -0
- data/test/{data → snapshots}/basic_formatting/expected-output.txt +0 -0
- data/test/{data → snapshots}/basic_formatting/source.lt3 +0 -0
- data/test/{data → snapshots}/block_comment/expected-error.txt +0 -0
- data/test/{data → snapshots}/block_comment/expected-output.txt +0 -0
- data/test/{data → snapshots}/block_comment/source.lt3 +0 -0
- data/test/snapshots/clusion.txt +70 -0
- data/test/{data → snapshots}/comments_ignored_1/expected-error.txt +0 -0
- data/test/{data → snapshots}/comments_ignored_1/expected-output.txt +0 -0
- data/test/{data → snapshots}/comments_ignored_1/source.lt3 +0 -0
- data/test/{data → snapshots}/copy_is_raw/expected-error.txt +0 -0
- data/test/{data → snapshots}/copy_is_raw/expected-output.txt +0 -0
- data/test/{data → snapshots}/copy_is_raw/rawtext.inc +0 -0
- data/test/{data → snapshots}/copy_is_raw/source.lt3 +0 -0
- data/test/{data → snapshots}/crap +0 -0
- data/test/{data → snapshots}/def_method/expected-error.txt +0 -0
- data/test/{data → snapshots}/def_method/expected-output.txt +0 -0
- data/test/{data → snapshots}/def_method/source.lt3 +0 -0
- data/test/{data → snapshots}/error_inc_line_num/expected-output.txt +0 -0
- data/test/{data → snapshots}/error_inc_line_num/file2.lt3 +0 -0
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
- data/test/{data → snapshots}/error_inc_line_num/source.lt3 +0 -0
- data/test/{data → snapshots}/error_invalid_name/expected-output.txt +0 -0
- data/test/snapshots/error_invalid_name/match-error.txt +1 -0
- data/test/{data → snapshots}/error_invalid_name/source.lt3 +0 -0
- data/test/{data → snapshots}/error_line_num/expected-output.txt +0 -0
- data/test/snapshots/error_line_num/match-error.txt +1 -0
- data/test/{data → snapshots}/error_line_num/source.lt3 +0 -0
- data/test/{data → snapshots}/error_mismatched_end/expected-output.txt +0 -2
- data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
- data/test/{data → snapshots}/error_mismatched_end/source.lt3 +0 -0
- data/test/{data → snapshots}/error_missing_end/expected-output.txt +0 -0
- data/test/snapshots/error_missing_end/match-error.txt +1 -0
- data/test/{data → snapshots}/error_missing_end/source.lt3 +0 -0
- data/test/{data/error_no_such_mixin → snapshots/error_name_not_permitted}/expected-output.txt +0 -0
- data/test/snapshots/error_name_not_permitted/match-error.txt +1 -0
- data/test/{data → snapshots}/error_name_not_permitted/source.lt3 +0 -0
- data/test/{data → snapshots}/error_no_such_copy/expected-output.txt +0 -5
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_copy/source.lt3 +0 -1
- data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -4
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_inc/source.lt3 +0 -0
- data/test/snapshots/error_no_such_mixin/expected-output.txt +5 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_mixin/source.lt3 +0 -0
- data/test/{data → snapshots}/example_alpha/expected-error.txt +0 -0
- data/test/{data → snapshots}/example_alpha/expected-output.txt +0 -0
- data/test/{data → snapshots}/example_alpha/source.lt3 +0 -0
- data/test/{data → snapshots}/example_alpha2/expected-error.txt +0 -0
- data/test/{data → snapshots}/example_alpha2/expected-output.txt +0 -0
- data/test/{data → snapshots}/example_alpha2/source.lt3 +0 -0
- data/test/{data → snapshots}/fixit +0 -0
- data/test/{data → snapshots}/functions/expected-error.txt +0 -0
- data/test/{data → snapshots}/functions/expected-output.txt +0 -0
- data/test/{data → snapshots}/functions/source.lt3 +0 -0
- data/test/{data → snapshots}/hello_world/expected-error.txt +0 -0
- data/test/{data → snapshots}/hello_world/expected-output.txt +0 -0
- data/test/{data → snapshots}/hello_world/source.lt3 +0 -0
- data/test/snapshots/icanhaz/expected-output.txt +5 -0
- data/test/snapshots/icanhaz/match-error.txt +1 -0
- data/test/snapshots/icanhaz/simple_import.rb +5 -0
- data/test/snapshots/icanhaz/source.lt3 +10 -0
- data/test/{data/more_complex_vars → snapshots/icanhaz2}/expected-error.txt +0 -0
- data/test/snapshots/icanhaz2/expected-output.txt +6 -0
- data/test/snapshots/icanhaz2/simple_canhaz.rb +5 -0
- data/test/snapshots/icanhaz2/source.lt3 +6 -0
- data/test/{data/predef_vars → snapshots/more_complex_vars}/expected-error.txt +0 -0
- data/test/{data → snapshots}/more_complex_vars/expected-output.txt +0 -0
- data/test/{data → snapshots}/more_complex_vars/source.lt3 +0 -0
- data/test/{data/raw_lines → snapshots/predef_vars}/expected-error.txt +0 -0
- data/test/snapshots/predef_vars/match-output.txt +6 -0
- data/test/{data → snapshots}/predef_vars/source.lt3 +0 -0
- data/test/{data/raw_text_block → snapshots/raw_lines}/expected-error.txt +0 -0
- data/test/{data → snapshots}/raw_lines/expected-output.txt +0 -0
- data/test/{data → snapshots}/raw_lines/source.lt3 +0 -0
- data/test/{data/simple_copy → snapshots/raw_text_block}/expected-error.txt +0 -0
- data/test/{data → snapshots}/raw_text_block/expected-output.txt +0 -0
- data/test/{data → snapshots}/raw_text_block/rawtext.inc +0 -0
- data/test/{data → snapshots}/raw_text_block/source.lt3 +0 -0
- data/test/{data/simple_include → snapshots/simple_copy}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_copy/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_copy/simplefile.inc +0 -0
- data/test/{data → snapshots}/simple_copy/source.lt3 +0 -0
- data/test/{data/simple_mixin → snapshots/simple_import}/expected-error.txt +0 -0
- data/test/snapshots/simple_import/expected-output.txt +7 -0
- data/test/snapshots/simple_import/simple_import.rb +5 -0
- data/test/snapshots/simple_import/source.lt3 +7 -0
- data/test/{data/simple_vars → snapshots/simple_include}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_include/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_include/simplefile.inc +0 -0
- data/test/{data → snapshots}/simple_include/source.lt3 +0 -1
- data/test/{data/single_raw_line → snapshots/simple_mixin}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_mixin/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_mixin/simple_mixin.rb +0 -0
- data/test/{data → snapshots}/simple_mixin/source.lt3 +0 -0
- data/test/{data/table_with_heredocs → snapshots/simple_vars}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_vars/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_vars/source.lt3 +0 -0
- data/test/{data/subset.txt → snapshots/single_raw_line/expected-error.txt} +0 -0
- data/test/{data → snapshots}/single_raw_line/expected-output.txt +0 -0
- data/test/{data → snapshots}/single_raw_line/source.lt3 +0 -0
- data/test/snapshots/subset.txt +0 -0
- data/test/snapshots/table_with_heredocs/expected-error.txt +0 -0
- data/test/{data → snapshots}/table_with_heredocs/expected-output.txt +0 -0
- data/test/{data → snapshots}/table_with_heredocs/source.lt3 +0 -0
- data/test/snapshots.rb +177 -0
- data/test/testlines.rb +2 -2
- data/test/unit/all.rb +4 -0
- data/test/unit/formatline.rb +650 -0
- data/test/unit/html.rb +38 -0
- data/test/unit/parser/all.rb +3 -0
- data/test/unit/parser/general.rb +59 -0
- data/test/unit/parser/importable.rb +19 -0
- data/test/unit/parser/mixin.rb +19 -0
- data/test/unit/parser/set.rb +164 -0
- data/test/unit/parser/string.rb +130 -0
- data/test/unit/parser.rb +6 -0
- data/test/unit/standard.rb +23 -0
- data/test/unit/stringparser.rb +140 -0
- metadata +137 -100
- data/test/data/error_inc_line_num/FOO +0 -21
- data/test/data/error_inc_line_num/expected-err-line1match.txt +0 -1
- data/test/data/error_invalid_name/expected-err-line1match.txt +0 -1
- data/test/data/error_line_num/expected-err-line1match.txt +0 -1
- data/test/data/error_mismatched_end/expected-err-line1match.txt +0 -1
- data/test/data/error_missing_end/ERR +0 -32
- data/test/data/error_missing_end/expected-err-line1match.txt +0 -1
- data/test/data/error_name_not_permitted/expected-error.txt +0 -1
- data/test/data/error_name_not_permitted/expected-output.txt +0 -4
- data/test/data/error_no_such_copy/expected-err-line1match.txt +0 -1
- data/test/data/error_no_such_inc/expected-err-line1match.txt +0 -1
- data/test/data/error_no_such_mixin/expected-err-line1match.txt +0 -1
- data/test/data/lines.txt +0 -124
- data/test/data/predef_vars/expected-output.txt +0 -6
- data/test/formatting.rb +0 -110
- data/test/test.rb +0 -140
data/lib/userapi.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# User API
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'formatline'
|
4
|
+
|
5
|
+
# UserAPI deals mostly with user-level methods.
|
4
6
|
|
5
7
|
module Livetext::UserAPI
|
6
8
|
|
@@ -93,10 +95,6 @@ module Livetext::UserAPI
|
|
93
95
|
else
|
94
96
|
lines
|
95
97
|
end
|
96
|
-
# rescue => err
|
97
|
-
# str = err.inspect + "\n"
|
98
|
-
# str << err.backtrace.map {|x| " " + x }.join("\n")
|
99
|
-
# _error!(str)
|
100
98
|
end
|
101
99
|
|
102
100
|
def _body_text(raw=false)
|
data/livetext.gemspec
CHANGED
data/plugin/bookish.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
def hardbreaks
|
1
|
+
def hardbreaks(args = nil, body = nil)
|
2
2
|
@hard = false
|
3
3
|
@hard = true unless @_args.first == "off"
|
4
4
|
end
|
@@ -7,15 +7,17 @@ def hardbreaks?
|
|
7
7
|
@hard
|
8
8
|
end
|
9
9
|
|
10
|
-
def credit
|
10
|
+
def credit(args = nil, body = nil)
|
11
11
|
# really just a place marker in source
|
12
12
|
end
|
13
13
|
|
14
|
+
# These are duplicated. Remove safely
|
15
|
+
|
14
16
|
def h1; _out "<h1>#{@_data}</h1>"; end
|
15
17
|
def h2; _out "<h2>#{@_data}</h2>"; end
|
16
18
|
def h3; _out "<h3>#{@_data}</h3>"; end
|
17
19
|
|
18
|
-
def alpha_columns
|
20
|
+
def alpha_columns(args = nil, body = nil)
|
19
21
|
n = @_args.first.to_i # FIXME: what if missing?
|
20
22
|
words = []
|
21
23
|
_body do |line|
|
@@ -30,9 +32,9 @@ def alpha_columns
|
|
30
32
|
_out "</table>"
|
31
33
|
end
|
32
34
|
|
33
|
-
def comment
|
34
|
-
|
35
|
-
end
|
35
|
+
# def comment
|
36
|
+
# _body { } # ignore body
|
37
|
+
# end
|
36
38
|
|
37
39
|
def _errout(*args)
|
38
40
|
::STDERR.puts *args
|
@@ -48,12 +50,14 @@ def _slug(str)
|
|
48
50
|
s2
|
49
51
|
end
|
50
52
|
|
51
|
-
|
53
|
+
|
54
|
+
# FIXME duplicated?
|
55
|
+
def image(args = nil, body = nil)
|
52
56
|
name = @_args[0]
|
53
57
|
_out "<img src='#{name}'></img>"
|
54
58
|
end
|
55
59
|
|
56
|
-
def figure
|
60
|
+
def figure(args = nil, body = nil)
|
57
61
|
name = @_args[0]
|
58
62
|
num = @_args[1]
|
59
63
|
title = @_args[2..-1].join(" ")
|
@@ -62,7 +66,7 @@ def figure
|
|
62
66
|
_out "<center><b>Figure #{num}</b> #{title}</center>"
|
63
67
|
end
|
64
68
|
|
65
|
-
def chapter
|
69
|
+
def chapter(args = nil, body = nil)
|
66
70
|
# _errout("chapter")
|
67
71
|
@chapter = @_args.first.to_i
|
68
72
|
@sec = @sec2 = 0
|
@@ -78,7 +82,7 @@ def chapter
|
|
78
82
|
HTML
|
79
83
|
end
|
80
84
|
|
81
|
-
def chapterN
|
85
|
+
def chapterN(args = nil, body = nil)
|
82
86
|
@chapter += 1
|
83
87
|
@sec = @sec2 = 0
|
84
88
|
title = @_data # .split(" ",2)[1]
|
@@ -94,7 +98,7 @@ def chapterN
|
|
94
98
|
HTML
|
95
99
|
end
|
96
100
|
|
97
|
-
def sec
|
101
|
+
def sec(args = nil, body = nil)
|
98
102
|
@sec += 1
|
99
103
|
@sec2 = 0
|
100
104
|
@section = "#@chapter.#@sec"
|
@@ -108,7 +112,7 @@ rescue => err
|
|
108
112
|
exit
|
109
113
|
end
|
110
114
|
|
111
|
-
def subsec
|
115
|
+
def subsec(args = nil, body = nil)
|
112
116
|
@sec2 += 1
|
113
117
|
@subsec = "#@chapter.#@sec.#@sec2"
|
114
118
|
title = @_data.dup
|
@@ -118,7 +122,7 @@ def subsec
|
|
118
122
|
_out "<h3>#@subsec #{title}</h3>\n"
|
119
123
|
end
|
120
124
|
|
121
|
-
def definition_table
|
125
|
+
def definition_table(args = nil, body = nil)
|
122
126
|
title = @_data
|
123
127
|
wide = "95"
|
124
128
|
delim = " :: "
|
@@ -140,7 +144,7 @@ def definition_table
|
|
140
144
|
_optional_blank_line
|
141
145
|
end
|
142
146
|
|
143
|
-
def table2
|
147
|
+
def table2(args = nil, body = nil)
|
144
148
|
title = @_data
|
145
149
|
wide = "90"
|
146
150
|
extra = _args[2]
|
@@ -164,7 +168,7 @@ def table2
|
|
164
168
|
_optional_blank_line
|
165
169
|
end
|
166
170
|
|
167
|
-
def simple_table
|
171
|
+
def simple_table(args = nil, body = nil)
|
168
172
|
title = @_data
|
169
173
|
delim = " :: "
|
170
174
|
_out "<table cellpadding=2>"
|
@@ -193,7 +197,7 @@ def simple_table
|
|
193
197
|
_out "</table>"
|
194
198
|
end
|
195
199
|
|
196
|
-
def table
|
200
|
+
def table(args = nil, body = nil)
|
197
201
|
@table_num ||= 0
|
198
202
|
@table_num += 1
|
199
203
|
title = @_data
|
@@ -227,7 +231,7 @@ def table
|
|
227
231
|
_out "<b>Table #@chapter.#@table_num #{title}</b></center><br>"
|
228
232
|
end
|
229
233
|
|
230
|
-
def toc!
|
234
|
+
def toc!(args = nil, body = nil)
|
231
235
|
_debug "Closing TOC"
|
232
236
|
@toc.close
|
233
237
|
rescue => err
|
@@ -236,7 +240,7 @@ rescue => err
|
|
236
240
|
_errout "Exception: #{err.inspect}"
|
237
241
|
end
|
238
242
|
|
239
|
-
def toc2
|
243
|
+
def toc2(args = nil, body = nil)
|
240
244
|
file = @_args[0]
|
241
245
|
@toc.close
|
242
246
|
::File.write(file, <<-EOS)
|
@@ -249,24 +253,24 @@ EOS
|
|
249
253
|
system("cat toc.tmp >>#{file}")
|
250
254
|
end
|
251
255
|
|
252
|
-
def missing
|
256
|
+
def missing(args = nil, body = nil)
|
253
257
|
@toc << "#{_nbsp(8)}<font color=red>TBD: #@_data</font><br>"
|
254
258
|
stuff = @_data.empty? ? "" : ": #@_data"
|
255
259
|
_out "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
|
256
260
|
end
|
257
261
|
|
258
|
-
def TBC
|
262
|
+
def TBC(args = nil, body = nil)
|
259
263
|
@toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
|
260
264
|
_out "<br><font color=red><i>To be continued...</i></font><br>"
|
261
265
|
end
|
262
266
|
|
263
|
-
def note
|
267
|
+
def note(args = nil, body = nil)
|
264
268
|
_out "<br><font color=red><i>Note: "
|
265
269
|
_out @_data
|
266
270
|
_out "</i></font><br>\n "
|
267
271
|
end
|
268
272
|
|
269
|
-
def quote
|
273
|
+
def quote(args = nil, body = nil)
|
270
274
|
_out "<blockquote>"
|
271
275
|
_body {|line| _out line }
|
272
276
|
_out "</blockquote>"
|
data/plugin/calibre.rb
CHANGED
data/plugin/livemagick.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'rmagick'
|
2
2
|
include ::Magick
|
3
3
|
|
4
|
-
def image
|
4
|
+
def image(args = nil, body = nil)
|
5
5
|
xx, yy, bg = _args
|
6
6
|
xx, yy = xx.to_i, yy.to_i
|
7
7
|
@image = Image.new(xx,yy) { self.background_color = bg }
|
8
8
|
_optional_blank_line
|
9
9
|
end
|
10
10
|
|
11
|
-
def canvas
|
11
|
+
def canvas(args = nil, body = nil)
|
12
12
|
color, width, opacity = _args
|
13
13
|
opacity, width = opacity.to_i, width.to_i
|
14
14
|
@canvas = Draw.new
|
@@ -18,7 +18,7 @@ def canvas
|
|
18
18
|
_optional_blank_line
|
19
19
|
end
|
20
20
|
|
21
|
-
def rectangle
|
21
|
+
def rectangle(args = nil, body = nil)
|
22
22
|
xy, wxh, stroke_color, stroke_width = _args
|
23
23
|
x, y = xy.split(",").map(&:to_i)
|
24
24
|
width, height = wxh.split("x").map(&:to_i)
|
@@ -29,14 +29,14 @@ def rectangle
|
|
29
29
|
@canvas.rectangle(x, y, x+width, y+height)
|
30
30
|
end
|
31
31
|
|
32
|
-
def pen
|
32
|
+
def pen(args = nil, body = nil)
|
33
33
|
@fill, @stroke = _args
|
34
34
|
@stroke = "black" if @stroke.nil? || @stroke.empty?
|
35
35
|
_debug "pen: fill=#@fill stroke=#@stroke"
|
36
36
|
_optional_blank_line
|
37
37
|
end
|
38
38
|
|
39
|
-
def font
|
39
|
+
def font(args = nil, body = nil)
|
40
40
|
size, font = _args
|
41
41
|
font = "Helvetica" if font.nil? || font.empty?
|
42
42
|
size = "32" if size.nil? || size.empty?
|
@@ -59,14 +59,14 @@ def _text(xy, wxh, str, weight, gravity)
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def text
|
62
|
+
def text(args = nil, body = nil)
|
63
63
|
xy, wxh, str = _data.split
|
64
64
|
weight, gravity = BoldWeight, CenterGravity
|
65
65
|
_text(xy, wxh, str, weight, gravity)
|
66
66
|
_optional_blank_line
|
67
67
|
end
|
68
68
|
|
69
|
-
def text!
|
69
|
+
def text!(args = nil, body = nil)
|
70
70
|
xy, wxh = _data.split
|
71
71
|
str = _body_text # .join
|
72
72
|
weight, gravity = BoldWeight, CenterGravity
|
@@ -74,17 +74,17 @@ def text!
|
|
74
74
|
_optional_blank_line
|
75
75
|
end
|
76
76
|
|
77
|
-
def draw
|
77
|
+
def draw(args = nil, body = nil)
|
78
78
|
@canvas.draw(@image)
|
79
79
|
_optional_blank_line
|
80
80
|
end
|
81
81
|
|
82
|
-
def save
|
82
|
+
def save(args = nil, body = nil)
|
83
83
|
@image.write(_args.first)
|
84
84
|
_optional_blank_line
|
85
85
|
end
|
86
86
|
|
87
|
-
def save!
|
87
|
+
def save!(args = nil, body = nil)
|
88
88
|
save
|
89
89
|
system("open #{_args.first}")
|
90
90
|
_optional_blank_line
|
data/plugin/markdown.rb
CHANGED
@@ -1,35 +1,37 @@
|
|
1
1
|
# This file is intended to be used via a Livetext .mixin
|
2
2
|
# or the equivalent.
|
3
3
|
|
4
|
+
SimpleFormats = {}
|
4
5
|
SimpleFormats[:b] = %w[* *]
|
5
6
|
SimpleFormats[:i] = %w[_ _]
|
6
7
|
SimpleFormats[:t] = %w[` `]
|
7
8
|
SimpleFormats[:s] = %w[<strike> </strike>]
|
8
9
|
|
9
|
-
def h1; _out "# #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end # atx style for now
|
10
|
-
def h2; _out "## #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
11
|
-
def h3; _out "### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
12
|
-
def h4; _out "#### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
13
|
-
def h5; _out "##### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
14
|
-
def h6; _out "###### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
15
10
|
|
16
|
-
def
|
11
|
+
def h1(args = nil, body = nil); _out "# #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end # atx style for now
|
12
|
+
def h2(args = nil, body = nil); _out "## #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
13
|
+
def h3(args = nil, body = nil); _out "### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
14
|
+
def h4(args = nil, body = nil); _out "#### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
15
|
+
def h5(args = nil, body = nil); _out "##### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
16
|
+
def h6(args = nil, body = nil); _out "###### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
17
|
+
|
18
|
+
def title(args = nil, body = nil)
|
17
19
|
h1
|
18
20
|
end
|
19
21
|
|
20
|
-
def section
|
22
|
+
def section(args = nil, body = nil)
|
21
23
|
h3
|
22
24
|
end
|
23
25
|
|
24
|
-
def bq # block quote
|
26
|
+
def bq(args = nil, body = nil) # block quote
|
25
27
|
_body {|line| _out "> #{line}" }
|
26
28
|
end
|
27
29
|
|
28
|
-
def list
|
30
|
+
def list(args = nil, body = nil)
|
29
31
|
_body {|line| _out " * #{line}" }
|
30
32
|
end
|
31
33
|
|
32
|
-
def olist # Doesn't handle paragraphs yet
|
34
|
+
def olist(args = nil, body = nil) # Doesn't handle paragraphs yet
|
33
35
|
n = 0
|
34
36
|
_body do |line|
|
35
37
|
n += 1
|
data/plugin/pyggish.rb
CHANGED
@@ -1,58 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
module PygmentFix # Remove CSS for Jutoh
|
4
|
-
Styles = {
|
5
|
-
:c => "#408080-i", # Comment
|
6
|
-
:k => "#008000-b", # Keyword
|
7
|
-
:o => "#666666", # Operator
|
8
|
-
:cm => "#408080-i", # Comment.Multiline
|
9
|
-
:cp => "#BC7A00", # Comment.Preproc
|
10
|
-
:c1 => "#408080-i", # Comment.Single
|
11
|
-
:cs => "#408080-i", # Comment.Special
|
12
|
-
:kc => "#008000-b", # Keyword.Constant
|
13
|
-
:kd => "#008000-b", # Keyword.Declaration
|
14
|
-
:kn => "#008000-b", # Keyword.Namespace
|
15
|
-
:kp => "#008000", # Keyword.Pseudo
|
16
|
-
:kr => "#008000-b", # Keyword.Reserved
|
17
|
-
:kt => "#B00040", # Keyword.Type
|
18
|
-
:m => "#666666", # Literal.Number
|
19
|
-
:s => "#BA2121", # Literal.String
|
20
|
-
:na => "#7D9029", # Name.Attribute
|
21
|
-
:nb => "#008000", # Name.Builtin
|
22
|
-
:nc => "#0000FF-b", # Name.Class
|
23
|
-
:no => "#880000", # Name.Constant
|
24
|
-
:nd => "#AA22FF", # Name.Decorator
|
25
|
-
:ni => "#999999-b", # Name.Entity
|
26
|
-
:ne => "#D2413A-b", # Name.Exception
|
27
|
-
:nf => "#0000FF", # Name.Function
|
28
|
-
:nl => "#A0A000", # Name.Label
|
29
|
-
:nn => "#0000FF-b", # Name.Namespace
|
30
|
-
:nt => "#008000-b", # Name.Tag
|
31
|
-
:nv => "#19177C", # Name.Variable
|
32
|
-
:ow => "#AA22FF-b", # Operator.Word
|
33
|
-
:w => "#bbbbbb", # Text.Whitespace
|
34
|
-
:mb => "#666666", # Literal.Number.Bin
|
35
|
-
:mf => "#666666", # Literal.Number.Float
|
36
|
-
:mh => "#666666", # Literal.Number.Hex
|
37
|
-
:mi => "#666666", # Literal.Number.Integer
|
38
|
-
:mo => "#666666", # Literal.Number.Oct
|
39
|
-
:sb => "#BA2121", # Literal.String.Backtick
|
40
|
-
:sc => "#BA2121", # Literal.String.Char
|
41
|
-
:sd => "#BA2121-i", # Literal.String.Doc
|
42
|
-
:s2 => "#BA2121", # Literal.String.Double
|
43
|
-
:se => "#BB6622-b", # Literal.String.Escape
|
44
|
-
:sh => "#BA2121", # Literal.String.Heredoc
|
45
|
-
:si => "#BB6688-b", # Literal.String.Interpol
|
46
|
-
:sx => "#008000", # Literal.String.Other
|
47
|
-
:sr => "#BB6688", # Literal.String.Regex
|
48
|
-
:s1 => "#BA2121", # Literal.String.Single
|
49
|
-
:ss => "#19177C", # Literal.String.Symbol
|
50
|
-
:bp => "#008000", # Name.Builtin.Pseudo
|
51
|
-
:vc => "#19177C", # Name.Variable.Class
|
52
|
-
:vg => "#19177C", # Name.Variable.Global
|
53
|
-
:vi => "#19177C", # Name.Variable.Instance
|
54
|
-
:il => "#666666" # Literal.Number.Integer.Long
|
55
|
-
}
|
1
|
+
require 'rouge'
|
56
2
|
|
57
3
|
def self.pyg_change(code, klass, style)
|
58
4
|
color = style[0..6]
|
@@ -82,13 +28,17 @@ module PygmentFix # Remove CSS for Jutoh
|
|
82
28
|
|
83
29
|
def self.pyg_finalize(code, lexer=:elixir)
|
84
30
|
Styles.each_pair {|klass, style| pyg_change(code, klass, style) }
|
31
|
+
File.open("debug-pf1", "w") {|f| f.puts code }
|
85
32
|
code.sub!(/<pre>/, "<pre>\n")
|
86
33
|
code.gsub!(/<span class="[np]">/, "")
|
87
34
|
code.gsub!(/<\/span>/, "")
|
88
35
|
color = _codebar_color(lexer)
|
89
|
-
code.sub!(/<td class="linenos"/, "<td width=
|
36
|
+
code.sub!(/<td class="linenos"/, "<td width=2%></td><td width=5% bgcolor=#{color}")
|
37
|
+
code.gsub!(/<td/, "<td valign=top ")
|
90
38
|
code.gsub!(/ class="[^"]*?"/, "") # Get rid of remaining Pygments CSS
|
39
|
+
File.open("debug-pf2", "w") {|f| f.puts code }
|
91
40
|
lines = code.split("\n")
|
41
|
+
# lines.each {|line| line << "\n" }
|
92
42
|
n1 = lines.index {|x| x =~ /<pre>/ }
|
93
43
|
n2 = lines.index {|x| x =~ /<\/pre>/ }
|
94
44
|
# FIXME ?
|
@@ -97,15 +47,13 @@ module PygmentFix # Remove CSS for Jutoh
|
|
97
47
|
lines[n1].sub!(/ 1$/, " 1 ")
|
98
48
|
(n1+1).upto(n2) {|n| lines[n].replace(" " + lines[n] + " ") }
|
99
49
|
code = lines.join("\n")
|
50
|
+
File.open("debug-pf3", "w") {|f| f.puts code }
|
100
51
|
code
|
101
52
|
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# Was in 'bookish':
|
105
53
|
|
106
|
-
# include PygmentFix
|
107
54
|
|
108
55
|
def _process_code(text)
|
56
|
+
File.open("debug-pc1", "w") {|f| f.puts text }
|
109
57
|
lines = text.split("\n")
|
110
58
|
lines = lines.select {|x| x !~ /##~ omit/ }
|
111
59
|
@refs = {}
|
@@ -117,28 +65,32 @@ def _process_code(text)
|
|
117
65
|
end
|
118
66
|
end
|
119
67
|
lines.map! {|line| " " + line }
|
120
|
-
|
68
|
+
text2 = lines.join("\n")
|
69
|
+
File.open("debug-pc2", "w") {|f| f.puts text2 }
|
70
|
+
text.replace(text2)
|
121
71
|
end
|
122
72
|
|
123
73
|
def _colorize(code, lexer=:elixir)
|
124
74
|
text = ::Pygments.highlight(code, lexer: lexer, options: {linenos: "table"})
|
125
75
|
_debug "--- in _colorize: text = #{text.inspect}"
|
126
|
-
PygmentFix.pyg_finalize(text, lexer)
|
127
|
-
|
76
|
+
text2 = PygmentFix.pyg_finalize(text, lexer)
|
77
|
+
result = "<!-- colorized code -->\n" + text2
|
78
|
+
result
|
128
79
|
end
|
129
80
|
|
130
81
|
def _colorize!(code, lexer=:elixir)
|
131
82
|
text = ::Pygments.highlight(code, lexer: lexer, options: {})
|
132
83
|
_debug "--- in _colorize!: text = #{text.inspect}"
|
133
|
-
PygmentFix.pyg_finalize(text, lexer)
|
134
|
-
|
84
|
+
text2 = PygmentFix.pyg_finalize(text, lexer)
|
85
|
+
result = "<!-- colorized code -->\n" + text2
|
86
|
+
result
|
135
87
|
end
|
136
88
|
|
137
|
-
def
|
89
|
+
def OLD_ruby
|
138
90
|
file = @_args.first
|
139
91
|
if file.nil?
|
140
92
|
code = "# Ruby code\n"
|
141
|
-
_body {|line| code << line }
|
93
|
+
_body {|line| code << line + "\n" }
|
142
94
|
else
|
143
95
|
code = "# Ruby code\n\n" + ::File.read(file)
|
144
96
|
end
|
@@ -148,11 +100,11 @@ def ruby
|
|
148
100
|
_out "\n#{html}\n "
|
149
101
|
end
|
150
102
|
|
151
|
-
def
|
103
|
+
def OLD_elixir
|
152
104
|
file = @_args.first
|
153
105
|
if file.nil?
|
154
106
|
code = ""
|
155
|
-
_body {|line| code << line }
|
107
|
+
_body {|line| code << line + "\n" }
|
156
108
|
else
|
157
109
|
code = ::File.read(file)
|
158
110
|
end
|
@@ -163,20 +115,10 @@ def elixir
|
|
163
115
|
end
|
164
116
|
|
165
117
|
def fragment
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
code << "# Ruby code\n\n" if lexer == :ruby
|
171
|
-
_body(true) {|line| code << " " + line }
|
172
|
-
_debug "code = \n#{code}\n-----"
|
173
|
-
params = "(code, lexer: #{lexer.inspect}, options: {})"
|
174
|
-
_debug "-- pygments params = #{params}"
|
175
|
-
text = _colorize!(code, lexer)
|
176
|
-
text ||= "ERROR IN HIGHLIGHTER"
|
177
|
-
_debug "text = \n#{text.inspect}\n-----"
|
178
|
-
# PygmentFix.pyg_finalize(text, lexer)
|
179
|
-
_out text + "\n<br>"
|
118
|
+
lang = @_args.empty? ? :elixir : @_args.first.to_sym # ruby or elixir
|
119
|
+
@_args = []
|
120
|
+
send(lang)
|
121
|
+
_out "\n"
|
180
122
|
end
|
181
123
|
|
182
124
|
def code # FIXME ?
|
@@ -186,8 +128,76 @@ end
|
|
186
128
|
|
187
129
|
def mono
|
188
130
|
_out "<pre>"
|
189
|
-
_body
|
131
|
+
_body {|line| _out " " + line }
|
190
132
|
_out "</pre>"
|
191
133
|
end
|
192
134
|
|
135
|
+
def create_code_styles
|
136
|
+
dir = @_outdir || "."
|
137
|
+
theme, back = "Github", "white"
|
138
|
+
css = Rouge::Themes.const_get(theme).render(scope: '.rb_highlight')
|
139
|
+
added = <<~CSS
|
140
|
+
.rb_highlight {
|
141
|
+
font-family: 'Monaco', 'Andale Mono', 'Lucida Grande', 'Courier', 'Lucida Console', 'Courier New', monospace;
|
142
|
+
white-space: pre;
|
143
|
+
background-color: #{back}
|
144
|
+
}
|
145
|
+
CSS
|
146
|
+
|
147
|
+
css.gsub!(/{\n/, "{\n font-family: courier;")
|
148
|
+
css = added + "\n" + css
|
149
|
+
# STDERR.puts "Writing #{theme} theme to ruby.css"
|
150
|
+
File.write("#{dir}/ruby.css", css)
|
151
|
+
|
152
|
+
css = Rouge::Themes.const_get(theme).render(scope: '.ex_highlight')
|
153
|
+
added = added.sub(/rb/, "ex")
|
154
|
+
css.gsub!(/{\n/, "{\n font-family: courier;")
|
155
|
+
css = added + "\n" + css
|
156
|
+
# STDERR.puts "Writing #{theme} theme to elixir.css"
|
157
|
+
File.write("#{dir}/elixir.css", css)
|
158
|
+
end
|
159
|
+
|
193
160
|
|
161
|
+
def format_ruby(source, theme = "Github", back = "black")
|
162
|
+
# theme/back not used now
|
163
|
+
formatter = Rouge::Formatters::HTML.new
|
164
|
+
lexer = Rouge::Lexers::Ruby.new
|
165
|
+
body = formatter.format(lexer.lex(source))
|
166
|
+
text = "<div class=rb_highlight>#{body}</div>"
|
167
|
+
text
|
168
|
+
end
|
169
|
+
|
170
|
+
def format_elixir(source, theme = "Github", back = "black")
|
171
|
+
# theme/back not used now
|
172
|
+
formatter = Rouge::Formatters::HTML.new
|
173
|
+
lexer = Rouge::Lexers::Elixir.new
|
174
|
+
body = formatter.format(lexer.lex(source))
|
175
|
+
text = "<div class=ex_highlight>#{body}</div>"
|
176
|
+
text
|
177
|
+
end
|
178
|
+
|
179
|
+
def ruby
|
180
|
+
file = @_args.first
|
181
|
+
if file.nil?
|
182
|
+
code = " # Ruby code\n\n"
|
183
|
+
_body {|line| code << " " + line + "\n" }
|
184
|
+
else
|
185
|
+
code = "# Ruby code\n\n" + ::File.read(file)
|
186
|
+
end
|
187
|
+
|
188
|
+
html = format_ruby(code)
|
189
|
+
_out html
|
190
|
+
end
|
191
|
+
|
192
|
+
def elixir
|
193
|
+
file = @_args.first
|
194
|
+
if file.nil?
|
195
|
+
code = ""
|
196
|
+
_body {|line| code << " " + line + "\n" }
|
197
|
+
else
|
198
|
+
code = ::File.read(file)
|
199
|
+
end
|
200
|
+
|
201
|
+
html = format_elixir(code)
|
202
|
+
_out html
|
203
|
+
end
|
data/plugin/tutorial.rb
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
|
3
|
-
def title
|
3
|
+
def title(args = nil, body = nil)
|
4
4
|
h1
|
5
|
+
_optional_blank_line
|
5
6
|
end
|
6
7
|
|
7
|
-
def section
|
8
|
+
def section(args = nil, body = nil)
|
8
9
|
h3
|
10
|
+
_optional_blank_line
|
9
11
|
end
|
10
12
|
|
11
|
-
def code
|
13
|
+
def code(args = nil, body = nil)
|
12
14
|
first = true # dumb hack! fixes blank space
|
13
15
|
_body do |line|
|
14
16
|
tag, first = "<pre>", false if first
|
15
17
|
_out "#{tag} #{::CGI.escape_html(line)}" # indentation
|
16
18
|
end
|
17
19
|
_out "</pre>"
|
20
|
+
_optional_blank_line
|
18
21
|
end
|
19
22
|
|
20
23
|
def rx(str)
|
21
24
|
::Regexp.compile(::Regexp.escape(str))
|
22
25
|
end
|
23
26
|
|
24
|
-
def inout
|
27
|
+
def inout(args = nil, body = nil)
|
25
28
|
src, out = _args
|
26
29
|
t1 = ::File.readlines(src) rescue (abort "t1 = #{src}")
|
27
30
|
t2 = ::File.readlines(out) rescue (abort "t2 = #{out}")
|
@@ -45,6 +48,7 @@ def inout
|
|
45
48
|
</tr>
|
46
49
|
</table>
|
47
50
|
HTML
|
51
|
+
_optional_blank_line
|
48
52
|
end
|
49
53
|
|
50
54
|
def put_table(src, exp)
|
@@ -73,11 +77,12 @@ def put_table(src, exp)
|
|
73
77
|
HTML
|
74
78
|
end
|
75
79
|
|
76
|
-
def testcase
|
80
|
+
def testcase(args = nil, body = nil)
|
77
81
|
name = _args.first
|
78
82
|
_out "\n<font size=+1><b>Test: </font><font size=+2><tt>#{name}</tt></font></b></h3><br>"
|
79
83
|
src, exp = "test/data/#{name}/source.lt3", "test/data/#{name}/expected-output.txt"
|
80
84
|
@_args = [src, exp] # Better way to do this??
|
81
85
|
put_table(src, exp)
|
82
86
|
_out "<br>"
|
87
|
+
_optional_blank_line
|
83
88
|
end
|
data/test/all.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Comments are ignored.
|
2
|
+
# Other lines: name_of_snapshot and any comments here are ignored (no # needed)
|
3
|
+
# fake_test_name Use # to un-omit ;)
|
4
|
+
error_no_such_inc Output BEFORE error doesn't get passed through
|
5
|
+
error_no_such_copy ^ Same behavior as error_no_such_inc
|
6
|
+
error_no_such_mixin ^ Same behavior as error_missing_end
|
7
|
+
error_invalid_name ^ Same behavior as error_no_such_inc
|
8
|
+
error_missing_end Output is duplicated somehow. Look for: puts @body or puts @main.body
|
9
|
+
error_inc_line_num Forgot what's wrong here
|
10
|
+
simple_import Not coded yet
|
11
|
+
icanhaz Dummy command similar to import/mixin
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|