Last active
October 24, 2016 06:05
-
-
Save yusuiked/740495067cd117461715a41d9c30455d to your computer and use it in GitHub Desktop.
PukiWiki のページファイル名の変換と、Pukiwiki 記法から Markdown 記法へ変換する雑なスクリプト
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
StringBuilder sb = new StringBuilder() | |
new File('wiki.txt').eachLine { line -> | |
// link | |
line = line.replaceAll(/\[\[(.*):(https*:.*)\]\]/, '[$1]($2)') | |
if (line.startsWith('#geshi')) { | |
// code | |
sb << line.replaceFirst(/^#geshi\((.*)\)\s*\{\{$/, '```$1') | |
} else if (line.startsWith('}}')) { | |
sb << line.replace('}}', '```') | |
} else if (line.matches(/^\|.*\|h$/)) { | |
def header = line.substring(0, line.lastIndexOf('h')) | |
def columns = header.split(/\|/) | |
sb << header | |
sb << '\n' | |
sb << '|' | |
columns.length.times { sb << '----|' } | |
} else if (line.startsWith('#')) { | |
// ignore | |
} else if (line.startsWith('>')) { | |
sb << line | |
} else if (line.startsWith(' ')) { | |
sb << line.replaceFirst(/^\s/, ' ') | |
} else if (line.startsWith('*')) { | |
sb << line.replace('*', '#') | |
// add empty line after the header. | |
sb << '\n' | |
} else if (line.startsWith('-')) { | |
sb << line.replace('-', ' *').replaceAll(/^\s+/, '') | |
} else if (line.startsWith('+')) { | |
sb << line.replace('+', ' 1.').replaceAll(/^\s+/, '') | |
} else { | |
sb << line | |
} | |
sb << '\n' | |
} | |
new File('/path/to/file.md').text = sb.toString() |
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
if (!args) { System.err.println 'requires wiki directory path!'; System.exit 1 } | |
files = "ls ${args[0]}".execute().text.split(/\s/) | |
files.each { file -> | |
println "$file =>" | |
println "\t${URLDecoder.decode(file.replaceAll(/([0-9A-Z]{2})/) {"%${it[1]}"})}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment