From 5c522536464ef1a85e3a990995d6294950ac8270 Mon Sep 17 00:00:00 2001 From: gcolpart Date: Mon, 26 Dec 2016 22:44:22 +0100 Subject: [PATCH] =?UTF-8?q?quelques=20am=C3=A9liorations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HowtoTracToMarkdown.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/HowtoTracToMarkdown.md b/HowtoTracToMarkdown.md index 07d7ff30..5b780c20 100644 --- a/HowtoTracToMarkdown.md +++ b/HowtoTracToMarkdown.md @@ -11,17 +11,21 @@ Si on souhaite convertir des pages du format Trac vers le format Markdown un pet body = STDIN.read 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!(/\[(https?[^\s\[\]]+)\s([^\[\]]+)\]/, '[\2](\1)') +body.gsub!(/([^(])(https?[^\s\[\]]+)/, '\1<\2>') 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 @@ -30,10 +34,10 @@ body.gsub!(/ *(\.){3,}/, '…') 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 : -~~~ -$ cat Page.trac | /path/to/trac_to_md > Page.md +~~~{.bash} +$ cat Page.trac | trac2md ~~~ Quelques remarques :