Skip to content

Commit 2b0da87

Browse files
authored
Merge pull request #13 from nteract/carriage
Escape carriage symbol
2 parents 25df49f + ec9bd18 commit 2b0da87

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"author": "Kyle Kelley <[email protected]>",
2626
"license": "MPL-2.0",
2727
"dependencies": {
28-
"anser": "^1.1.0"
28+
"anser": "^1.1.0",
29+
"escape-carriage": "^1.0.1"
2930
},
3031
"peerDependencies": {
3132
"react": "^0.14.0 || ^15.0.0-0"

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const React = require('react');
22
const Anser = require('anser');
3+
const escapeCarriageReturn = require('escape-carriage');
34

45
/**
56
* ansiToJson
@@ -11,13 +12,13 @@ const Anser = require('anser');
1112
* @return {Array} The parsed input.
1213
*/
1314
function ansiToJSON(input) {
15+
input = escapeCarriageReturn(input);
1416
return Anser.ansiToJson(input, {
1517
json: true,
1618
remove_empty: true,
1719
});
1820
}
1921

20-
2122
function ansiJSONtoStyleBundle(ansiBundle) {
2223
const style = {};
2324
if (ansiBundle.bg) {

test/index-spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ describe('Ansi', () => {
2727
expect(el.text()).to.equal('hello world');
2828
expect(el.html()).to.equal('<code><span>hello </span><span style="color:rgb(0, 187, 0);">wo</span><span style="background-color:rgb(187, 187, 0);color:rgb(0, 187, 0);">rl</span><span>d</span></code>');
2929
});
30+
31+
it('can handle carrigage symbol', () => {
32+
const el = enzyme.shallow(React.createElement(Ansi, null, 'this sentence\rthat\nwill make you pause'));
33+
expect(el).to.not.be.null;
34+
expect(el.text()).to.equal('that sentence\nwill make you pause');
35+
});
3036
});

0 commit comments

Comments
 (0)