66import logging
77from fuzzywuzzy import process
88
9- SNIP_PREFIX = "// snip: "
10- SNIP_FILE_PREFIX = "// snip-file: "
11- TAG_PREFIX = "// tag: "
9+ SNIP_PREFIX = "// snip"
10+ SNIP_FILE_PREFIX = "// snip-file"
11+ TAG_PREFIX = "// tag"
1212
1313# The virtual "ref" that represents the current state of the files on disk,
1414# and may not necessarily be stored in the index or in a commit. Uses a
@@ -57,7 +57,7 @@ def find(base_path, extensions):
5757 @property
5858 def cleaned_contents (self ):
5959 """Returns a version of 'text' that has no expanded snippets."""
60- snip_with_code = re .compile ("(//.*snip(\-file)*:.*\n )(\[.*\]\n )*----\n (.*\n )*?----\n " )
60+ snip_with_code = re .compile ("(//.*snip(\-file)*:? .*\n )(\[.*\]\n )*----\n (.*\n )*?----\n " , flags = re . IGNORECASE )
6161 cleaned = re .sub (snip_with_code , r'\1' , self .contents )
6262 return cleaned
6363
@@ -80,19 +80,25 @@ def snippets(self):
8080 # encountered in the document
8181 current_ref = WORKSPACE_REF
8282
83+ tag_regex = re .compile (r"$\/\/\s*tag:?\s*(.*)^" , flags = re .IGNORECASE )
84+ snip_regex = re .compile (r"$\/\/\s*tag:?\s*(.*)^" , flags = re .IGNORECASE )
85+
8386 for line in source_lines :
8487 output_lines .append (line )
8588
8689 # change which tag we're looking at if we hit an instruction to
8790 # do so
88- if line .startswith (TAG_PREFIX ):
89- current_ref = line [len (TAG_PREFIX )+ 1 :].strip ()
91+ tag = tag_regex .match (line )
92+
93+ if tag :
94+ current_ref = tag .groups (1 ).strip ()
9095
9196 # is this a snippet?
92- if line .startswith (SNIP_PREFIX ):
97+ snippet = snip_regex .match (line )
98+ if snippet :
9399
94100 # figure out what tags we're supposed to be using here
95- query_text = line [ len ( SNIP_PREFIX ) + 1 :]
101+ query_text = snippet . groups ( 1 )
96102
97103 # build the tag query from this
98104 query = TagQuery (query_text , ref = current_ref )
0 commit comments