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 = 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 '';
示例#3
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)
示例#4
0
    def run(self):

        begin = time()

        content = self.content
        original_position = self.original_position
        is_xml = self.is_xml

        # remove unparseable content

        # comments
        unparseable = content.split('<!--')
        content = unparseable.pop(0)
        l = len(unparseable)
        i = 0
        while i < l:
            tmp = unparseable[i].split('-->')
            content += '....'
            content += len(tmp.pop(0)) * '.'
            content += '...'
            content += "...".join(tmp)
            i += 1

        unparseable = content.split('/*')
        content = unparseable.pop(0)
        l = len(unparseable)
        i = 0
        while i < l:
            tmp = unparseable[i].split('*/')
            content += '..'
            content += len(tmp.pop(0)) * '.'
            content += '..'
            content += "..".join(tmp)
            i += 1

        # script
        unparseable = content.split('<script')
        content = unparseable.pop(0)
        l = len(unparseable)
        i = 0
        while i < l:
            tmp = unparseable[i].split('</script>')
            content += '.......'
            content += len(tmp.pop(0)) * '.'
            content += '.........'
            content += ".........".join(tmp)
            i += 1

        # script
        unparseable = content.split('<style')
        content = unparseable.pop(0)
        l = len(unparseable)
        i = 0
        while i < l:
            tmp = unparseable[i].split('</style>')
            content += '......'
            content += len(tmp.pop(0)) * '.'
            content += '........'
            content += "........".join(tmp)
            i += 1

        # 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':
                # 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':
                    # 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)
示例#5
0
    def run(self):

        begin = time()

        content = self.content
        original_position = self.original_position
        is_xml = self.is_xml

        # remove unparseable content

        # comments
        unparseable = content.split("<!--")
        content = unparseable.pop(0)
        l = len(unparseable)
        i = 0
        while i < l:
            tmp = unparseable[i].split("-->")
            content += "...."
            content += len(tmp.pop(0)) * "."
            content += "..."
            content += "...".join(tmp)
            i += 1

        unparseable = content.split("/*")
        content = unparseable.pop(0)
        l = len(unparseable)
        i = 0
        while i < l:
            tmp = unparseable[i].split("*/")
            content += ".."
            content += len(tmp.pop(0)) * "."
            content += ".."
            content += "..".join(tmp)
            i += 1

            # script
        unparseable = content.split("<script")
        content = unparseable.pop(0)
        l = len(unparseable)
        i = 0
        while i < l:
            tmp = unparseable[i].split("</script>")
            content += "......."
            content += len(tmp.pop(0)) * "."
            content += "........."
            content += ".........".join(tmp)
            i += 1

            # script
        unparseable = content.split("<style")
        content = unparseable.pop(0)
        l = len(unparseable)
        i = 0
        while i < l:
            tmp = unparseable[i].split("</style>")
            content += "......"
            content += len(tmp.pop(0)) * "."
            content += "........"
            content += "........".join(tmp)
            i += 1

            # 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
        )