本文整理汇总了TypeScript中vs/editor/common/modes.ITokenizationSupport.tokenize方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ITokenizationSupport.tokenize方法的具体用法?TypeScript ITokenizationSupport.tokenize怎么用?TypeScript ITokenizationSupport.tokenize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vs/editor/common/modes.ITokenizationSupport
的用法示例。
在下文中一共展示了ITokenizationSupport.tokenize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _actualColorize
function _actualColorize(lines: string[], tabSize: number, tokenizationSupport: ITokenizationSupport): string {
let html: string[] = [];
let state = tokenizationSupport.getInitialState();
for (let i = 0, length = lines.length; i < length; i++) {
let line = lines[i];
let tokenizeResult = tokenizationSupport.tokenize(line, state);
let renderResult = renderLine(new RenderLineInput(
line,
tabSize,
0,
-1,
'none',
false,
new LineParts(tokenizeResult.tokens.map(t => new ViewLineToken(t.startIndex, t.type)), line.length + 1)
));
html = html.concat(renderResult.output);
html.push('<br/>');
state = tokenizeResult.endState;
}
return html.join('');
}
示例2: _tokenizeLine
function _tokenizeLine(line: string, tokenizationSupport:ITokenizationSupport, emitToken: IEmitTokenFunc, startState: IState): IState {
var tokenized = tokenizationSupport.tokenize(line, startState),
endState = tokenized.endState,
tokens = tokenized.tokens,
offset = 0,
tokenText: string;
// For each token inject spans with proper class names based on token type
for (var j = 0; j < tokens.length; j++) {
var token = tokens[j];
// Tokens only provide a startIndex from where they are valid from. As such, we need to
// look ahead the value of the token by advancing until the next tokens start inex or the
// end of the line.
if (j < tokens.length - 1) {
tokenText = line.substring(offset, tokens[j + 1].startIndex);
offset = tokens[j + 1].startIndex;
} else {
tokenText = line.substr(offset);
}
var className = 'token';
var safeType = token.type.replace(/[^a-z0-9\-]/gi, ' ');
if (safeType.length > 0) {
className += ' ' + safeType;
}
emitToken(className, tokenText);
}
return endState;
}