This repository was archived by the owner on Oct 22, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,10 +76,12 @@ module.exports = class CodeSection {
7676 this . storyPageId = '' ;
7777 this . currentHint = '' ;
7878 this . hints = [ ] ;
79+ this . filters = null ;
7980 }
8081
8182 appendDoc ( doc ) {
8283 doc = doc . replace ( / < ! - - | - - > / gm, '' ) + '\n' ;
84+ doc = this . parseFilters ( doc ) ;
8385 this . extractHeadings ( doc ) ;
8486 this . doc_ += doc ;
8587 this . cachedMarkedDoc = false ;
@@ -238,6 +240,18 @@ module.exports = class CodeSection {
238240 return lines . slice ( 1 , lines . length - 1 ) . join ( '\n' ) ;
239241 }
240242
243+ parseFilters ( line ) {
244+ const filterMatch = line . match ( / @ f i l t e r \( ( [ ^ ) ] + ) \) / ) ;
245+ if ( ! filterMatch ) {
246+ return line ;
247+ }
248+ if ( this . filters ) {
249+ throw new Error ( 'Multiple @filter annotations found in section' ) ;
250+ }
251+ this . filters = filterMatch [ 1 ] . split ( ',' ) . map ( f => f . trim ( ) ) ;
252+ return line . replace ( filterMatch [ 0 ] , '' ) ;
253+ }
254+
241255 extractHeadings ( line ) {
242256 const matches = line . match ( / ^ \s * # + \s * ( .+ ) $ / m) ;
243257 if ( ! matches ) {
Original file line number Diff line number Diff line change @@ -84,6 +84,13 @@ describe("CodeSection", function() {
8484 expect ( section . doc ) . toEqual ( "\nhello\n\n\nworld\n\n" ) ;
8585 } ) ;
8686
87+ it ( "parses filters" , function ( ) {
88+ section . appendDoc ( "<!--hello" ) ;
89+ section . appendDoc ( "world! @filter(websites, email)-->" ) ;
90+ expect ( section . doc ) . toEqual ( "hello\nworld! \n" ) ;
91+ expect ( section . filters ) . toEqual ( [ "websites" , "email" ] ) ;
92+ } ) ;
93+
8794 } ) ;
8895 describe ( 'hide columns if code section' , function ( ) {
8996 /*
You can’t perform that action at this time.
0 commit comments