FEATURE: Updated IPB import script

* IPB import script replace PHP code tags with proper markdown

remove excess newlines in code blocks
decode HTML entities in code blocks
add replacement for list items
proper handling of attachments that are not images
fix typo
improved quote handling
fix code style complaint from travis-ci build
This commit is contained in:
Carsten Brandt 2018-09-12 03:12:28 +02:00 committed by Sam
parent 16bd3f2cf2
commit 921e2213b8
1 changed files with 13 additions and 2 deletions

View File

@ -788,6 +788,10 @@ EOM
raw.gsub!(/'/, "'")
raw.gsub!(/\[url="(.+?)"\]http.+?\[\/url\]/, "\\1\n")
raw.gsub!(/\[media\](.+?)\[\/media\]/, "\n\\1\n\n")
raw.gsub!(/\[php\](.+?)\[\/php\]/m) { |m| "\n\n```php\n\n" + @htmlentities.decode($1.gsub(/\n\n/, "\n")) + "\n\n```\n\n" }
raw.gsub!(/\[code\](.+?)\[\/code\]/m) { |m| "\n\n```\n\n" + @htmlentities.decode($1.gsub(/\n\n/, "\n")) + "\n\n```\n\n" }
raw.gsub!(/\[list\](.+?)\[\/list\]/m) { |m| "\n" + $1.gsub(/\[\*\]/, "\n- ") + "\n\n" }
raw.gsub!(/\[quote\]/, "\n[quote]\n")
raw.gsub!(/\[\/quote\]/, "\n[/quote]\n")
raw.gsub!(/date=\'(.+?)\'/, '')
raw.gsub!(/timestamp=\'(.+?)\' /, '')
@ -829,9 +833,16 @@ EOM
puts "Attachment #{attach_id} not found."
attach_string = "Attachment #{attach_id} not found."
else
attach_string = "#{attach_id}\n\n![#{attachments.first['filename']}](#{UPLOADS}/#{attachments.first['loc']})\n"
attach_url = "#{UPLOADS}/#{attachments.first['loc'].gsub(' ', '%20')}"
if attachments.first['filename'].match(/(png|jpg|jpeg|gif)$/)
# images are rendered as a link that contains the image
attach_string = "#{attach_id}\n\n[![#{attachments.first['filename']}](#{attach_url})](#{attach_url})\n"
else
# other attachments are simple download links
attach_string = "#{attach_id}\n\n[#{attachments.first['filename']}](#{attach_url})\n"
end
end
raw.gsub!(attach_regex, attach_string)
raw.sub!(attach_regex, attach_string)
end
raw