def print_to_file(self, notebook, page): file = TmpFile('print-to-browser.html', persistent=True, unique=False) template = zim.templates.get_template('html', 'Print') template.set_linker(StaticLinker('html', notebook, page)) html = template.process(notebook, page) file.writelines(html) return file
def _get(self, clipboard, selectiondata, id, *a): '''Callback to get the data in a specific format @param clipboard: a C{gtk.Clipboard} objet @param selectiondata: a C{gtk.SelectionData} object to set the data on @param id: target id for the requested data format @param a: any additional arguments are discarded ''' logger.debug("Clipboard requests data as '%s', we have a parsetree", selectiondata.target) if id == PARSETREE_TARGET_ID: # TODO make links absolute (?) xml = self.parsetree.tostring().encode('utf-8') selectiondata.set(PARSETREE_TARGET_NAME, 8, xml) elif id == HTML_TARGET_ID: # FIXME - HACK - dump and parse as wiki first to work # around glitches in pageview parsetree dumper # main visibility when copy pasting bullet lists # Same hack in print to browser plugin dumper = get_format('wiki').Dumper() text = ''.join( dumper.dump(self.parsetree) ).encode('utf-8') parser = get_format('wiki').Parser() parsetree = parser.parse(text) #-- dumper = get_format('html').Dumper( linker=StaticLinker('html', self.notebook, self.path) ) html = ''.join( dumper.dump(parsetree) ) html = wrap_html(html, target=selectiondata.target) #~ print 'PASTING: >>>%s<<<' % html selectiondata.set(selectiondata.target, 8, html) elif id == TEXT_TARGET_ID: logger.debug("Clipboard requested text, we provide '%s'" % self.format) #~ print ">>>>", self.format, parsetree.tostring() if self.format in ('wiki', 'plain'): dumper = get_format(self.format).Dumper() else: dumper = get_format(self.format).Dumper( linker=StaticLinker(self.format, self.notebook, self.path) ) text = ''.join( dumper.dump(self.parsetree) ).encode('utf-8') selectiondata.set_text(text) else: assert False, 'Unknown target id %i' % id
def runTest(self): notebook = get_test_notebook() notebook.get_store(Path(':')).dir = Dir('/source/dir/') # fake source dir linker = StaticLinker('html', notebook) linker.set_usebase(True) # normally set by html format module linker.set_path(Path('foo:bar')) # normally set by exporter linker.set_base(Dir('/source/dir/foo')) # normally set by exporter self.assertEqual(linker.page('+dus'), './bar/dus.html') self.assertEqual(linker.page('dus'), './dus.html') self.assertEqual(linker.file('./dus.pdf'), './bar/dus.pdf') self.assertEqual(linker.file('../dus.pdf'), './dus.pdf') self.assertEqual(linker.file('../../dus.pdf'), '../dus.pdf')
def runTest(self): '''Test proper linking of files in export''' notebook = tests.new_notebook(fakedir='/source/dir/') linker = StaticLinker('html', notebook) linker.set_usebase(True) # normally set by html format module linker.set_path(Path('foo:bar')) # normally set by exporter linker.set_base(Dir('/source/dir/foo')) # normally set by exporter self.assertEqual(linker.link_page('+dus'), './bar/dus.html') self.assertEqual(linker.link_page('dus'), './dus.html') self.assertEqual(linker.link_file('./dus.pdf'), './bar/dus.pdf') self.assertEqual(linker.link_file('../dus.pdf'), './dus.pdf') self.assertEqual(linker.link_file('../../dus.pdf'), '../dus.pdf') ## setup environment for interwiki link if os.name == 'nt': uri = 'file:///C:/foo' else: uri = 'file:///foo' list = get_notebook_list() list.append(NotebookInfo(uri, interwiki='foo')) list.write() ## href = interwiki_link('foo?Ideas:Task List') self.assertIsNotNone(href) self.assertEqual(linker.link('foo?Ideas:Task List'), uri + '/Ideas/Task_List.txt')