Mobileread
epub code snippets (html / css)
#191  jbacelar 06-16-2016, 12:35 PM
@roger64

Oh! forgiveness for being so succinct.

The correct code is:
Code
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): return match.group().replace("?","@?").replace("!","@!").replace(";","@;").replace(":","@:")
Of course, you also have to remove the n-b-spaces, before the other characters.
Reply 

#192  roger64 06-16-2016, 02:06 PM
It's working.

The only thing is the count with the Calibre editor: it anounces 1386 replacement which seems to be only the replacements regarding the first element. When I make a separate recount (out of the function), it finds 1802 which seems to be the true amount, because, as far as I can look, every punctuation signs get its own @.

The main thing is that the full function does the job. I will reuse it for many other things.

Thanks a lot for your very appreciated help.
Reply 

#193  jbacelar 06-16-2016, 02:13 PM
You are welcome
Reply 

#194  roger64 10-08-2016, 09:24 PM
Hi

I have a regex question. The solution would allow me to convert more easily output from my word processor.

Say we have this text:

Code
<blockquote> <p>A la première ville,<br/>Son amant l’habille<br/>Tout en satin blanc</p> <p>A la seconde ville,<br/>Son amant l’habille<br/>En or, en argent.</p> <p>Elle était si belle<br/>Qu’on lui tendait les voiles<br/>Dans tout le régiment.</p>
</blockquote>
I wish, using an editor, to add a class "note" for each p. The number of p can vary from one to nine.

I fail to do it.
Reply 

#195  theducks 10-09-2016, 01:07 AM
Quote roger64
Hi

I have a regex question. The solution would allow me to convert more easily output from my word processor.

Say we have this text:

Code
<blockquote> <p>A la première ville,<br/>Son amant l’habille<br/>Tout en satin blanc</p> <p>A la seconde ville,<br/>Son amant l’habille<br/>En or, en argent.</p> <p>Elle était si belle<br/>Qu’on lui tendait les voiles<br/>Dans tout le régiment.</p>
</blockquote>
I wish, using an editor, to add a class "note" for each p. The number of p can vary from one to nine.

I fail to do it.
Just do a SINGLE mode search and replace, with the cursor on the <blockquote>

<p>
<p class="note">

If you are changing a font, why not apply the class to the Blockquote instead
Reply 

#196  jbacelar 10-09-2016, 04:43 AM
Calibre Editor, function regex.

Search (with multiline activated):
<blockquote>.*<p>.*</blockquote>

Replace:
Code
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): return match.group().replace("<p>","<p class=""note"">")
Come on, have fun.
Reply 

#197  roger64 10-09-2016, 05:21 AM


Sure I will since this function can have a lot more uses!! Thanks for it.

Oh! and I missed the theducks solution above which of course is also of practical use. Thanks too!!!
Reply 

 « First  « Prev   (20/20)
Today's Posts | Search this Thread | Login | Register