forked from tisba/couchdocs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of MoinMoin2Markdown transformation
This is going to be a 80/20 solution for the migration of the CouchDB wiki pages from the MoinMoin-Syntax to Markdown.
- Loading branch information
Sebastian Cohnen
committed
Mar 26, 2010
1 parent
cafd2dd
commit e6e7d32
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,73 @@ | |||
require "rubygems" | |||
|
|||
input = IO.readlines('../wiki/HTTP_database_API.mm','').to_s | |||
|
|||
def substitute_pattern_in_string_with(pattern, string) | |||
string.scan(pattern).flatten.inject({}) do |acc, matched| | |||
acc[matched] = yield matched | |||
acc | |||
end.each do |matched, substitute| | |||
string.gsub!(matched, substitute) | |||
end | |||
|
|||
return string | |||
end | |||
|
|||
transformations = [ | |||
{ :regexp => /=+\s*?$/, :replacement => '' }, # headlines | |||
|
|||
# { :regexp => /^(?:(\{\{\{)|(\}\}\}))\s*?$/,:replacement => '....' }, # blocks (extra line) | |||
{ :regexp => /\{\{\{(.*?)\}\}\}/, :replacement => '`\1`' }, # blocks (inline) | |||
|
|||
{ :regexp => /'''([^']+)'''/, :replacement => '**\1**' }, # bold | |||
{ :regexp => /''([^']+)''/, :replacement => '*\1*' }, # italic | |||
|
|||
{ :regexp => /_\_(\S)/, :replacement => '_\_\1' }, # escaping (italic) | |||
|
|||
{ :regexp => /<<TableOfContents\(.\)>>/, :replacement => '' } # drop some stuff | |||
] | |||
|
|||
# do the basic stuff | |||
output = transformations.inject(input) do |txt, pattern| | |||
txt.gsub(pattern[:regexp], pattern[:replacement]) | |||
end | |||
|
|||
# transform headlines | |||
output = substitute_pattern_in_string_with(/^=+/, output) do |matched_string| | |||
"#" * matched_string.length | |||
end | |||
|
|||
# doing blocks | |||
output = substitute_pattern_in_string_with(/\{\{\{.*?\}\}\}/m, output) do |matched_block| | |||
block = matched_block.split("\n") | |||
block.shift | |||
block.pop | |||
"\n" << block.each.inject("") do |acc, line| | |||
acc << " " << line << "\n" | |||
end | |||
|
|||
end | |||
|
|||
puts output | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|