From b1e69d1f9594eee97d1d4378c2a95727a4195cb6 Mon Sep 17 00:00:00 2001 From: Erick Guan Date: Tue, 10 Feb 2015 21:43:16 -0800 Subject: [PATCH] find more reply syntax during processing in discuzx importer --- script/import_scripts/discuz_x.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/script/import_scripts/discuz_x.rb b/script/import_scripts/discuz_x.rb index 171cb96d0a3..a3795bf7b9c 100644 --- a/script/import_scripts/discuz_x.rb +++ b/script/import_scripts/discuz_x.rb @@ -361,6 +361,10 @@ class ImportScripts::DiscuzX < ImportScripts::Base # [quote] quotation includes the topic which is the same as reply to in Discourse # We get the pid to find the post number the post reply to. So it can be stripped s = s.gsub(/\[quote\][\s\S]*?\[\/quote\]/i, '').strip + s = s.gsub(/\[b\]回复 \[url=forum.php\?mod=redirect&goto=findpost&pid=\d+&ptid=\d+\].* 的帖子\[\/url\]\[\/b\]/i, '').strip + + # Convert image bbcode + s.gsub!(/\[img=(\d+),(\d+)\]([^\]]*)\[\/img\]/i, '') # Remove the font tag # Discourse doesn't support the font tag @@ -376,14 +380,16 @@ class ImportScripts::DiscuzX < ImportScripts::Base s.gsub!(/\[color=[^ \t\r\n\f\]]*?\]/i, '') s.gsub!(/\[\/color\]/i, '') + # Remove the hide tag + s.gsub!(/\[\/?hide\]/i, '') + # Remove the align tag # still don't know what it is s.gsub!(/\[align=[^ \t\r\n\f\]]*?\]/i, '') s.gsub!(/\[\/align\]/i, "\n") # Convert code - s.gsub!(/\[code\]/i, "\n```\n") - s.gsub!(/\[\/code\]/i, "\n```\n") + s.gsub!(/\[\/?code\]/i, "\n```\n") # The edit notice should be removed # example: 本帖最后由 Helloworld 于 2015-1-28 22:05 编辑 @@ -514,9 +520,10 @@ class ImportScripts::DiscuzX < ImportScripts::Base # post id is in the quote block def find_post_id_by_quote_number(raw) s = raw.dup - quote_post_id = s.match(/\[quote\][\S\s]*pid=(\d+)[\S\s]*\[\/quote\]/) + quote_reply = s.match(/\[quote\][\S\s]*pid=(\d+)[\S\s]*\[\/quote\]/) + reply = s.match(/url=forum.php\?mod=redirect&goto=findpost&pid=(\d+)&ptid=\d+/) - quote_post_id ? quote_post_id[1] : nil + quote_reply ? quote_reply[1] : (reply ? reply[1] : nil) end # for some reason, discuz inlined some png file