2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-31 14:05:14 +00:00

No more <> spacing evilry in dtext.

This commit is contained in:
Edho Arief
2012-06-07 05:18:27 -07:00
parent ff1282cf97
commit 37df8f76ec

View File

@@ -105,17 +105,15 @@ module DText
end
def parseurl(str)
str.gsub!(/([<>])/, ' \1 ')
# Basic URL pattern
url = /(h?ttps?:\/\/\[?(:{0,2}[\w\-]+)((:{1,2}|\.)[\w\-]+)*\]?(:\d+)*(\/[^\s\n]*)*)/
url = /(h?ttps?:\/\/\[?(:{0,2}[\w\-]+)((:{1,2}|\.)[\w\-]+)*\]?(:\d+)*(\/[^\s\n<]*)*)/
# Substitute url tag in this form:
str.gsub!(/(^|[\s\(])#{url}/, '\1<a href="\2">\2</a>') # url
str.gsub!(/(^|[\s\(>])#{url}/, '\1<a href="\2">\2</a>') # url
str.gsub!(/&lt;&lt;\s*#{url}\s*\|\s*(.+?)\s*&gt;&gt;/, '<a href="\1">\7</a>') # <<url|label>>
str.gsub!(/(^|\s+)&quot;(.+?)&quot;:#{url}/, '\1<a href="\3">\2</a>') # "label":url
str.gsub!(/&lt;&lt;\s*#{url}\s*&gt;&gt;/, '<a href="\1">\1</a>') # <<url>>
str.gsub!(/<a href="ttp/, '<a href="http') # Fix ttp(s) scheme
str.gsub!(/ ([<>]) /, '\1')
return str
end