Class: MarkdownTopicConverter

Inherits:
MarkdownConverter show all
Defined in:
lib/markdown-ruby-china.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MarkdownConverter

convert, #convert

Class Method Details

.format(raw) ⇒ Object



98
99
100
# File 'lib/markdown-ruby-china.rb', line 98

def self.format(raw)
  self.instance.format(raw)
end

Instance Method Details

#format(raw) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/markdown-ruby-china.rb', line 102

def format(raw)
  text = raw.clone
  return '' if text.blank?

  convert_bbcode_img(text)
  users = nomalize_user_mentions(text)

  # 如果 ``` 在刚刚换行的时候 Redcapter 无法生成正确,需要两个换行
  text.gsub!("\n```","\n\n```")

  # 调用MarkdownConverter父类来高亮代码
  result = convert(text)

  doc = Nokogiri::HTML.fragment(result)
  link_mention_floor(doc)
  link_mention_user(doc, users)
  replace_emoji(doc)

  return doc.to_html.strip
rescue => e
  puts "MarkdownTopicConverter.format ERROR: #{e}"
  return text
end