Created
September 8, 2012 10:28
-
-
Save tiye/3673285 to your computer and use it in GitHub Desktop.
bad markHTML
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
<a> | |
<a> | |
<a> | |
<a> | |
<a> | |
<a> | |
<a> | |
<a> | |
<a> | |
<a> | |
``` | |
<a> | |
<a> | |
```` | |
<a> | |
<a> | |
``` | |
<a> | |
``` |
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
var backquote, indented, markLine; | |
indented = function(line) { | |
return line.slice(0, 4) === ' '; | |
}; | |
backquote = function(line) { | |
return line.slice(0, 3) === '```'; | |
}; | |
markLine = function(line) { | |
if (line[0] === '>') { | |
return mark_line(line.slice(1)); | |
} else { | |
return line.replace(/</g, '<').replace(/>/g, '>').replace(/\s/g, ' '); | |
} | |
}; | |
exports.html = function(str) { | |
var isQuote, isText, list; | |
isText = true; | |
isQuote = false; | |
list = []; | |
str.split('\n').forEach(function(line) { | |
var ret; | |
if (indented(line)){isText = false }else{isText = true}; | |
if (backquote(line)) isQuote = !isQuote; | |
ret = isText && (!isQuote) ? markLine(line) : line; | |
return list.push(ret); | |
}); | |
return list.join('\n'); | |
}; |
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
html = require('./markHTML').html | |
fs = require 'fs' | |
raw = fs.readFileSync 'file.txt', 'utf8' | |
out = html raw | |
list_a = raw.split '\n' | |
list_b = out.split '\n' | |
len = list_b.length | |
show = console.log | |
[0...len].forEach (i) -> | |
show i, list_a[i] | |
show i, list_b[i] | |
show '\n' |
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
➤➤ coffee t.coffee | |
0 '' | |
0 '' | |
1 '<a>' | |
1 '<a>' | |
2 ' <a>' | |
2 ' <a>' | |
3 '<a>' | |
3 '<a>' | |
4 ' <a>' | |
4 ' <a>' | |
5 ' <a>' | |
5 ' <a>' | |
6 ' <a>' | |
6 ' <a>' | |
7 ' <a>' | |
7 ' <a>' | |
8 ' <a>' | |
8 ' <a>' | |
9 ' <a>' | |
9 ' <a>' | |
10 '<a>' | |
10 '<a>' | |
11 '``` ' | |
11 '``` ' | |
12 '<a>' | |
12 '<a>' | |
13 ' <a>' | |
13 ' <a>' | |
14 '````' | |
14 '````' | |
15 ' <a>' | |
15 ' <a>' | |
16 '<a>' | |
16 '<a>' | |
17 '```' | |
17 '```' | |
18 '<a>' | |
18 '<a>' | |
19 '```' | |
19 '```' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment