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("&", "&amp;")
a = a.replace("\"", "&quot;")
a = a.replace("\'", "&#039;")
a = a.replace("<", "&lt;")
a = a.replace(">", "&gt;")
# newlines
a = a.replace("\r\n", "\n")
# fix [/spoiler] that should be </span>
if "&lt;span" in a:
a = re.sub("(&lt;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 "&gt;" in a:
# quotelinks
a = re.sub("(&gt;&gt;(\d+))", "<a>\\1</a>", a)
a = re.sub("(&gt;&gt;&gt;\/(\w+)\/(\d+)?)", "<a>\\1</a>", a)
# greentext
a = re.sub("(^|\n)( )?(&gt;(?:.*?))(?=$|\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
Please note that all contributions to Bibliotheca Anonoma are considered to be released under the Creative Commons Attribution-ShareAlike (see Bibliotheca Anonoma:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)