コード例 #1
0
	def parse(self, input, partial=False):
		if not isinstance(input, str):
			input = ''.join(input)

		if not partial:
			input = fix_line_end(input)

		parser = zim.parser.Parser(
			Rule(LINK, url_re.r, process=self.parse_url) # FIXME need .r attribute because url_re is a Re object
		)

		builder = ParseTreeBuilder(partial=partial)
		builder.start(FORMATTEDTEXT)
		parser(builder, input)
		builder.end(FORMATTEDTEXT)
		return builder.get_parsetree()
コード例 #2
0
ファイル: plain.py プロジェクト: hjq300/zim-wiki
	def parse(self, input, partial=False):
		if not isinstance(input, basestring):
			input = ''.join(input)

		if not partial:
			input = fix_line_end(input)

		parser = zim.parser.Parser(
			Rule(LINK, url_re.r, process=self.parse_url) # FIXME need .r atribute because url_re is a Re object
		)

		builder = ParseTreeBuilder(partial=partial)
		builder.start(FORMATTEDTEXT)
		parser(builder, input)
		builder.end(FORMATTEDTEXT)
		return builder.get_parsetree()
コード例 #3
0
    def parse(self, input, partial=False, file_input=False):
        if not isinstance(input, str):
            input = ''.join(input)

        input = input.replace(
            '\u2029', ' '
        )  # Unicode PARAGRAPH SEPARATOR, causes conflict between "splitlines()" and regex "\n" matching - see issues #1760

        if not partial:
            input = fix_line_end(input)

        meta, version = None, False
        if file_input:
            input, meta = parse_header_lines(input)
            version = meta.get('Wiki-Format')

        # Support backward compatibility - see history notes WIKI_FORMAT_VERSION
        version = version or self.version
        if version == 'zim 0.6':
            mywikiparser = wikiparser
        elif version in ('zim 0.4', 'zim 0.5'):
            mywikiparser = WikiParser(backward_url_parsing=True)
        else:
            mywikiparser = WikiParser(backward_indented_blocks=True,
                                      backward_url_parsing=True)

        builder = ParseTreeBuilder(partial=partial)
        mywikiparser(builder, input)

        parsetree = builder.get_parsetree()
        if meta is not None:
            for k, v in list(meta.items()):
                # Skip headers that are only interesting for the parser
                #
                # Also remove "Modification-Date" here because it causes conflicts
                # when merging branches with version control, use mtime from filesystem
                # If we see this header, remove it because it will not be updated.
                if k not in ('Content-Type', 'Wiki-Format',
                             'Modification-Date'):
                    parsetree.meta[k] = v
        return parsetree