View Single Post
Old 12-04-2018, 04:06 AM   #2
jbacelar
Interested in the matter
jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.jbacelar ought to be getting tired of karma fortunes by now.
 
jbacelar's Avatar
 
Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
I use a search/replace battery:
Code:
1- Search: <p>\[(\ d +)\] (or whatever may apply)
Replace with: <p class="nota" id="n\1">[\1]
2- Search: (<p class="nota")>\[(\d +)\]
Replace with this function:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    return match.group(1)+' id="n'+match.group(2)+'"><a href="../'+file_name+'#r'+match.group(2)+'">['+match.group(2)+']</a>'
3- Search: (<p class="nota".+?>.+?</p>)
Replace with this function:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    notas = open('e:/Libros/Taller/En curso/notas.txt', 'a')
    texto = match.group()+'\n'  
    notas.write(texto)
    return ''
replace.file_order = 'spine'
Due to my poor knowledge of Python, the last function puts all the notes in the file notas.txt, this can be improved if someone knows how to place them in the corresponding xhtml file of the ebook.
I manually create this last file, and make a copy/paste with the data of notas.txt.
jbacelar is offline   Reply With Quote