Skip to content

Commit cf9a068

Browse files
committed
Correctly process Unix redirect characters
1 parent 0127e74 commit cf9a068

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/parser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
var _ = require('lodash');
22
var marked = require('marked');
3-
var unhtml = require('unhtml');
3+
var S = require('string');
44

55
var allElements = [
66
'blockquote', 'html', 'strong', 'em', 'br', 'del',
77
'heading', 'hr', 'image', 'link', 'list', 'listitem',
88
'paragraph', 'strikethrough', 'table', 'tablecell', 'tablerow'
99
];
1010

11+
function unhtml(text){
12+
return S(text).unescapeHTML().stripTags().s;
13+
}
14+
1115
exports.parse = function(markdown) {
1216

1317
var page = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"ms": "~0.6.2",
4242
"request": "~2.44.0",
4343
"rimraf": "~2.2.6",
44-
"unhtml": "~0.1.0",
44+
"string": "^3.3.1",
4545
"unzip2": "^0.2.5",
4646
"wrench": "~1.5.8"
4747
},

test/parser.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,28 @@ describe('Parser', function() {
112112
page.examples[1].description.should.eql('example 2, see inline_cmd2 for details');
113113
});
114114

115+
it('should parse code examples with unix redirects ">", "<", ">>" and "<<<"', function() {
116+
var page = parser.parse(
117+
'\n- Concatenate several files into the target file.' +
118+
'\n' +
119+
'\n`cat {{file1}} {{file2}} > {{target-file}}`' +
120+
'\n' +
121+
'\n- Concatenate several files into the target file.' +
122+
'\n' +
123+
'\n`wc -l < {{users-file}}`' +
124+
'\n' +
125+
'\n- Output one file into the target file.' +
126+
'\n' +
127+
'\n`cat {{file}} >> {{target-file}}`' +
128+
'\n' +
129+
'\n- Calculate the result of expression' +
130+
'\n' +
131+
'\n`bc <<< "1 + 1"`'
132+
);
133+
page.examples[0].code.should.eql('cat {{file1}} {{file2}} > {{target-file}}');
134+
page.examples[1].code.should.eql('wc -l < {{users-file}}');
135+
page.examples[2].code.should.eql('cat {{file}} >> {{target-file}}');
136+
page.examples[3].code.should.eql('bc <<< "1 + 1"');
137+
});
138+
115139
});

0 commit comments

Comments
 (0)