Add Django and html singleton tags support to pretty print.

In this commit we are modifying pretty print tool to support
Django and html singleton tags. For Addition of html singleton
tags template parser was modified to emit psudeo
html singleton end tags to accompany html singleton tags and
token class was updated to have line_span field.
This commit is contained in:
adnrs96
2017-02-17 00:55:53 +05:30
committed by Tim Abbott
parent 1458d0d3a2
commit 3acf8b050d
3 changed files with 107 additions and 34 deletions

View File

@@ -27,13 +27,14 @@ class TokenizerState(object):
self.col = 1
class Token(object):
def __init__(self, kind, s, tag, line, col):
# type: (str, str, str, int, int) -> None
def __init__(self, kind, s, tag, line, col, line_span):
# type: (str, str, str, int, int, int) -> None
self.kind = kind
self.s = s
self.tag = tag
self.line = line
self.col = col
self.line_span = line_span
def tokenize(text):
# type: (str) -> List[Token]
@@ -131,15 +132,30 @@ def tokenize(text):
(e.message, state.line, state.col,
e.line_content))
line_span = len(s.split('\n'))
token = Token(
kind=kind,
s=s,
tag=tag,
line=state.line,
col=state.col,
line_span=line_span
)
tokens.append(token)
advance(len(s))
if kind == 'html_singleton':
# Here we insert a Pseudo html_singleton_end tag so as to have
# ease of detection of end of singleton html tags which might be
# needed in some cases as with our html pretty printer.
token = Token(
kind='html_singleton_end',
s='</' + tag + '>',
tag=tag,
line=state.line,
col=state.col,
line_span=1
)
tokens.append(token)
return tokens