2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-17 19:21:20 +03:00

feat(parse): allow tags to be escaped with backslash (#17)

* feat(parse): allow tags to be escaped with backslash

adds additional option `enableEscapeTags` to `parse` and `createLexer` that
when true will parse openTag and closeTag as WORD (rather than TAG) when
proceeded with backslash
This commit is contained in:
David Ferguson
2019-06-17 20:29:10 +01:00
committed by Nikolay Kostyurin
parent 7e25c45c83
commit c4f78c1230
4 changed files with 46 additions and 2 deletions
+17
View File
@@ -288,6 +288,23 @@ describe('lexer', () => {
expectOutput(output, tokens);
});
test('escaped tag', () => {
const tokenizeEscape = input => (createLexer(input, {
enableEscapeTags: true
}).tokenize());
const input = '\\[b\\]test\\[';
const tokens = tokenizeEscape(input);
const output = [
[TYPE.WORD, '[', '0', '0'],
[TYPE.WORD, 'b', '0', '0'],
[TYPE.WORD, ']', '0', '0'],
[TYPE.WORD, 'test', '0', '0'],
[TYPE.WORD, '[', '0', '0'],
];
expectOutput(output, tokens);
});
describe('html', () => {
const tokenizeHTML = input => createLexer(input, { openTag: '<', closeTag: '>' }).tokenize();
+16
View File
@@ -183,5 +183,21 @@ describe('Parser', () => {
}
]);
});
test('parse escaped tags tags', () => {
const ast = parse('\\[b\\]test\\[/b\\]', {
enableEscapeTags: true
});
expectOutput(ast, [
'[',
'b',
']',
'test',
'[',
'/b',
']',
]);
});
});
});