Created
May 20, 2011 17:33
-
-
Save grapswiz/983377 to your computer and use it in GitHub Desktop.
wiki format to html
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
(function(global) { | |
global.onload = function() { | |
ajaxRequest('in.txt', function(input) { | |
var text = ''; | |
input = input.split('\n'); | |
for (var i = 0; i < input.length; i++) { | |
if (input[i] != '') { | |
text += format(input[i]); | |
} | |
} | |
var output = document.getElementById('out'); | |
output.innerHTML = text; | |
}); | |
}; | |
//TODO: <ui>の中に必要分の<li>をまとめる | |
function format(s) { | |
var text = ''; | |
if (s.match(/=== (\w+) ===/)) { | |
text += '<h1>' + RegExp.$1 + '</h1>'; | |
} else if (s.match(/== ((\w|\W)+) ==/)) { | |
text += '<h2>' + RegExp.$1 + '</h2>'; | |
} else if (s.match(/= ((\w|\W)+) =/)) { | |
text += '<h3>' + RegExp.$1 + '</h3>'; | |
} else if (s.match(/\* ((\w|\W)+)/)) { | |
text += '<ui>'; | |
text += '<li>' + RegExp.$1 + '</li>'; | |
text += '</ui>'; | |
} else { | |
text += s; | |
} | |
return text; | |
} | |
function ajaxRequest(url, callback) { | |
var req = new XMLHttpRequest(); | |
req.open('GET', url, true); | |
req.onreadystatechange = function() { | |
if (req.readyState == 4) { | |
if (req.status == 200) { | |
callback(req.responseText); | |
} | |
} | |
}; | |
req.send(null); | |
} | |
})(this); |
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
=== wiki記法をHTMLに整形するツール === | |
* 入力ファイルをwiki記法にしたがってHTMLに整形する |
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
<h1>wiki記法をHTMLに整形するツール</h1> | |
<ui><li>入力ファイルをwiki記法にしたがってHTMLに整形する</li></ui> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment