Skip to content

Commit e740572

Browse files
javier-godoymlopezFC
authored andcommitted
fix: preserve lines commented with show-source
Close #54
1 parent 728f29e commit e740572

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,8 @@ pre[class*="language-"] {
293293
}
294294

295295
return lines.filter(line=>line!==null)
296-
.map(line=>{
297-
let m= line!.match("^(?<spaces>\\s*)//\\s*show-source\\s(?<line>.*)");
298-
return m?m.groups!.spaces+m.groups!.line : line!;
299-
}).filter(line=>
296+
.map(line=>line!)
297+
.filter(line=>
300298
!line.match("//\\s*hide-source(\\s|$)")
301299
&& !line.startsWith('@Route')
302300
&& !line.startsWith('@PageTitle')
@@ -306,7 +304,11 @@ pre[class*="language-"] {
306304
&& line != 'import com.vaadin.flow.router.PageTitle;'
307305
&& line != 'import com.vaadin.flow.router.Route;'
308306
&& line != 'import com.flowingcode.vaadin.addons.demo.DemoSource;'
309-
).join('\n');
307+
).map(line=>{
308+
let m= line!.match("^(?<spaces>\\s*)//\\s*show-source\\s(?<line>.*)");
309+
return m?m.groups!.spaces+m.groups!.line : line;
310+
})
311+
.join('\n');
310312
}
311313

312314
escapeHtml(unsafe: string) {

src/test/java/com/flowingcode/vaadin/addons/demo/it/SourceCodeViewerIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,9 @@ public void testLicenseCleanup() {
5454
assertEquals(expected(), open());
5555
}
5656

57+
@Test
58+
public void testCleanupOverride() {
59+
assertEquals(expected(), open());
60+
}
61+
5762
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import com.flowingcode.vaadin.addons.demo.DemoSource;
2+
import com.vaadin.flow.router.PageTitle;
3+
import com.vaadin.flow.router.Route;
4+
5+
@Route("hide")
6+
//show-source @Route("show")
7+
class MyClass {
8+
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@Route("show")
2+
class MyClass {
3+
4+
}

0 commit comments

Comments
 (0)