Skip to content

Commit eb7407a

Browse files
layout and highlighter improvement
1 parent 5081c44 commit eb7407a

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

components/csharp-viewer.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,51 @@ class CSharpViewer extends HTMLElement {
7676
'orderby', 'group', 'by', 'into', 'on', 'equals', 'ascending', 'descending'
7777
];
7878

79-
// Highlight comments (// and /* */)
80-
code = code.replace(/(\/\/.*?$)/gm, '<span class="cs-comment">$1</span>');
81-
code = code.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="cs-comment">$1</span>');
79+
// Use placeholders to protect already-highlighted content
80+
const protectedSections = [];
81+
let protectIndex = 0;
8282

83-
// Highlight strings
84-
code = code.replace(/("(?:[^"\\]|\\.)*")/g, '<span class="cs-string">$1</span>');
83+
// 1. Protect and highlight comments first (they have highest priority)
84+
code = code.replace(/(\/\/.*?$)/gm, (match) => {
85+
const placeholder = `___PROTECTED_${protectIndex}___`;
86+
protectedSections[protectIndex] = `<span class="cs-comment">${match}</span>`;
87+
protectIndex++;
88+
return placeholder;
89+
});
8590

86-
// Highlight numbers
91+
code = code.replace(/(\/\*[\s\S]*?\*\/)/g, (match) => {
92+
const placeholder = `___PROTECTED_${protectIndex}___`;
93+
protectedSections[protectIndex] = `<span class="cs-comment">${match}</span>`;
94+
protectIndex++;
95+
return placeholder;
96+
});
97+
98+
// 2. Protect and highlight strings
99+
code = code.replace(/("(?:[^"\\]|\\.)*")/g, (match) => {
100+
const placeholder = `___PROTECTED_${protectIndex}___`;
101+
protectedSections[protectIndex] = `<span class="cs-string">${match}</span>`;
102+
protectIndex++;
103+
return placeholder;
104+
});
105+
106+
// 3. Highlight numbers (only outside strings/comments)
87107
code = code.replace(/\b(\d+\.?\d*[fFdDmM]?)\b/g, '<span class="cs-number">$1</span>');
88108

89-
// Highlight keywords
109+
// 4. Highlight keywords (only outside strings/comments)
90110
const keywordPattern = new RegExp(`\\b(${keywords.join('|')})\\b`, 'g');
91111
code = code.replace(keywordPattern, '<span class="cs-keyword">$1</span>');
92112

93-
// Highlight types (PascalCase words)
94-
code = code.replace(/\b([A-Z][a-zA-Z0-9]*(?:&lt;[^&]*&gt;)?)\b/g, '<span class="cs-type">$1</span>');
113+
// 5. Highlight types - PascalCase words (only outside strings/comments)
114+
code = code.replace(/\b([A-Z][a-zA-Z0-9]*(?:&lt;[^&]*&gt;)?)\b(?![^<]*<\/span>)/g, '<span class="cs-type">$1</span>');
95115

96-
// Highlight method calls
116+
// 6. Highlight method calls (only outside strings/comments)
97117
code = code.replace(/\b([a-zA-Z_][a-zA-Z0-9_]*)\s*(?=\()/g, '<span class="cs-method">$1</span>');
98118

119+
// 7. Restore protected sections (comments and strings)
120+
protectedSections.forEach((section, index) => {
121+
code = code.replace(`___PROTECTED_${index}___`, section);
122+
});
123+
99124
return code;
100125
}
101126

index.html

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,18 @@
573573
<i class="bi bi-code-square me-1"></i>Format
574574
</button>
575575
</div>
576-
<div style="flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 0; margin: 0;">
577-
<label class="terminal-label" style="margin: 0;">Source Schema:</label>
578-
<json-editor id="sourceSchemaInput" rows="4" style="flex: 1; min-height: 60px;"></json-editor>
579-
<label class="terminal-label" style="margin: 0;">Destination Schema:</label>
580-
<json-editor id="destSchemaInput" rows="4" style="flex: 1; min-height: 60px;"></json-editor>
576+
<!-- Split layout: Source and Destination side by side -->
577+
<div style="flex: 1; display: flex; flex-direction: row !important; overflow: hidden; padding: 0; margin: 0; gap: 2px; background: #1e1e1e;">
578+
<!-- Left: Source Schema -->
579+
<div style="flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 0; margin: 0; min-width: 0;">
580+
<label class="terminal-label" style="margin: 0; flex-shrink: 0;">Source Schema:</label>
581+
<json-editor id="sourceSchemaInput" rows="4" style="flex: 1; min-height: 60px; width: 100%;"></json-editor>
582+
</div>
583+
<!-- Right: Destination Schema -->
584+
<div style="flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 0; margin: 0; min-width: 0;">
585+
<label class="terminal-label" style="margin: 0; flex-shrink: 0;">Destination Schema:</label>
586+
<json-editor id="destSchemaInput" rows="4" style="flex: 1; min-height: 60px; width: 100%;"></json-editor>
587+
</div>
581588
</div>
582589
</div>
583590

0 commit comments

Comments
 (0)