Skip to content

A platform for community discussion. Free, open, simple.

FIX: BBCode to Markdown conversion in phpBB3 importer was broken

Gerhard Schlager192a0886e2de
diff --git a/script/import_scripts/phpbb3/settings.yml b/script/import_scripts/phpbb3/settings.yml
index 4fd15fc9d0b..08b50e283a1 100644
--- a/script/import_scripts/phpbb3/settings.yml
+++ b/script/import_scripts/phpbb3/settings.yml
@@ -11,8 +11,8 @@ database:
batch_size: 1000 # Don't change this unless you know what you're doing. The default (1000) should work just fine.
import:
- # Enable this option if you want to have a better conversion of BBCodes to Markdown.
- # WARNING: This can slow down your import.
+ # WARNING: Do not activate this option unless you know what you are doing.
+ # It will probably break the BBCode to Markdown conversion and slows down your import.
use_bbcode_to_md: false
# This is the path to the root directory of your current phpBB installation (or a copy of it).
diff --git a/script/import_scripts/phpbb3/support/text_processor.rb b/script/import_scripts/phpbb3/support/text_processor.rb
index d89a6cc99fb..fa6e623d328 100644
--- a/script/import_scripts/phpbb3/support/text_processor.rb
+++ b/script/import_scripts/phpbb3/support/text_processor.rb
@@ -27,6 +27,7 @@ module ImportScripts::PhpBB3
process_links(text)
process_lists(text)
process_code(text)
+ fix_markdown(text)
text
end
@@ -114,11 +115,13 @@ module ImportScripts::PhpBB3
# convert list tags to ul and list=1 tags to ol
# list=a is not supported, so handle it like list=1
# list=9 and list=x have the same result as list=1 and list=a
- text.gsub!(/\[list\](.*?)\[\/list:u\]/mi, '[ul]\1[/ul]')
- text.gsub!(/\[list=.*?\](.*?)\[\/list:o\]/mi, '[ol]\1[/ol]')
+ text.gsub!(/\[list\](.*?)\[\/list:u\]/mi) do
+ $1.gsub(/\[\*\](.*?)\[\/\*:m\]\n*/mi) { "* #{$1}\n" }
+ end
- # convert *-tags to li-tags so bbcode-to-md can do its magic on phpBB's lists:
- text.gsub!(/\[\*\](.*?)\[\/\*:m\]/mi, '[li]\1[/li]')
+ text.gsub!(/\[list=.*?\](.*?)\[\/list:o\]/mi) do
+ $1.gsub(/\[\*\](.*?)\[\/\*:m\]\n*/mi) { "1. #{$1}\n" }
+ end
end
# This replaces existing [attachment] BBCodes with the corresponding HTML tags for Discourse.
@@ -149,9 +152,14 @@ module ImportScripts::PhpBB3
def process_code(text)
text.gsub!(/<span class="syntax.*?>(.*?)<\/span>/) { "#{$1}" }
- text.gsub!(/\[code(=[a-z]*)?\](.*?)\[\/code\]/i) { "[code]#{@he.decode($2)}[/code]" }
+ text.gsub!(/\[code(=[a-z]*)?\](.*?)\[\/code\]/i) { "[code]\n#{@he.decode($2)}\n[/code]" }
text.gsub!(/<br \/>/, "\n")
text
end
+
+ def fix_markdown(text)
+ text.gsub!(/(\n*\[\/?quote.*?\]\n*)/mi) { |q| "\n#{q.strip}\n" }
+ text
+ end
end
end