Skip to content

Commit

Permalink
feat(xlf/renderer/xlf-md): em syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
moki committed Oct 14, 2023
1 parent 5027de8 commit 1ccf684
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders xlf to markdown renders em wrapped in <g> tags 1`] = `"Предложение номер *один*."`;
exports[`renders xlf to markdown renders plain text 1`] = `"Sentence about something. Another sentence."`;
exports[`renders xlf to markdown renders strong wrapped in <g> tags 1`] = `"Предложение номер **один**."`;
11 changes: 11 additions & 0 deletions src/xlf/renderer/xlf-md/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class XLFMDRenderer {
tag: this.tag.bind(this),
g: this.g.bind(this),
strong: this.strong.bind(this),
em: this.em.bind(this),
};
}

Expand Down Expand Up @@ -75,6 +76,16 @@ class XLFMDRenderer {

return token.equivText ?? '**';
}

em(token: XLFToken): string {
assert(isXLFTagToken(token));
token as XLFTagToken;
if (!token?.equivText) {
throw new Error(`token: ${token} missing equiv-text`);
}

return token.equivText ?? '*';
}
}

export {XLFMDRenderer};
Expand Down
28 changes: 28 additions & 0 deletions src/xlf/renderer/xlf-md/renderer-inline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,32 @@ describe('renders xlf to markdown', () => {
const rendered = renderer.render(tokens);
expect(rendered).toMatchSnapshot();
});

it('renders em wrapped in <g> tags', () => {
const renderer = new XLFMDRenderer();
const tokens: Array<XLFToken> = [
{type: 'tag', data: 'target', nodeType: 'open'},
{type: 'text', data: 'Предложение номер '},
{
type: 'tag',
data: 'g',
nodeType: 'open',
syntax: 'em',
equivText: '*',
},
{type: 'text', data: 'один'},
{
type: 'tag',
data: 'g',
nodeType: 'close',
syntax: 'em',
equivText: '*',
},
{type: 'text', data: '.'},
{type: 'tag', data: 'target', nodeType: 'close'},
];

const rendered = renderer.render(tokens);
expect(rendered).toMatchSnapshot();
});
});

0 comments on commit 1ccf684

Please sign in to comment.