Skip to content

Commit bcb0238

Browse files
committed
feat: add support for show-source
Close #42
1 parent fe1429c commit bcb0238

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ pre[class*="language-"] {
244244
}
245245

246246
cleanupCode(text: string) : string {
247-
return text.split('\n').filter(line=>
247+
return text.split('\n').map(line=>{
248+
let m= line!.match("^(?<spaces>\\s*)//\\s*show-source\\s(?<line>.*)");
249+
return m?m.groups!.spaces+m.groups!.line : line!;
250+
}).filter(line=>
248251
!line.match("//\\s*hide-source(\\s|$)")
249252
&& !line.startsWith('@Route')
250253
&& !line.startsWith('@PageTitle')

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class SampleDemoDefault extends Div {
3131

3232
public SampleDemoDefault() {
3333
add(new Span("Demo component with defaulted @DemoSource annotation"));
34+
// show-source System.out.println("this line will be displayed in the code snippet");
3435
this.getClass(); // hide-source (this line will not be displayed in the code snippet)
3536
}
3637
}

0 commit comments

Comments
 (0)