Skip to content

Instantly share code, notes, and snippets.

@grapswiz
Created May 20, 2011 17:33
Show Gist options
  • Save grapswiz/983377 to your computer and use it in GitHub Desktop.
Save grapswiz/983377 to your computer and use it in GitHub Desktop.
wiki format to html
(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);
=== wiki記法をHTMLに整形するツール ===
* 入力ファイルをwiki記法にしたがってHTMLに整形する
<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