Editing Ayase
From Bibliotheca Anonoma
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 218: | Line 218: | ||
The proposed python code for converting bbcode back to their original 4chan html tags is as follows: | The proposed python code for converting bbcode back to their original 4chan html tags is as follows: | ||
<pre> | |||
def convert_comment(a): | |||
# basic html escape | |||
a = a.replace("&", "&") | |||
a = a.replace("\"", """) | |||
a = a.replace("\'", "'") | |||
a = a.replace("<", "<") | |||
a = a.replace(">", ">") | |||
# newlines | |||
a = a.replace("\r\n", "\n") | |||
# fix [/spoiler] that should be </span> | |||
if "<span" in a: | |||
a = re.sub("(<span(.+?))\[\/spoiler\]", "\\1</span>", a) | |||
# spoilers | |||
# needs to be first because they will end other stuff like quotes | |||
for idx in range(10): | |||
if not "[spoiler]" in a: break | |||
a = re.sub("\[spoiler\](.*?)\[\/spoiler\]", "<s>\\1</s>", a, flags=re.S) | |||
# remaining tags | |||
if "[" in a: | |||
a = re.sub("\[banned\](.*?)\[\/banned\]", "<strong style=\"color: red;\">\\1</strong>", a, flags=re.S) | |||
a = re.sub("\[code\](.*?)\[\/code\]", "<pre class=\"prettyprint\">\\1</pre>", a, flags=re.S) | |||
a = re.sub("\[math\](.*?)\[\/math\]", "<span class=\"math\">\\1</span>", a, flags=re.S) | |||
a = re.sub("\[eqn\](.*?)\[\/eqn\]", "<div class=\"math\">\\1</div>", a, flags=re.S) | |||
a = re.sub("\[sjis\](.*?)\[\/sjis\]", "<span class=\"sjis\">\\1</span>", a, flags=re.S) | |||
a = re.sub("\[shiftjis\](.*?)\[\/shiftjis\]", "<span class=\"sjis\">\\1</span>", a, flags=re.S) | |||
if ">" in a: | |||
# quotelinks | |||
a = re.sub("(>>(\d+))", "<a>\\1</a>", a) | |||
a = re.sub("(>>>\/(\w+)\/(\d+)?)", "<a>\\1</a>", a) | |||
# greentext | |||
a = re.sub("(^|\n)( )?(>(?:.*?))(?=$|\n|<\/?s>)", "\\1\\2<span class=\"quote\">\\3</span>", a, flags=re.S) | |||
if ":lit]" in a: | |||
a = re.sub("\[(\/?[a-z]+?):lit\]", "[\\1]", a) | |||
a = a.replace("\n", "<br>") | |||
return a | |||
</pre> | |||
https://gist.github.com/bakugo/1545c39231d6ed10226b4600d7270681 | https://gist.github.com/bakugo/1545c39231d6ed10226b4600d7270681 |