wiki/HowtoTracToMarkdown.md

43 lines
1.4 KiB
Markdown
Raw Normal View History

2016-11-13 09:51:43 +01:00
---
title: Howto Trac to Markdown
...
Si on souhaite convertir des pages du format Trac vers le format Markdown un petit script peut faciliter la tâche.
~~~{.ruby}
#!/usr/bin/env ruby
## Based on: https://gist.github.com/619537
body = STDIN.read
body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '`\1`')
2016-12-26 22:44:22 +01:00
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}
2016-11-13 09:51:43 +01:00
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)')
2016-12-26 22:44:22 +01:00
body.gsub!(/([^(])(https?[^\s\[\]]+)/, '\1<\2>')
2016-11-13 09:51:43 +01:00
body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')
body.gsub!(/'''(.+?)'''/, '*\1*')
body.gsub!(/''(.+?)''/, '_\1_')
body.gsub!(/^\s\d\./, '1.')
# custom add-on for pedantic satisfaction
body.gsub!(/ *(\.){3,}/, '…')
STDOUT.write(body)
~~~
2016-12-26 22:44:22 +01:00
Copiez simplement ce script là où vous le souhaitez, rendez-le exécutable puis :
2016-11-13 09:51:43 +01:00
2016-12-26 22:44:22 +01:00
~~~{.bash}
$ cat Page.trac | trac2md
2016-11-13 09:51:43 +01:00
~~~
2016-12-26 22:46:38 +01:00
*Note* : le script ne gère pas une conversion parfaite, il faudra relire le document et faire quelques corrections manuelles (titre en "front matter Yaml", etc.). Patches welcome :)