FIX: BBCode to Markdown conversion in phpBB3 importer was broken

This fixes the conversion for quotes, code blocks and lists (except for nested lists). It also discourages the usage of the ruby-bbcode-to-md gem.
This commit is contained in:
Gerhard Schlager 2018-01-30 12:49:51 +01:00
parent c26db2116c
commit 192a0886e2
2 changed files with 15 additions and 7 deletions

View File

@ -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. batch_size: 1000 # Don't change this unless you know what you're doing. The default (1000) should work just fine.
import: import:
# Enable this option if you want to have a better conversion of BBCodes to Markdown. # WARNING: Do not activate this option unless you know what you are doing.
# WARNING: This can slow down your import. # It will probably break the BBCode to Markdown conversion and slows down your import.
use_bbcode_to_md: false use_bbcode_to_md: false
# This is the path to the root directory of your current phpBB installation (or a copy of it). # This is the path to the root directory of your current phpBB installation (or a copy of it).

View File

@ -27,6 +27,7 @@ module ImportScripts::PhpBB3
process_links(text) process_links(text)
process_lists(text) process_lists(text)
process_code(text) process_code(text)
fix_markdown(text)
text text
end end
@ -114,11 +115,13 @@ module ImportScripts::PhpBB3
# convert list tags to ul and list=1 tags to ol # convert list tags to ul and list=1 tags to ol
# list=a is not supported, so handle it like list=1 # 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 # 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:u\]/mi) do
text.gsub!(/\[list=.*?\](.*?)\[\/list:o\]/mi, '[ol]\1[/ol]') $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!(/\[list=.*?\](.*?)\[\/list:o\]/mi) do
text.gsub!(/\[\*\](.*?)\[\/\*:m\]/mi, '[li]\1[/li]') $1.gsub(/\[\*\](.*?)\[\/\*:m\]\n*/mi) { "1. #{$1}\n" }
end
end end
# This replaces existing [attachment] BBCodes with the corresponding HTML tags for Discourse. # This replaces existing [attachment] BBCodes with the corresponding HTML tags for Discourse.
@ -149,9 +152,14 @@ module ImportScripts::PhpBB3
def process_code(text) def process_code(text)
text.gsub!(/<span class="syntax.*?>(.*?)<\/span>/) { "#{$1}" } 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.gsub!(/<br \/>/, "\n")
text text
end end
def fix_markdown(text)
text.gsub!(/(\n*\[\/?quote.*?\]\n*)/mi) { |q| "\n#{q.strip}\n" }
text
end
end end
end end