From e1f7d056772f3f1e7312d1e87e3aa5928c3dbf94 Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Wed, 2 Mar 2016 15:11:33 -0800 Subject: [PATCH] phpbb-import-script: move bbcode_to_md to before other text processing This seems to fix the issue I reported at https://meta.discourse.org/t/import-script-phpbb/40424 --- script/import_scripts/phpbb3/importer.rb | 4 +++- .../import_scripts/phpbb3/support/text_processor.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/script/import_scripts/phpbb3/importer.rb b/script/import_scripts/phpbb3/importer.rb index 9f88a73b2b4..83d748fa6ed 100644 --- a/script/import_scripts/phpbb3/importer.rb +++ b/script/import_scripts/phpbb3/importer.rb @@ -172,8 +172,10 @@ module ImportScripts::PhpBB3 # no need for this since the importer sets last_seen_at for each user during the import end + # Do not use the bbcode_to_md in base.rb. If enabled, it will be + # used in text_processor.rb instead. def use_bbcode_to_md? - @settings.use_bbcode_to_md + false end def batches diff --git a/script/import_scripts/phpbb3/support/text_processor.rb b/script/import_scripts/phpbb3/support/text_processor.rb index c0e99e4dd2a..edd104f6d33 100644 --- a/script/import_scripts/phpbb3/support/text_processor.rb +++ b/script/import_scripts/phpbb3/support/text_processor.rb @@ -9,6 +9,7 @@ module ImportScripts::PhpBB3 @database = database @smiley_processor = smiley_processor + @settings = settings @new_site_prefix = settings.new_site_prefix create_internal_link_regexps(settings.original_site_prefix) end @@ -18,6 +19,9 @@ module ImportScripts::PhpBB3 text = CGI.unescapeHTML(text) clean_bbcodes(text) + if @settings.use_bbcode_to_md + text = bbcode_to_md(text) + end process_smilies(text) process_links(text) process_lists(text) @@ -46,6 +50,15 @@ module ImportScripts::PhpBB3 text.gsub!(/:(?:\w{8})\]/, ']') end + def bbcode_to_md(text) + begin + text.bbcode_to_md(false) + rescue e + puts "Problem converting \n#{text}\n using ruby-bbcode-to-md" + text + end + end + def process_smilies(text) @smiley_processor.replace_smilies(text) end