@@ -66,10 +66,11 @@ class SnippetPreprocessor(Preprocessor):
6666
6767 RE_SNIPPET_SECTION = re .compile (
6868 r'''(?xi)
69- ^.*?
69+ ^(?P<pre>.*?)
70+ (?P<escape>;*)
7071 (?P<inline_marker>-{1,}8<-{1,}[ \t]+)
71- \[[ \t]*(?P<type>start|end)[ \t]*:[ \t]*(?P<name>[a-z][-_0-9a-z]*)[ \t]*\]
72- .*?$
72+ (?P<section> \[[ \t]*(?P<type>start|end)[ \t]*:[ \t]*(?P<name>[a-z][-_0-9a-z]*)[ \t]*\])
73+ (?P<post> .*?) $
7374 '''
7475 )
7576
@@ -103,14 +104,27 @@ def extract_section(self, section, lines):
103104
104105 # Found a snippet section marker with our specified name
105106 m = self .RE_SNIPPET_SECTION .match (l )
106- if m is not None and m .group ('name' ) == section :
107+
108+ # Handle escaped line
109+ if m and start and m .group ('escape' ):
110+ l = (
111+ m .group ('pre' ) + m .group ('escape' ).replace (';' , '' , 1 ) + m .group ('inline_marker' ) +
112+ m .group ('section' ) + m .group ('post' )
113+ )
114+
115+ # Found a section we are looking for.
116+ elif m is not None and m .group ('name' ) == section :
107117
108118 # We found the start
109119 if not start and m .group ('type' ) == 'start' :
110120 start = True
111121 found = True
112122 continue
113123
124+ # Ignore duplicate start
125+ elif start and m .group ('type' ) == 'start' :
126+ continue
127+
114128 # We found the end
115129 elif start and m .group ('type' ) == 'end' :
116130 start = False
@@ -120,6 +134,10 @@ def extract_section(self, section, lines):
120134 else :
121135 break
122136
137+ # Found a section we don't care about, so ignore it.
138+ elif m and start :
139+ continue
140+
123141 # We are currently in a section, so append the line
124142 if start :
125143 new_lines .append (l )
0 commit comments