Skip to content

Commit 4572ae7

Browse files
committed
Final highlighting bugs
1 parent 026b401 commit 4572ae7

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

graph-selector/src/highlight.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,24 @@ describe("highlight", () => {
394394
expect(spacedResult?.token).toBe("attribute");
395395
expect(spacedResult?.match).toBe("[size = 2.439]");
396396
});
397+
398+
test("tokenizes attributes containing URLs", () => {
399+
// Test URL in attribute
400+
const urlResult = testTokenizerRule(
401+
'[src="https://i.ibb.co/N3r6Fv1/Screen-Shot-2023-01-11-at-2-22-31-PM.png"]',
402+
);
403+
expect(urlResult?.token).toBe("attribute");
404+
expect(urlResult?.match).toBe(
405+
'[src="https://i.ibb.co/N3r6Fv1/Screen-Shot-2023-01-11-at-2-22-31-PM.png"]',
406+
);
407+
408+
// Test URL in attribute with leading spaces
409+
const spacedUrlResult = testTokenizerRule(
410+
' [src="https://i.ibb.co/N3r6Fv1/Screen-Shot-2023-01-11-at-2-22-31-PM.png"]',
411+
);
412+
expect(spacedUrlResult?.token).toBe("attribute");
413+
expect(spacedUrlResult?.match).toBe(
414+
' [src="https://i.ibb.co/N3r6Fv1/Screen-Shot-2023-01-11-at-2-22-31-PM.png"]',
415+
);
416+
});
397417
});

graph-selector/src/highlight.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ export function registerHighlighter(monaco: typeof Monaco) {
4242
defaultToken: "string",
4343
tokenizer: {
4444
root: [
45-
// URLs (must come before comment and edge label rules)
46-
[/^\s*https?:\/\/[^\s]+/, "string"],
47-
// \/\/ single-line comment... (but not URLs)
48-
[/^\/\/.*|[^:]\/\/.*/, "comment"],
49-
[/\/\*/, "comment", "@comment"],
45+
// Attributes with quoted values (including URLs), numbers, or words
46+
[/\s*\[\w+\s*=\s*(['"].*?['"]|-?\d*\.?\d+|\w+)\]|\s*\[\w+\]/, "attribute"],
47+
// URLs (must come after attributes but before edge labels)
48+
[/\s*https?:\/\/[^\s]+/, "string"],
5049
// Edge label at start of line (after optional indentation)
51-
[/^\s+[^:\s/][^:]*:/, "type"], // Match edge label but exclude URLs by preventing / after :
50+
[/^\s+[a-zA-Z][\w-]*:/, "type"], // Match edge label starting with letter
5251
// Variable pointers (including leading space)
5352
[/ \([^)]+\)/, "variable"],
5453
[/\([^)]+\)/, "variable"],
5554
// #id and .class combinations (must come before word rule)
5655
[/(#[\w-]+(\.[a-zA-Z][\w-]*)*|\.[a-zA-Z][\w-]*(\.[\w-]+)*)/, "attribute"],
57-
// Attributes with quoted values or numbers
58-
[/\[\w+\s*=\s*(['"][^'"]*['"]|-?\d*\.?\d+|\w+)\]|\[\w+\]/, "attribute"],
56+
// \/\/ single-line comment... (but not URLs)
57+
[/^\/\/.*|[^:]\/\/.*/, "comment"],
58+
[/\/\*/, "comment", "@comment"],
5959
// Escaped characters (must come before other rules)
6060
[/\\[[\](){}<>:#.\/]/, "string"],
6161
// Spaces

0 commit comments

Comments
 (0)