Ticket #8652: django-multiline-tags-with-no-raw-r8662.diff

File django-multiline-tags-with-no-raw-r8662.diff, 2.1 KB (added by Michael Manfre <mmanfre@…>, 16 years ago)

Patch to add multiline tag support and escape tag syntax

  • django/template/__init__.py

     
    7979COMMENT_TAG_END = '#}'
    8080SINGLE_BRACE_START = '{'
    8181SINGLE_BRACE_END = '}'
     82RAW_TAG_START = '{$'
     83RAW_TAG_END = '$}'
    8284
    8385ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.'
    8486
     
    8789UNKNOWN_SOURCE="&lt;unknown source&gt;"
    8890
    8991# match a variable or block tag and capture the entire tag, including start/end delimiters
    90 tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s)' % (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END),
     92tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s)' % (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END),
    9193                                          re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END),
    92                                           re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END)))
     94                                          re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END),
     95                                          re.escape(RAW_TAG_START), re.escape(RAW_TAG_END)), re.S)
    9396
    9497# global dictionary of libraries that have been loaded using get_library
    9598libraries = {}
     
    221224        otherwise it should be treated as a literal string.
    222225        """
    223226        if in_tag:
    224             if token_string.startswith(VARIABLE_TAG_START):
     227            if token_string.startswith(RAW_TAG_START):
     228                token = Token(TOKEN_TEXT, token_string[len(RAW_TAG_START):-len(RAW_TAG_END)].strip())
     229            elif token_string.startswith(VARIABLE_TAG_START):
    225230                token = Token(TOKEN_VAR, token_string[len(VARIABLE_TAG_START):-len(VARIABLE_TAG_END)].strip())
    226231            elif token_string.startswith(BLOCK_TAG_START):
    227232                token = Token(TOKEN_BLOCK, token_string[len(BLOCK_TAG_START):-len(BLOCK_TAG_END)].strip())
     
    229234                token = Token(TOKEN_COMMENT, '')
    230235        else:
    231236            token = Token(TOKEN_TEXT, token_string)
     237
    232238        return token
    233239
    234240class Parser(object):
Back to Top