2
2
Name: bbcode
3
3
Type: module
4
4
Options: [delay]
5
- Version: 0.3.1
5
+ Version: 0.3.2
6
6
Title: "Codec: BBcode"
7
7
Purpose: {Basic BBCode implementation. For more info about BBCode check http://en.wikipedia.org/wiki/BBCode}
8
8
File: https://raw.githubusercontent.com/Oldes/Rebol3/master/src/mezz/codec-bbcode.reb
@@ -13,7 +13,8 @@ REBOL [
13
13
0.2.0 19-Feb-2012 "review"
14
14
0.2.1 22-Aug-2012 "added [hr] and [anchor]"
15
15
0.3.0 24-Apr-2020 "ported to Rebol3"
16
- 0.3.1 11-Dec-2023 "FIX: `bbcode` must accept only string input"
16
+ 0.3.1 11-Dec-2023 "FIX: `bbcode` must accept only string input" \
17
+ 0.3.2 12-Dec-2023 "FEAT: csv table emitter"
17
18
]
18
19
]
19
20
@@ -39,6 +40,7 @@ ch_digits: charset [#"0" - #"9"]
39
40
ch_hexa: charset [#"a" - #"f" #"A" - #"F" #"0" - #"9" ]
40
41
ch_name: charset [#"a" - #"z" #"A" - #"Z" #"*" #"0" - #"9" ]
41
42
ch_url: charset [#"a" - #"z" #"A" - #"Z" #"0" - #"9" "./:~+-%#\_=&?@" ]
43
+ ch_crlf: charset CRLF
42
44
ch_safe-value-chars: complement charset {'"}
43
45
44
46
rl_newline: [CRLF | LF]
@@ -188,6 +190,69 @@ emit-tag: func[tag][
188
190
insert tail html either block? tag [rejoin tag][tag]
189
191
]
190
192
193
+ emit-tag-csv: function/with [spec [string! ]][
194
+ row: "" ;; no copy, it is cleared each time
195
+ trim/head/tail spec
196
+
197
+ close-p-if-possible
198
+ close-tags
199
+ emit-tag [{<table} form-attribute "class" form-attribute "align" form-attribute "style" {>^/ } ]
200
+ all [
201
+ widths: get-attribute "widths"
202
+ widths: transcode widths
203
+ ]
204
+ if align: get-attribute "coltype" [
205
+ parse align [
206
+ some [
207
+ #"c" (emit-tag {<col align="center">^/ } )
208
+ | #"l" (emit-tag {<col align="left">^/ } )
209
+ | #"r" (emit-tag {<col align="right">^/ } )
210
+ | #"j" (emit-tag {<col align="justify">^/ } )
211
+ ]
212
+ ]
213
+ ]
214
+ ch_divider: charset get-attribute/default "divider" TAB
215
+ ch_notDivider: complement union ch_divider ch_crlf
216
+ rl_data: [copy data any ch_notDivider]
217
+
218
+ data: align: none
219
+ row-num: col-num: col-width: 0
220
+ datatag: "th" ;; first row is always used for headers!
221
+ parse spec [
222
+ some [
223
+ (
224
+ clear row
225
+ ++ row-num
226
+ )
227
+ any ch_space
228
+ some [
229
+ rl_data
230
+ 1 ch_divider
231
+ (
232
+ append row ajoin [{<} datatag get-col-width {>} data {</} datatag {>} ]
233
+ )
234
+ ]
235
+ rl_data [rl_newline | end] (
236
+ append row ajoin [{<} datatag get-col-width {>} data {</} datatag {>} ]
237
+ datatag: "td"
238
+ emit-tag ["<tr>" row "</tr>^/ " ]
239
+ )
240
+ ]
241
+ ]
242
+ emit-tag "</table>"
243
+ ] [
244
+ data: widths: align: row-num: col-num: col-width: none
245
+ get-col-width : does [
246
+ ++ col-num
247
+ either all [
248
+ row-num = 1
249
+ block? widths
250
+ col-width: pick widths col-num
251
+ integer? col-width
252
+ ][ ajoin [" width=" col-width] ][ "" ]
253
+ ]
254
+ ]
255
+
191
256
enabled-tags: [
192
257
"b" "i" "s" "u" "del" "h1" "h2" "h3" "h4" "h5" "h6" "span" "class"
193
258
"ins" "dd" "dt" "ol" "ul" "li" "url" "list" "br" "hr"
@@ -414,8 +479,8 @@ bbcode: func [
414
479
]
415
480
unless empty? opened-tags [ close-tags ]
416
481
html
417
- ]
418
- if error? err [
482
+ ][
483
+ err: system /state/last-error
419
484
; send possible trimmed error in the result instead of throwing it!
420
485
append html ajoin ["^/ #[ERROR! [code: " err/code " type: " err/type " id: " err/id #"]" ]
421
486
]
0 commit comments