textToHtmlTokenizer.ts ×11

Frontier kind: Code frontier

unlabeled · c_e58efe71612f

3 tests · 39255 LOC · 240 files · introduces 0 tests · 71 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges71 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
4570 ranges39255 lines · 240 files · Browse complete extent
All tests (intent)
3 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

3 files ranked by introduced lines: 71 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/languages/textToHtmlTokenizer.ts 55 introduced LOC · 11 ranges

Open complete file

32
33 export function tokenizeLineToHTML(text: string, viewLineTokens: IViewLineTokens, colorMap: string[], startOffset: number, endOffset: number, tabSize: number, useNbsp: boolean): string {
34 > let result = `<div>`; textToHtmlTokenizer.ts
35 > let charIndex = 0;
36 > let width = 0;
37 >
38 > let prevIsSpace = true;
39 >
40 > for (let tokenIndex = 0, tokenCount = viewLineTokens.getCount(); tokenIndex < tokenCount; tokenIndex++) {
41 > const tokenEndIndex = viewLineTokens.getEndOffset(tokenIndex);
42 > let partContent = '';
43 >
44 > for (; charIndex < tokenEndIndex && charIndex < endOffset; charIndex++) {
45 > const charCode = text.charCodeAt(charIndex);
46 > const isTab = charCode === CharCode.Tab;
47 >
48 > width += strings.isFullWidthCharacter(charCode) ? 2 : (isTab ? 0 : 1);
49 >
50 > if (charIndex < startOffset) {
51 if (isTab) {
52 const remainder = width % tabSize;
55 continue;
56 }
58 > switch (charCode) {
59 > case CharCode.Tab: {
60 const remainder = width % tabSize;
61 const insertSpacesCount = remainder === 0 ? tabSize : tabSize - remainder;
74 break;
75 }
76 > case CharCode.LessThan: textToHtmlTokenizer.ts
77 partContent += '&lt;';
78 prevIsSpace = false;
79 break;
81 > case CharCode.GreaterThan:
82 partContent += '&gt;';
83 prevIsSpace = false;
84 break;
86 > case CharCode.Ampersand:
87 partContent += '&amp;';
88 prevIsSpace = false;
89 break;
91 > case CharCode.Null:
92 partContent += '&#00;';
93 prevIsSpace = false;
94 break;
96 > case CharCode.UTF8_BOM:
97 > case CharCode.LINE_SEPARATOR:
98 > case CharCode.PARAGRAPH_SEPARATOR:
99 > case CharCode.NEXT_LINE:
100 partContent += '\ufffd';
101 prevIsSpace = false;
102 break;
104 > case CharCode.CarriageReturn:
105 // zero width space, because carriage return would introduce a line break
106 partContent += '&#8203';
107 prevIsSpace = false;
108 break;
110 > case CharCode.Space:
111 if (useNbsp && prevIsSpace) {
112 partContent += '&#160;';
117 }
118 break;
120 > default:
121 > partContent += String.fromCharCode(charCode);
122 > prevIsSpace = false;
123 > }
124 > }
125 >
126 > if (tokenEndIndex <= startOffset) {
127 continue;
128 }
130 > result += `<span style="${viewLineTokens.getInlineStyle(tokenIndex, colorMap)}">${partContent}</span>`;
131 >
132 > if (tokenEndIndex > endOffset || charIndex >= endOffset || startOffset >= endOffset) {
133 > break;
134 > }
135 > }
136 >
137 > result += `</div>`;
138 > return result;
139 > }
140
141 export function _tokenizeToString(text: string, languageIdCodec: ILanguageIdCodec, tokenizationSupport: IReducedTokenizationSupport): string {
src/vs/editor/common/encodedTokenAttributes.ts 12 introduced LOC · 6 ranges

Open complete file

145
146 public static getInlineStyleFromMetadata(metadata: number, colorMap: string[]): string {
147 > const foreground = this.getForeground(metadata); encodedTokenAttributes.ts
148 > const fontStyle = this.getFontStyle(metadata);
149 >
150 > let result = `color: ${colorMap[foreground]};`;
151 > if (fontStyle & FontStyle.Italic) {
152 result += 'font-style: italic;';
153 }
154 > if (fontStyle & FontStyle.Bold) { encodedTokenAttributes.ts
155 result += 'font-weight: bold;';
156 }
157 > let textDecoration = ''; encodedTokenAttributes.ts
158 > if (fontStyle & FontStyle.Underline) {
159 textDecoration += ' underline';
160 }
161 > if (fontStyle & FontStyle.Strikethrough) { encodedTokenAttributes.ts
162 textDecoration += ' line-through';
163 }
164 > if (textDecoration) { encodedTokenAttributes.ts
165 result += `text-decoration:${textDecoration};`;
166
167 }
168 > return result; encodedTokenAttributes.ts
169 > }
170
171 public static getPresentationFromMetadata(metadata: number): ITokenPresentation {
src/vs/editor/test/common/core/testLineToken.ts 4 introduced LOC · 2 ranges

Open complete file

37
38 public getInlineStyle(colorMap: string[]): string {
39 > return TokenMetadata.getInlineStyleFromMetadata(this._metadata, colorMap); testLineToken.ts
40 > }
41
42 public getPresentation(): ITokenPresentation {
102
103 public getInlineStyle(tokenIndex: number, colorMap: string[]): string {
104 > return this._actual[tokenIndex].getInlineStyle(colorMap); testLineToken.ts
105 > }
106
107 public getPresentation(tokenIndex: number): ITokenPresentation {