1
0
Fork 0
forked from gitea/nas

Merge branch 'kb_development' into kb_migration

This commit is contained in:
KMY 2023-03-04 16:20:34 +09:00
commit 3e1b4108ed
6 changed files with 84 additions and 5 deletions

View file

@ -43,7 +43,13 @@ class TextFormatter
end
end
html = simple_format(html, {}, sanitize: false).delete("\n") if multiline?
# line first letter for blockquote
p 'DEBUG ' + html.gsub(/^gt;/, '>')
html = markdownify(html.gsub(/^>/, '>'))
# html = simple_format(html, {}, sanitize: false).delete("\n") if multiline?
html = html.delete("\n")
p html
html.html_safe # rubocop:disable Rails/OutputSafety
end
@ -155,4 +161,45 @@ class TextFormatter
def preloaded_accounts?
preloaded_accounts.present?
end
def markdownify(html)
# not need filter_html because escape is already done
@htmlobj ||= MyMarkdownHTML.new(
filter_html: false,
hard_wrap: true
)
@markdown ||= Redcarpet::Markdown.new(@htmlobj,
autolink: false,
tables: false,
underline: true,
disable_indented_code_blocks: false,
fenced_code_blocks: true,
highlight: false
)
@markdown.render(html)
end
class MyMarkdownHTML < Redcarpet::Render::HTML
def link(link, title, content)
nil
end
def block_code(code, language)
"<pre>#{process_program_code(code)}</pre>"
end
def codespan(code)
"<code>#{process_program_code(code)}</code>"
end
def header(text, header_level)
"<p>#{text}</p>"
end
private
def process_program_code(code)
code.gsub(/\n/, '<br>')
end
end
end