forum: automatically post new forum posts to Discord.

This commit is contained in:
evazion
2021-02-18 07:08:45 -06:00
parent 93f6e935a8
commit b63d8207a9
6 changed files with 106 additions and 0 deletions

View File

@@ -250,6 +250,29 @@ class DText
text.gsub(/\A[[:space:]]+|[[:space:]]+\z/, "")
end
def self.to_markdown(dtext)
html_to_markdown(format_text(dtext))
end
def self.html_to_markdown(html)
html = Nokogiri::HTML.fragment(html)
html.children.map do |node|
case node.name
when "div", "blockquote", "table"
"" # strip [expand], [quote], and [table] tags
when "br"
"\n"
when "text"
node.text.gsub(/_/, '\_').gsub(/\*/, '\*')
when "p", "h1", "h2", "h3", "h4", "h5", "h6"
html_to_markdown(node.inner_html) + "\n\n"
else
html_to_markdown(node.inner_html)
end
end.join
end
def self.from_html(text, inline: false, &block)
html = Nokogiri::HTML.fragment(text)