Skip to content

Commit

Permalink
feat(xlf/renderer/xlf-md): code syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
moki committed Oct 17, 2023
1 parent b81b410 commit 16a4187
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/xlf/renderer/xlf-md/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class XLFMDRenderer {
s: this.s.bind(this),
sup: this.sup.bind(this),
samp: this.samp.bind(this),
x: this.x.bind(this),
code: this.code.bind(this),
};
}

Expand Down Expand Up @@ -122,6 +124,32 @@ class XLFMDRenderer {

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

x(token: XLFToken): string {
assert(isXLFTagToken(token));
token as XLFTagToken;

const syntax = token.syntax;
if (!syntax?.length) {
throw new Error("can't render g tag without syntax");
}

const handler = this.rules[syntax];
if (!handler) {
throw new Error(`syntax ${syntax} not implemented`);
}

return handler(token);
}

code(token: XLFToken): string {
assert(isXLFTagToken(token));
token as XLFTagToken;

assert(token.equivText?.length, 'x supposed to wrap original markup inside equiv-text');

return token.equivText;
}
}

export {XLFMDRenderer};
Expand Down

0 comments on commit 16a4187

Please sign in to comment.