FEATURE: option to use ruby-bbcode-to-md in bulk import script
ruby-bbcode-to-md provides better bbcode to markdown conversion
This commit is contained in:
parent
0365d50797
commit
735a48415d
|
@ -1,3 +1,16 @@
|
|||
if ARGV.include?('bbcode-to-md')
|
||||
# Replace (most) bbcode with markdown before creating posts.
|
||||
# This will dramatically clean up the final posts in Discourse.
|
||||
#
|
||||
# In a temp dir:
|
||||
#
|
||||
# git clone https://github.com/nlalonde/ruby-bbcode-to-md.git
|
||||
# cd ruby-bbcode-to-md
|
||||
# gem build ruby-bbcode-to-md.gemspec
|
||||
# gem install ruby-bbcode-to-md-*.gem
|
||||
require 'ruby-bbcode-to-md'
|
||||
end
|
||||
|
||||
require "pg"
|
||||
require "set"
|
||||
require "redcarpet"
|
||||
|
@ -66,6 +79,7 @@ class BulkImport::Base
|
|||
@uploader = ImportScripts::Uploader.new
|
||||
@html_entities = HTMLEntities.new
|
||||
@encoding = CHARSET_MAP[charset]
|
||||
@bbcode_to_md = true if use_bbcode_to_md?
|
||||
|
||||
@markdown = Redcarpet::Markdown.new(
|
||||
Redcarpet::Render::HTML.new(hard_wrap: true),
|
||||
|
@ -172,6 +186,10 @@ class BulkImport::Base
|
|||
@last_post_action_id = last_id(PostAction)
|
||||
end
|
||||
|
||||
def use_bbcode_to_md?
|
||||
ARGV.include?("bbcode-to-md")
|
||||
end
|
||||
|
||||
def execute
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
@ -463,6 +481,9 @@ class BulkImport::Base
|
|||
@topic_id_by_post_id[post[:id]] = post[:topic_id]
|
||||
post[:raw] = (post[:raw] || "").scrub.strip.presence || "<Empty imported post>"
|
||||
post[:raw] = process_raw post[:raw]
|
||||
if @bbcode_to_md
|
||||
post[:raw] = post[:raw].bbcode_to_md(false) rescue post[:raw]
|
||||
end
|
||||
post[:like_count] ||= 0
|
||||
post[:cooked] = pre_cook post[:raw]
|
||||
post[:hidden] ||= false
|
||||
|
|
Loading…
Reference in New Issue