Skip to content

Commit 4d8c309

Browse files
committed
feat: support highlighting code in CSS
Close #98
1 parent 6dc63a1 commit 4d8c309

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ The `// begin-block` and `// end-block` comments are removed after post-processi
183183
add(other);
184184
```
185185

186+
For highlighting code in CSS, use `/*// begin-block filenameAndId */`
187+
186188
<!-- FROM https://github.com/FlowingCode/CommonsDemo/pull/62 -->
187189
![image](https://github.com/FlowingCode/CommonsDemo/assets/11554739/02063272-029f-4b4b-bd6f-821f2f8a0158)
188190

src/main/resources/META-INF/resources/frontend/code-viewer.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,11 @@ pre[class*="language-"] {
416416
//process instructions in element nodes
417417
if (nodes[i].nodeType!=1) continue;
418418

419-
const text = nodes[i].textContent!;
419+
var text = nodes[i].textContent!;
420+
421+
var blockComment = text.match("^/\\*(?<content>(\\*(?!\/)|[^\\*])*)\\*\/");
422+
if (blockComment) text = blockComment.groups!.content;
423+
420424
var m = text.match("^//\\s*begin-block\\s+(\\S+)\\s*");
421425

422426
if (m) {

src/test/java/com/flowingcode/vaadin/addons/demo/MultiSourceDemo.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ public MultiSourceDemo() {
4141
div.addClassName("custom-style");
4242
SourceCodeViewer.highlightOnHover(div, "main");
4343
add(div);
44-
// end-block
4544

4645
Button button1 = new Button("Highlight code in AdditionalSources");
4746
SourceCodeViewer.highlightOnClick(button1, "AdditionalSources.java#fragment");
48-
add(button1);
47+
add(new Div(button1));
48+
49+
Button button2 = new Button("Highlight code in CSS");
50+
SourceCodeViewer.highlightOnClick(button2, "multi-source-demo.css#css-fragment");
51+
add(new Div(button2));
52+
// end-block
4953
}
5054

5155
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*// begin-block css */
12
.custom-style {
2-
color: red;
3-
}
3+
color: red;
4+
}
5+
/*// end-block */

0 commit comments

Comments
 (0)