コード例 #1
0
ファイル: sourceview.py プロジェクト: hjq300/zim-wiki
    def testDumpHtml(self):
        xml = '''\
<?xml version='1.0' encoding='utf-8'?>
<zim-tree><object lang="python" linenumbers="false" type="code">
def foo(a, b):
	print "FOO", a >= b

</object></zim-tree>'''
        tree = ParseTree().fromstring(xml)
        dumper = HtmlDumper(StubLinker())
        html = dumper.dump(tree)
        #~ print '>>', html
        self.assertIn('\tprint "FOO", a &gt;= b\n', html)
コード例 #2
0
ファイル: zim_to_md.py プロジェクト: xuyuan/zim_to
                c = attrib.get('lang', "")
                return ['```%s\n' % c] + strings + ['```\n']
        return super(Dumper, self).dump_object(tag, attrib, strings)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-T',
                        dest='wiki_text',
                        help='the selected text including wiki formatting')
    parser.add_argument('-f',
                        dest='file',
                        help='the page source as temporary file')
    parser.add_argument('-D', dest='source_dir', help='the document root')
    args = parser.parse_args()

    zim_parser = get_parser('wiki')
    if args.wiki_text:
        wiki_text = args.wiki_text
    else:
        wiki_text = open(args.file).read()
    tree = zim_parser.parse(wiki_text)
    try:
        linker = StubLinker(source_dir=args.source_dir)
        dumper = Dumper(linker=linker)
        lines = dumper.dump(tree)
        textile_text = ''.join(lines).encode('utf-8')
        pyperclip.copy(textile_text)
    except Exception as e:
        pyperclip.copy(e.message)