On Mon, Jan 3, 2011 at 6:01 PM, Pascollin <pascol...@gmail.com> wrote:
> I would like a plugin to reuse text snippets from some other pages.
>
> Example : I create a page "my text templates" and set this as snippets
> root in the plugin preferences.
>
> I tried to create such a plugin, but I didn't find how to add zim
> formatted text to the current insert point (textview/textbuffer).
>
> Could you give me some advice ?

To insert formatted text you need to parse the text first in order to
get a "parse tree", then you can use the "insert_parsetree_at_cursor"
method. You can get a parsetree for a page with "get_parsetree" or use
the parser for the specific format (default wiki format most likely).

To parse a piece of text and insert it in the current page the plugin
would need to do the following ("self" being the plugin object and
"text" the snippet):

>>>>>
import zim.formats

format = zim.formats.get_format('wiki')
parser = format.Parser()
parsetree = parser.parse(text)

buffer = self.ui.mainwindow.pageview.view.get_buffer()
buffer.insert_parsetree_at_cursor(parsetree)
<<<<<

Hope this helps,

Jaap

_______________________________________________
Mailing list: https://launchpad.net/~zim-wiki
Post to     : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp

Reply via email to