Rich Text Editor (WIP)
This commit is contained in:
@@ -42,19 +42,6 @@ class Formatter
|
||||
|
||||
html = encode_and_link_urls(html, linkable_accounts)
|
||||
|
||||
# : todo :
|
||||
if options[:use_markdown]
|
||||
html = convert_headers(html)
|
||||
html = convert_strong(html)
|
||||
html = convert_italic(html)
|
||||
html = convert_strikethrough(html)
|
||||
html = convert_code(html)
|
||||
html = convert_codeblock(html)
|
||||
html = convert_links(html)
|
||||
html = convert_lists(html)
|
||||
html = convert_ordered_lists(html)
|
||||
end
|
||||
|
||||
html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify]
|
||||
|
||||
html = simple_format(html, {}, sanitize: false)
|
||||
@@ -321,79 +308,4 @@ class Formatter
|
||||
"<a data-focusable=\"true\" role=\"link\" href=\"#{encode(TagManager.instance.url_for(account))}\" class=\"u-url mention\">@#{encode(account.acct)}</a>"
|
||||
end
|
||||
|
||||
def convert_headers(html)
|
||||
html.gsub(/^\#{1,6}.*$/) do |header|
|
||||
weight = 0
|
||||
header.split('').each do |char|
|
||||
break unless char == '#'
|
||||
weight += 1
|
||||
end
|
||||
content = header.sub(/^\#{1,6}/, '')
|
||||
"<h#{weight}>#{content}</h#{weight}>"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_strong(html)
|
||||
html.gsub(/\*{2}.*\*{2}|_{2}.*_{2}/) do |strong|
|
||||
content = strong.gsub(/\*{2}|_{2}/, '')
|
||||
"<strong>#{content}</strong>"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_italic(html)
|
||||
html.gsub(/\*{1}(\w|\s)+\*{1}|_{1}(\w|\s)+_{1}/) do |italic|
|
||||
content = italic.gsub(/\*{1}|_{1}/, '')
|
||||
"<em>#{content}</em>"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_strikethrough(html)
|
||||
html.gsub(/~~(\w|\s)+~~/) do |strike|
|
||||
content = strike.gsub(/~~/, '')
|
||||
"<strike>#{content}</strike>"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_code(html)
|
||||
html.gsub(/`(\w|\s)+`/) do |code|
|
||||
content = code.gsub(/`/, '')
|
||||
"<code>#{content}</code>"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_codeblock(html)
|
||||
html.gsub(/```\w*(.*(\r\n|\r|\n))+```/) do |code|
|
||||
lang = code.match(/```\w+/)[0].gsub(/`/, '')
|
||||
content = code.gsub(/```\w+/, '```').gsub(/`/, '')
|
||||
"<pre class=\"#{lang}\"><code>#{content}</code></pre>"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_links(html)
|
||||
html.gsub(/\[(\w|\s)+\]\((\w|\W)+\)/) do |anchor|
|
||||
link_text = anchor.match(/\[(\w|\s)+\]/)[0].gsub(/[\[\]]/, '')
|
||||
href = anchor.match(/\((\w|\W)+\)/)[0].gsub(/\(|\)/, '')
|
||||
"<a href=\"#{href}\">#{link_text}</a>"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_lists(html)
|
||||
html.gsub(/(\-.+(\r|\n|\r\n))+/) do |list|
|
||||
items = "<ul>\n"
|
||||
list.gsub(/\-.+/) do |li|
|
||||
items << "<li>#{li.sub(/^\-/, '').strip}</li>\n"
|
||||
end
|
||||
items << "</ul>\n"
|
||||
end
|
||||
end
|
||||
|
||||
def convert_ordered_lists(html)
|
||||
html.gsub(/(\d\..+(\r|\n|\r\n))+/) do |list|
|
||||
items = "<ol>\n"
|
||||
list.gsub(/\d.+/) do |li|
|
||||
items << "<li>#{li.sub(/^\d\./, '').strip}</li>\n"
|
||||
end
|
||||
items << "</ol>\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user