Ticket #2594: template_whitespace_ticket_2594.diff
File template_whitespace_ticket_2594.diff, 3.3 KB (added by , 15 years ago) |
---|
-
template/__init__.py
90 90 UNKNOWN_SOURCE="<unknown source>" 91 91 92 92 # match a variable or block tag and capture the entire tag, including start/end delimiters 93 tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s)' % (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END), 94 re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END), 95 re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END))) 93 tag_re = re.compile('([\n\r\v\f]+[ \t]*?%s[^\n\r\v\f%s%s]*?%s(?=[ \t]*?[\n\r\v\f]+)|%s.*?%s|%s.*?%s|%s.*?%s)' % ( 94 re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END), re.escape(BLOCK_TAG_END), 95 re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END), 96 re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END), 97 re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END))) 98 # find the command within a block tag 99 block_command_re = re.compile('%s(?P<token_string>.*?)%s' % (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END))) 96 100 97 101 # global dictionary of libraries that have been loaded using get_library 98 102 libraries = {} … … 207 211 self.contents[:20].replace('\n', '')) 208 212 209 213 def split_contents(self): 210 split = [] 214 split = [] 211 215 bits = iter(smart_split(self.contents)) 212 216 for bit in bits: 213 217 # Handle translation-marked template pieces … … 230 234 "Return a list of tokens from a given template_string." 231 235 in_tag = False 232 236 result = [] 233 for bit in tag_re.split(self.template_string): 237 for bit in tag_re.split(self.template_string): 234 238 if bit: 235 239 result.append(self.create_token(bit, in_tag)) 236 240 in_tag = not in_tag … … 241 245 Convert the given token string into a new Token object and return it. 242 246 If in_tag is True, we are processing something that matched a tag, 243 247 otherwise it should be treated as a literal string. 244 """ 248 """ 245 249 if in_tag: 246 250 if token_string.startswith(VARIABLE_TAG_START): 247 251 token = Token(TOKEN_VAR, token_string[len(VARIABLE_TAG_START):-len(VARIABLE_TAG_END)].strip()) 248 elif token_string.startswith(BLOCK_TAG_START): 249 token = Token(TOKEN_BLOCK, token_string[len(BLOCK_TAG_START):-len(BLOCK_TAG_END)].strip()) 252 elif token_string.lstrip().startswith(BLOCK_TAG_START): 253 token_struct = block_command_re.search(token_string) 254 token_string = token_struct.group('token_string') 255 token = Token(TOKEN_BLOCK, token_string.strip()) 250 256 elif token_string.startswith(COMMENT_TAG_START): 251 257 token = Token(TOKEN_COMMENT, '') 252 258 else: … … 984 990 builtins.append(get_library(module_name)) 985 991 986 992 add_to_builtins('django.template.defaulttags') 987 add_to_builtins('django.template.defaultfilters') 993 add_to_builtins('django.template.defaultfilters') 994 No newline at end of file