quelques améliorations

This commit is contained in:
gcolpart 2016-12-26 22:44:22 +01:00
parent d6ef507190
commit 5c52253646

View file

@ -11,17 +11,21 @@ Si on souhaite convertir des pages du format Trac vers le format Markdown un pet
body = STDIN.read body = STDIN.read
body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '`\1`') body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '`\1`')
body.gsub!(/\{\{\{(.+?)\}\}\}/m){|m| m.each_line.map{|x| "\t#{x}".gsub(/[\{\}]{3}/,'')}.join} body.gsub!(/^\s*\*/, '*')
body.gsub!(/(\S)\n\* /, '\1' "\n\n* ")
body.gsub!(/^[ ]*\{\{\{/, '{{{')
body.gsub!(/(\S)\n\{\{\{/, '\1' "\n\n{{{")
body.gsub!(/\{\{\{(.+?)\}\}\}/m){|m| m.each_line.map{|x| "#{x}".gsub(/ *[\{\}]{3}/,"~~~")}.join}
body.gsub!(/\=\=\=\=\=\s(.+?)\s\=\=\=\=\=/, '##### \1') body.gsub!(/\=\=\=\=\=\s(.+?)\s\=\=\=\=\=/, '##### \1')
body.gsub!(/\=\=\=\=\s(.+?)\s\=\=\=\=/, '#### \1') body.gsub!(/\=\=\=\=\s(.+?)\s\=\=\=\=/, '#### \1')
body.gsub!(/\=\=\=\s(.+?)\s\=\=\=/, '### \1') body.gsub!(/\=\=\=\s(.+?)\s\=\=\=/, '### \1')
body.gsub!(/\=\=\s(.+?)\s\=\=/, '## \1') body.gsub!(/\=\=\s(.+?)\s\=\=/, '## \1')
body.gsub!(/\=\s(.+?)\s\=/, '# \1') body.gsub!(/\=\s(.+?)\s\=/, '# \1')
body.gsub!(/\[(https?[^\s\[\]]+)\s([^\[\]]+)\]/, '[\2](\1)') body.gsub!(/\[(https?[^\s\[\]]+)\s([^\[\]]+)\]/, '[\2](\1)')
body.gsub!(/([^(])(https?[^\s\[\]]+)/, '\1<\2>')
body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1') body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')
body.gsub!(/'''(.+?)'''/, '*\1*') body.gsub!(/'''(.+?)'''/, '*\1*')
body.gsub!(/''(.+?)''/, '_\1_') body.gsub!(/''(.+?)''/, '_\1_')
body.gsub!(/^\s\*/, '*')
body.gsub!(/^\s\d\./, '1.') body.gsub!(/^\s\d\./, '1.')
# custom add-on for pedantic satisfaction # custom add-on for pedantic satisfaction
@ -30,10 +34,10 @@ body.gsub!(/ *(\.){3,}/, '…')
STDOUT.write(body) STDOUT.write(body)
~~~ ~~~
Copiez simplement ce script là où vous le souhaitez, rendez-le exécutable puis Copiez simplement ce script là où vous le souhaitez, rendez-le exécutable puis :
~~~ ~~~{.bash}
$ cat Page.trac | /path/to/trac_to_md > Page.md $ cat Page.trac | trac2md
~~~ ~~~
Quelques remarques : Quelques remarques :