Skip to content

Commit e63e68f

Browse files
committed
fix: ensure first \r is not ignored with different styles
close #20
1 parent 2420182 commit e63e68f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/decompiler.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ export function decompileText(dia, style) {
7575
.map((slice, idx) => {
7676
const sliceCopy = JSON.parse(JSON.stringify(slice));
7777
const tag = {};
78-
if (idx) {
78+
if (idx || slice.style !== dia.style) {
7979
tag.r = slice.style === dia.style ? '' : slice.style;
80-
} else {
80+
}
81+
if (!idx) {
8182
if (style.Alignment !== dia.alignment) {
8283
tag.an = dia.alignment;
8384
}

test/decompiler.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ describe('ASS decompiler', () => {
130130
describe('text decompiler', () => {
131131
it('should put \\r to the beginning of tags', () => {
132132
expect(decompileText({
133+
style: 'Default',
133134
alignment: 1,
134135
slices: [{
135136
style: 'Default',
@@ -148,5 +149,37 @@ describe('ASS decompiler', () => {
148149
Alignment: 1,
149150
})).to.equal('{\\t(0,1000,1,\\1c&HFF&)}Hello{\\rNondefault\\t(1000,2000,1,\\1c&HFFFF&)}World');
150151
});
152+
153+
it('should not ignore the first \\r with different style', () => {
154+
expect(decompileText({
155+
style: 'Base',
156+
slices: [
157+
{
158+
style: 'Base',
159+
fragments: [],
160+
},
161+
{
162+
style: 'Highlight',
163+
fragments: [
164+
{
165+
tag: {},
166+
text: 'Maine',
167+
drawing: null,
168+
},
169+
],
170+
},
171+
{
172+
style: 'Base',
173+
fragments: [
174+
{
175+
tag: {},
176+
text: ' apne',
177+
drawing: null,
178+
},
179+
],
180+
},
181+
],
182+
}, {})).to.equal('{\\rHighlight}Maine{\\r} apne');
183+
});
151184
});
152185
});

0 commit comments

Comments
 (0)