rtf-stream-parser
Version:
Stream Transform class to tokenize RTF, and another to de-encapsulate text or HTML
37 lines (36 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleGroupState = void 0;
const allTokenhandler = (global, token) => {
if (global._done) {
if (token.type === 3 && token.data.length === 1 && token.data[0] === 0) {
}
else {
global._options.warn('Additional tokens after final closing bracket');
}
return true;
}
};
const groupTokenHandlers = {
[0]: global => {
const oldState = global._state;
const newState = Object.create(oldState);
++newState.groupDepth;
global._state = newState;
},
[1]: global => {
global._state = Object.getPrototypeOf(global._state);
if (global._state === global._rootState) {
global._done = true;
}
},
};
exports.handleGroupState = {
allTokenHandler: allTokenhandler,
tokenHandlers: groupTokenHandlers,
preStreamFlushHandler: global => {
if (global._state !== global._rootState) {
global._options.warn('Not enough matching closing brackets');
}
}
};