I am trying to write a simple bbcode Python script. How can I improve this? Also, how can I get rid of the ":arg" when the result is actually printed. YES I KNOW ITS PROBABLY FUCKING UGLY AND I AM A SHITTY PROGRAMMER FORCED INDENTATION OF ANUS READ SICP ETC
import string
b = '[b]'
b2 = '[/b]'
u = '[u]'
u2 = '[/u]'
o = '[o]'
o2 = '[/o]'
i = '[i]'
i2 = '[/i]'
s = '[s]'
s2 = '[/s]'
m = '[m]'
m2 = '[/m]'
c = '[code]'
c2 = ''
sp = ''
sp2 = ''
bbcode = raw_input('ENTER ANUS, RECEIVE HAX: ')
if ':b' in bbcode:
print b + bbcode + b2
if ':u' in bbcode:
print u + bbcode + u
if ':o' in bbcode:
print o + bbcode + o2
if ':i' in bbcode:
print i + bbcode + i2
if ':s' in bbcode:
print s + bbcode + s2
if ':m' in bbcode:
print m + bbcode + m2
if ':c' in bbcode:
print c + bbcode + c2
if ':sp' in bbcode:
print sp + bbcode + sp2[/code]
def bbcode_strip!(str)
str.gsub!(REGEXP_BBCODE) { bbcode_strip!($3) }
return str
end
def bbcode_replace!(str)
str.gsub!(REGEXP_BBCODE) do |match|
case $1
when 'b'
"<b>#{bbcode_replace!($3)}</b>"
when 'i'
"<i>#{bbcode_replace!($3)}</i>"
when 'o'
"<o>#{bbcode_replace!($3)}</o>"
when 'u'
"<u>#{bbcode_replace!($3)}</u>"
when 'sub'
"<sub>#{bbcode_replace!($3)}</sub>"
when 'sup'
"<sup>#{bbcode_replace!($3)}</sup>"
when 'a'
"<a href=\"http:\/\/#{$2 || bbcode_strip!($3)}\" title=\"http:\/\/#{$2 || bbcode_strip!($3)}\">#{bbcode_replace!($3)}</a>"
when 'img'
"<img src=\"#{$2 || bbcode_strip!($3)}\" alt=\"#{bbcode_strip!($3)}\" title=\"#{bbcode_strip!($3)}\" />"
when '#'
$3
else
"[#{$1}#{$2 && "=#{$2}"}]#{bbcode_replace!($3)}[/#{$1}]"
end
end
return str
end