REBOL [
Title: "BBcode"
Date: 5-Jan-2009/1:06:26+1:00
Name: 'bbcode
Version: 0.1.0
File: %bbcode.r
Author: "David 'Oldes' Oliva"
Email: oliva.david@seznam.cz
Home: http://box.lebeda.ws/~hmm/
Owner: none
Rights: none
Needs: none
Tabs: 4
Usage: [
test-cases: [
{text [b]bold[/b] abc} {text bold abc}
{text [b]bold [i]italic[/b]} {text bold italic}
{[s]strikethrough text[/s]} {strikethrough text}
{[url]http://example.org[/url]} {http://example.org}
{[url=http://example.com]Example[/url]} {Example}
{[url=http://example.com][b]Example[/url]} {Example}
{[b][ul][li]Jenny[/li][li]Alex[/li][li]Beth[/li][/ul][/b]} {
}
{[ul][li]bla[li]bla} {
xx[b]yy[/b]zz
}
{[list][*]aaa[*]bbb[/list]} {} tmp {
}]
)
|
"[rebol]" copy tmp to "[/rebol]" thru "]" (
append html rejoin [{} tmp {
}]
;TODO: add REBOL code colorizer
)
|
#"[" [
;normal opening tags
copy tag some ch-name opt rl-attribute
#"]" (
if tag = "*" [tag: "li"]
append html either find enabled-tags tag [
if find ["li"] tag [
;closed already opened tag
if all [
tmp: find/last opened-tags tag
none? find tmp "ol"
none? find tmp "ul"
][
close-tags copy tmp
clear tmp
]
]
append opened-tags tag
switch/default tag [
"url" [rejoin [{}]]
"color" [
either all [attr parse attr [
#"#" [6 ch-hexa | 3 ch-hexa]
]][
append opened-tags "span"
rejoin [{}]
][
;;Should the invalid tag be visible?
;rejoin either attr [
; ["[" tag "=" attr "]"]
;][ ["[" tag "]"] ]
""
]
]
"quote" [
append opened-tags ["fieldset" "blockquote"]
either attr [
rejoin [{