zim-wiki team mailing list archive
-
zim-wiki team
-
Mailing list archive
-
Message #02629
Creating and editing pages using zim module and custom tools
Hi guys!
Developer talk below.
In order to find my away around the Zim code so I can help killing some
bugs I am creating a few custom tools using zim module.
One of my practices when creating new pages is creating on the top of the
page links do other namespaces that might relate to each other. A bit like
some people use tags but I prefer clickable links that can be listed as
backlinks to when I am visiting a page.
My first idea for a custom tool was to list inside the current page (the
page I am visiting) some selected pages that have a particular link at the
top (that I am calling headers for myself).
For this I get a page list using notebook.get_pagelist() and then go
through each page content to search the first lines of the page for the
links.
Question 1:
Is it OK to use get_pagelist() and not index.list_pages() since I need the
content of each page?
Question 2:
To find the links at the top of the page I understand I can use the
ElementTree but I found it easier, for my purpose, to parse the source text
file directly because I don't have to go through the format tags (ex: <p>
and <link>). Is this ok or I should stick to using the zim module interface?
In some situations I want to create a new page. I have managed to create
new pages using some code like this:
notebook_path = '<file system path to notebook>'
new_page_path = '<namespace path to notebook>'
text = 'sample initial text'
notebook = get_notebook(notebook_path)
new_page = notebook.get_new_page(Path(new_page_path))
template = notebook.get_template(page)
tree = template.process_to_parsetree(notebook, page)
new_page.set_parsetree(tree)
new_page.parse('wiki',text,append=True)
notebook.store_page(new_page)
notebook.emit('stored-page',new_path) # not sure if this is necessary
(yep! "stolen" from the zim module code)
Question 3:
Is this code ok for use in custom tools?
Question 4:
I found that if zim is running, the treeview is not updated immediately. Is
there a way to force this?
Question 5 and 6:
Is notebook.emit() necessary? Am I using it properly?
Thank you!
Follow ups