mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
fix parse tags in brackets
This commit is contained in:
@@ -177,14 +177,30 @@ class Tokenizer {
|
|||||||
this.colPos = 0;
|
this.colPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
charOPENBRAKET() {
|
charOPENBRAKET(charCode) {
|
||||||
this.flushWord();
|
const nextCharCode = this.seekChar(1);
|
||||||
this.tagToken = this.createTagToken('');
|
const isNextSpace = nextCharCode === SPACE || nextCharCode === TAB;
|
||||||
|
|
||||||
|
if (isNextSpace) {
|
||||||
|
this.createWord();
|
||||||
|
this.wordToken[Token.VALUE_ID] += getChar(charCode);
|
||||||
|
} else {
|
||||||
|
this.flushWord();
|
||||||
|
|
||||||
|
this.tagToken = this.createTagToken('');
|
||||||
|
}
|
||||||
|
|
||||||
this.nextCol();
|
this.nextCol();
|
||||||
}
|
}
|
||||||
|
|
||||||
charCLOSEBRAKET() {
|
charCLOSEBRAKET(charCode) {
|
||||||
|
const prevCharCode = this.seekChar(-1);
|
||||||
|
const isPrevSpace = prevCharCode === SPACE || prevCharCode === TAB;
|
||||||
|
|
||||||
|
if (isPrevSpace) {
|
||||||
|
this.wordToken[Token.VALUE_ID] += getChar(charCode);
|
||||||
|
}
|
||||||
|
|
||||||
this.nextCol();
|
this.nextCol();
|
||||||
this.flushTag();
|
this.flushTag();
|
||||||
this.flushAttrNames();
|
this.flushAttrNames();
|
||||||
@@ -328,6 +344,8 @@ class Tokenizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Tokenizer('[ [g]G[/g] ]').tokenize()
|
||||||
|
|
||||||
module.exports = Tokenizer;
|
module.exports = Tokenizer;
|
||||||
module.exports.createTokenOfType = createTokenOfType;
|
module.exports.createTokenOfType = createTokenOfType;
|
||||||
module.exports.TYPE = {
|
module.exports.TYPE = {
|
||||||
|
|||||||
@@ -53,6 +53,23 @@ describe('Tokenizer', () => {
|
|||||||
expectOutput(output, tokens);
|
expectOutput(output, tokens);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('tokenize tags in brakets', () => {
|
||||||
|
const input = '[ [h1]G[/h1] ]';
|
||||||
|
const tokens = tokenize(input);
|
||||||
|
|
||||||
|
const output = [
|
||||||
|
[TYPE.WORD, '[', '0', '0'],
|
||||||
|
[TYPE.SPACE, ' ', '1', '0'],
|
||||||
|
[TYPE.TAG, 'h1', '2', '0'],
|
||||||
|
[TYPE.WORD, 'G', '1', '0'],
|
||||||
|
[TYPE.TAG, '/h1', '7', '0'],
|
||||||
|
[TYPE.SPACE, ' ', '12', '0'],
|
||||||
|
[TYPE.WORD, ']', '7', '0'],
|
||||||
|
];
|
||||||
|
|
||||||
|
expectOutput(output, tokens);
|
||||||
|
});
|
||||||
|
|
||||||
test('tokenize tag as param', () => {
|
test('tokenize tag as param', () => {
|
||||||
const input = '[color="#ff0000"]Text[/color]';
|
const input = '[color="#ff0000"]Text[/color]';
|
||||||
const tokens = tokenize(input);
|
const tokens = tokenize(input);
|
||||||
|
|||||||
Reference in New Issue
Block a user