mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user