View Single Post
Old 02-27-2024, 08:58 AM   #16
reinsley
Connoisseur
reinsley began at the beginning.
 
reinsley's Avatar
 
Posts: 65
Karma: 10
Join Date: Dec 2016
Location: France
Device: Kindle PaperWhite
Quote:
Originally Posted by lomkiri View Post
Ok, your initial explanation was really unclear
Shame on me, I answered two helpers in the same post and got tangled up in my explanations. That said, asking a question is a good way to clear one's head, but I'll tidy up before posting.

Quote:
Originally Posted by lomkiri View Post
BUT

let see if I really get what you mean : I understand that you want to target this sentence
<p class="calibre8"> <span class="calibre3">He came through the door. « I'm here », he said.</span> </p>

and transform it to
<p class="calibre8"> <span class="calibre3">He came through the door.</span></p>
<p class="calibre8"> <span class="calibre3"> — « I'm here », he said.</span> </p>


but not this one :
<p class="calibre8"> <span class="calibre3"> — « Sentence ending with a comma, » said the man. « Then a second part. »</span> </p>

Is it OK ?
Right.

Quote:
Originally Posted by lomkiri View Post
You've got the idea, I guess you will be able to adapt it if you have some slightly different needs.
Since you seem to need to make some complex substitutions, I guess you should find a tuto for using regexes, there is a quite good one in the help in the site of calibre. The site I've given the URL in my first message is a reference, not a tuto, it is not for learning the basis.
The site https://regex101.com may help you to construct your regexes (select PCRE as a flavor)
I need to do my homework to perfect the formula with regex101 and the other reference site.


I'm on the right track.
FYI : The nbsp don't take the \s into account. I'll normalize all the text before the regex.
Issue : A line starting with em dash is selected with the following regex.
Lines starting with text are nicely formatted when they are enlighted.

Here's the search : (<p class="calibre8"> <span class="calibre3">)(\s—\s«.+?,\s»\s)?([^.]+.) (« )
and replace : \1\2\3</span> </p>
<p class="calibre8"> <span class="calibre3"> — «
in regular expression mode that find the emdash.


some examples put in calibre html page :

<body>
<p class="calibre8"> <span class="calibre3">He came through the door. « I'm here », he said.</span> </p>
<p>comment : I need to find and select . «</p>
<span class="calibre3">*</span>
<p class="calibre8"> <span class="calibre3"> — « Sentence ending with a comma, » said the man. « Then a second part. »</span> </p>
<p>comment : no need to find and select . «</p>
<span class="calibre3">*</span>
<p class="calibre8"> <span class="calibre3"> — «*Je répète donc ma question*», reprit le directeur, faussement calme. « L’information vous parait-elle authentique*?*»</span> </p>
<p>comment : no need to find and select . «</p>
<span class="calibre3">*</span>
<p class="calibre8"> <span class="calibre3">Axel échangea un regard en coin avec les autres. « Bon, maintenant que nous sommes là, autant aller jeter un coup d’œil sur place, non*?*»</span> </p>
<p>comment : I need to find and select . «</p>
<span class="calibre3">*</span>
<p class="calibre8"> <span class="calibre3">Le médecin esquissa une grimace. « Je dirais une quinzaine d’heures. La nuit dernière, sans doute. Ce matin, au plus tard.*»</span> </p>
<p>comment : I need to find and select . «</p>
<span class="calibre3">*</span>
<p class="calibre8"> <span class="calibre3">Le patron fut le premier à répondre. « Les deux adolescents cela ne fait aucun doute.*»</span> </p>
<p>comment : I need to find and select . «</p>
<span class="calibre3">*</span>
<p class="calibre8"> <span class="calibre3"> — « Donc la voie vous semble la plus vraisemblable, c’est ça*?*», reprit le conseiller à la sécurité.</span></p>
<p>comment : no need to find and select . «</p>
</body>


the CSS :
.calibre3 {
font-size: 1em
}
.calibre8 {;
margin-bottom: 0%;
margin-top: 0%;
text-align: justify
}

Thank you very much fo the the follow-up. Best regards.
reinsley is offline   Reply With Quote