def close_tag(self, data, is_xml): data = Tag.clean_html(data).split('<') data.reverse() try: i = 0 lenght = len(data) - 1 while i < lenght: tag = Tag.name(data[i], True, is_xml) # if opening tag, close the tag if tag: if not Tag.is_closing(data[i]): return '</' + Tag.name(data[i], True, is_xml) + '' # if closing tag, jump to opening tag else: i = i + 1 skip = 0 while i < lenght: if Tag.name(data[i], True, is_xml) == tag: if not Tag.is_closing(data[i]): if skip == 0: break else: skip = skip - 1 else: skip = skip + 1 i = i + 1 i = i + 1 return '' except: return ''
def close_tag(self, data, is_xml): data = Tag.clean_html(data).split('<') data.reverse() try: i = 0 lenght = len(data)-1 while i < lenght: tag = Tag.name(data[i], True, is_xml) # if opening tag, close the tag if tag: if not Tag.is_closing(data[i]): return '</'+Tag.name(data[i], True, is_xml)+'' # if closing tag, jump to opening tag else: i = i+1 skip = 0 while i < lenght: if Tag.name(data[i], True, is_xml) == tag: if not Tag.is_closing(data[i]): if skip == 0: break else: skip = skip-1 else: skip = skip+1 i = i+1 i = i+1 return '' except: return '';
def run(self): begin = time() content = self.content original_position = self.original_position is_xml = self.is_xml # remove unparseable content content = Tag.clean_html(content) # linting: opening tags data = content.split('<') position = original_position+len(data.pop(0)) invalid_tag_located_at = -1 i = 0 lenght = len(data) first_at = 0 while i < lenght: tag = Tag.name(data[i], False, is_xml) if tag and tag != 'html' and tag != 'body' and tag != 'head': # if opening tag, then check if closing tag exists if not Tag.is_closing(data[i]): # print tag+' is opening ' if first_at == 0: first_at = position a = i+1 skip = 0 while a < lenght: inner_tag_name = Tag.name(data[a], False, is_xml) # check if same tag was found if inner_tag_name and inner_tag_name == tag: # check if tag is closing if Tag.is_closing(data[a]): if skip == 0: break else: skip = skip-1 else: skip = skip+1 a = a+1 if a >= lenght: self.message = '"'+tag+'" tag is not closing' invalid_tag_located_at = position break position += len(data[i])+1 i = i+1 # linting: closing tags if invalid_tag_located_at == -1: position = original_position+len(content); data = content.split('<') data.reverse() i = 0 lenght = len(data)-1 while i < lenght: tag = Tag.name(data[i], False, is_xml) if tag and tag != 'html' and tag != 'body' and tag != 'head': # if closing tag, check if opening tag exists if Tag.is_closing(data[i]): # print tag+' is closing ' a = i+1 skip = 0 while a < lenght: inner_tag_name = Tag.name(data[a], False, is_xml) if inner_tag_name and inner_tag_name == tag: # check if tag is opening if not Tag.is_closing(data[a]): if skip == 0: break else: skip = skip-1 else: skip = skip+1 a = a+1 if a >= lenght: self.message = '"'+tag+'" tag is not opening' invalid_tag_located_at = position-(len(data[i])+1) if invalid_tag_located_at < first_at: invalid_tag_located_at = -1 break position -= len(data[i])+1 i = i+1 elapsed_time = time() - begin; # print 'Benchmark: '+str(elapsed_time) self.invalid_tag_located_at = invalid_tag_located_at sublime.set_timeout(lambda:tag_lint.display(self.view, self.message, self.invalid_tag_located_at, self.from_command), 0)
def run(self): begin = time() content = self.content original_position = self.original_position is_xml = self.is_xml # remove unparseable content content = Tag.clean_html(content) # linting: opening tags data = content.split('<') position = original_position + len(data.pop(0)) invalid_tag_located_at = -1 i = 0 lenght = len(data) first_at = 0 while i < lenght: tag = Tag.name(data[i], False, is_xml) if tag and tag != 'html' and tag != 'body' and tag != 'head': # if opening tag, then check if closing tag exists if not Tag.is_closing(data[i]): # print tag+' is opening ' if first_at == 0: first_at = position a = i + 1 skip = 0 while a < lenght: inner_tag_name = Tag.name(data[a], False, is_xml) # check if same tag was found if inner_tag_name and inner_tag_name == tag: # check if tag is closing if Tag.is_closing(data[a]): if skip == 0: break else: skip = skip - 1 else: skip = skip + 1 a = a + 1 if a >= lenght: self.message = '"' + tag + '" tag is not closing' invalid_tag_located_at = position break position += len(data[i]) + 1 i = i + 1 # linting: closing tags if invalid_tag_located_at == -1: position = original_position + len(content) data = content.split('<') data.reverse() i = 0 lenght = len(data) - 1 while i < lenght: tag = Tag.name(data[i], False, is_xml) if tag and tag != 'html' and tag != 'body' and tag != 'head': # if closing tag, check if opening tag exists if Tag.is_closing(data[i]): # print tag+' is closing ' a = i + 1 skip = 0 while a < lenght: inner_tag_name = Tag.name(data[a], False, is_xml) if inner_tag_name and inner_tag_name == tag: # check if tag is opening if not Tag.is_closing(data[a]): if skip == 0: break else: skip = skip - 1 else: skip = skip + 1 a = a + 1 if a >= lenght: self.message = '"' + tag + '" tag is not opening' invalid_tag_located_at = position - (len(data[i]) + 1) if invalid_tag_located_at < first_at: invalid_tag_located_at = -1 break position -= len(data[i]) + 1 i = i + 1 elapsed_time = time() - begin # print 'Benchmark: '+str(elapsed_time) self.invalid_tag_located_at = invalid_tag_located_at sublime.set_timeout( lambda: tag_lint. display(self.view, self.message, self.invalid_tag_located_at, self. from_command), 0)