html2wiki

Last-modified: 2013-06-19 (水) 15:46:51

htmlのtableをwiki文法に変換。
テキストファイルに保存し、拡張子を.htmlに変換してブラウザで開くと使える。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
(function ($, undefined) {
	'use strict';
	var resizeTextarea = function (textarea) {
		var rows = 0;
		var cols = 0;
		$.each($(textarea).val().split('\n'), function () {
			++rows;
			cols = Math.max(cols, this.length);
		});
		$(textarea).attr({'rows': rows, 'cols': cols})
	}
	setInterval(function () {
		$('textarea[name="html"]').each(function () {
			resizeTextarea(this);
			var value = '';
			$('<div />').html(this.value).find('table').each(function () {
				$(this).find('tr').each(function () {
					value += '|';
					$(this).find('th, td').each(function () {
						value += $(this).text() + '|';
					});
					value += '\n';
				});
				value += '\n';
			});
			resizeTextarea($('textarea[name="wiki"]').val(value));
		});
	}, 1);
})(jQuery);
</script>
<body>
<div style="float: left"><textarea wrap="off" name="html"></textarea></div>
<div style="float: left"><textarea wrap="off" readonly name="wiki"></textarea></div>
</body>
</html>