Skip to content

Commit

Permalink
feat: support highlighting code in CSS
Browse files Browse the repository at this point in the history
Close #98
  • Loading branch information
javier-godoy committed Jun 26, 2024
1 parent 6dc63a1 commit 4d8c309
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ The `// begin-block` and `// end-block` comments are removed after post-processi
add(other);
```

For highlighting code in CSS, use `/*// begin-block filenameAndId */`

<!-- FROM https://github.com/FlowingCode/CommonsDemo/pull/62 -->
![image](https://github.com/FlowingCode/CommonsDemo/assets/11554739/02063272-029f-4b4b-bd6f-821f2f8a0158)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ pre[class*="language-"] {
//process instructions in element nodes
if (nodes[i].nodeType!=1) continue;

const text = nodes[i].textContent!;
var text = nodes[i].textContent!;

var blockComment = text.match("^/\\*(?<content>(\\*(?!\/)|[^\\*])*)\\*\/");
if (blockComment) text = blockComment.groups!.content;

var m = text.match("^//\\s*begin-block\\s+(\\S+)\\s*");

if (m) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ public MultiSourceDemo() {
div.addClassName("custom-style");
SourceCodeViewer.highlightOnHover(div, "main");
add(div);
// end-block

Button button1 = new Button("Highlight code in AdditionalSources");
SourceCodeViewer.highlightOnClick(button1, "AdditionalSources.java#fragment");
add(button1);
add(new Div(button1));

Button button2 = new Button("Highlight code in CSS");
SourceCodeViewer.highlightOnClick(button2, "multi-source-demo.css#css-fragment");
add(new Div(button2));
// end-block
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*// begin-block css */
.custom-style {
color: red;
}
color: red;
}
/*// end-block */

0 comments on commit 4d8c309

Please sign in to comment.