本文整理匯總了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;
}