Ajout de HowtoTracToMarkdown
This commit is contained in:
parent
fa16c7eba1
commit
1ac8963e82
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
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`')
|
||||
body.gsub!(/\{\{\{(.+?)\}\}\}/m){|m| m.each_line.map{|x| "\t#{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!(/\[(https?[^\s\[\]]+)\s([^\[\]]+)\]/, '[\2](\1)')
|
||||
body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')
|
||||
body.gsub!(/'''(.+?)'''/, '*\1*')
|
||||
body.gsub!(/''(.+?)''/, '_\1_')
|
||||
body.gsub!(/^\s\*/, '*')
|
||||
body.gsub!(/^\s\d\./, '1.')
|
||||
|
||||
# custom add-on for pedantic satisfaction
|
||||
body.gsub!(/ *(\.){3,}/, '…')
|
||||
|
||||
STDOUT.write(body)
|
||||
~~~
|
||||
|
||||
Copiez simplement ce script là où vous le souhaitez, rendez-le exécutable puis
|
||||
|
||||
~~~
|
||||
$ cat Page.trac | /path/to/trac_to_md > Page.md
|
||||
~~~
|
||||
|
||||
Quelques remarques :
|
||||
|
||||
* le script ne gère pas la conversion du titre en "front matter Yaml"
|
||||
* le script ne transforme pas les blocs indentés en bloc de code (`~~~`)
|
Loading…
Reference in New Issue