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 "pg"
|
||||||
require "set"
|
require "set"
|
||||||
require "redcarpet"
|
require "redcarpet"
|
||||||
|
@ -66,6 +79,7 @@ class BulkImport::Base
|
||||||
@uploader = ImportScripts::Uploader.new
|
@uploader = ImportScripts::Uploader.new
|
||||||
@html_entities = HTMLEntities.new
|
@html_entities = HTMLEntities.new
|
||||||
@encoding = CHARSET_MAP[charset]
|
@encoding = CHARSET_MAP[charset]
|
||||||
|
@bbcode_to_md = true if use_bbcode_to_md?
|
||||||
|
|
||||||
@markdown = Redcarpet::Markdown.new(
|
@markdown = Redcarpet::Markdown.new(
|
||||||
Redcarpet::Render::HTML.new(hard_wrap: true),
|
Redcarpet::Render::HTML.new(hard_wrap: true),
|
||||||
|
@ -172,6 +186,10 @@ class BulkImport::Base
|
||||||
@last_post_action_id = last_id(PostAction)
|
@last_post_action_id = last_id(PostAction)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def use_bbcode_to_md?
|
||||||
|
ARGV.include?("bbcode-to-md")
|
||||||
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
@ -463,6 +481,9 @@ class BulkImport::Base
|
||||||
@topic_id_by_post_id[post[:id]] = post[:topic_id]
|
@topic_id_by_post_id[post[:id]] = post[:topic_id]
|
||||||
post[:raw] = (post[:raw] || "").scrub.strip.presence || "<Empty imported post>"
|
post[:raw] = (post[:raw] || "").scrub.strip.presence || "<Empty imported post>"
|
||||||
post[:raw] = process_raw post[:raw]
|
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[:like_count] ||= 0
|
||||||
post[:cooked] = pre_cook post[:raw]
|
post[:cooked] = pre_cook post[:raw]
|
||||||
post[:hidden] ||= false
|
post[:hidden] ||= false
|
||||||
|
|
Loading…
Reference in New Issue