File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
main/resources/META-INF/resources/frontend
test/java/com/flowingcode/vaadin/addons/demo Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,7 @@ pre[class*="language-"] {
197197 var code = self . querySelector ( "code" ) as HTMLElement ;
198198 var text = self . removeLicense ( this . responseText ) ;
199199 code . setAttribute ( "class" , "language-" + language ) ;
200- code . innerHTML = self . escapeHtml ( text ) ;
200+ code . innerHTML = self . escapeHtml ( self . cleanupCode ( text ) ) ;
201201
202202 ( window as any ) . Prism . highlightAllUnder ( self ) ;
203203 self . __license . reverse ( ) . forEach ( e => self . querySelector ( 'pre code' ) ?. prepend ( e ) ) ;
@@ -243,6 +243,19 @@ pre[class*="language-"] {
243243 return text ;
244244 }
245245
246+ cleanupCode ( text : string ) : string {
247+ return text . split ( '\n' ) . filter ( line =>
248+ ! line . match ( "//\\s*hide-source(\\s|$)" )
249+ && ! line . startsWith ( '@Route' )
250+ && ! line . startsWith ( '@PageTitle' )
251+ && ! line . startsWith ( '@DemoSource' )
252+ && ! line . startsWith ( 'package ' )
253+ && line != 'import com.vaadin.flow.router.PageTitle;'
254+ && line != 'import com.vaadin.flow.router.Route;'
255+ && line != 'import com.flowingcode.vaadin.addons.demo.DemoSource;'
256+ ) . join ( '\n' ) ;
257+ }
258+
246259 escapeHtml ( unsafe : string ) {
247260 return unsafe
248261 . replace ( / & / g, "&" )
Original file line number Diff line number Diff line change @@ -31,5 +31,6 @@ public class SampleDemoDefault extends Div {
3131
3232 public SampleDemoDefault () {
3333 add (new Span ("Demo component with defaulted @DemoSource annotation" ));
34+ this .getClass (); // hide-source (this line will not be displayed in the code snippet)
3435 }
3536}
You can’t perform that action at this time.
0 commit comments