- AuthorPosts
- April 8, 2022 at 8:58 am #28136spirosParticipant
I have a jsee macro making a number of find/replace operations using
document.selection.Replace
I want to add a conditional find/replace operation. For exampleif the text contains more than 1 instance of
<span class="bld">
Do nothing
Else
find<span class="bld">A</span>
and deleteHow can this be done in a jsee macro?
April 27, 2022 at 5:44 am #28150Yutaka EmuraKeymasterYou can write a macro like this:
if( document.selection.Find( "<span class=\"bld\">", eeFindAround | eeFindCount ) <= 1 ) { document.selection.Replace( "<span class=\"bld\">A</span>", "", eeReplaceAll ); }
April 27, 2022 at 6:34 am #28151spirosParticipantThank you so much!
I get an error
https://ibb.co/JjQfq7C
https://ibb.co/zZ6sBJdWhen I click, it indicates the line of the document (8) where I added the code.
document.selection.StartOfDocument(false); document.selection.Replace("(<span class=\x22bld\x22>)(.*?)(</span>)","<{\\2}>",eeReplaceAll | eeFindReplaceRegExp,0); document.selection.Replace("</?\\w+((\\s+\\w+(\\s*=\\s*(?:\x22.*?\x22|\x27.*?\x27|[\\^\x27\x22>\\s]+))?)+\\s*|\\s*)/?>","",eeReplaceAll | eeFindReplaceRegExp,0); document.selection.Replace("<{","<br><span class=\x22bld\x22>",eeReplaceAll,0); document.selection.Replace("}>","</span>",eeReplaceAll,0); document.selection.Replace("Definition=<br>","Definition=",eeReplaceAll,0); document.selection.Replace(" <br>","<br>",eeReplaceAll,0); if( document.selection.Find( "<span class=\"bld\">", eeFindAround | eeFindCount ) <= 1 ) { document.selection.Replace( "<br><span class=\"bld\">A</span>", " ", eeReplaceAll ); } document.selection.SelectAll(); document.selection.Copy(eeCopyUnicode); editor.ExecuteCommandByID(4120);
April 28, 2022 at 11:19 am #28152Yutaka EmuraKeymasterAs for the first screenshot, you can set the “Do not show this message again” check box to disable this message in the future.
As for the second screenshot, I am not sure what the issue is. Can you please create a minimum reproducible test case so that I can test the issue?
April 28, 2022 at 1:08 pm #28153spirosParticipant1. Yes, I did it, no more errors.
Test text:
εσσα, εν, poet. for [[κυκλικός]], <span class="sense"><span class="bld">A</span> [[circular]], ἀγορᾶς θρόνος <span class="bibl">S.<span class="title">OT</span>161</span> (lyr.); ἴτυς <span class="title">AP</span>7.232 (Antip.).</span>
April 28, 2022 at 8:21 pm #28154Yutaka EmuraKeymasterI couldn’t reproduce the issue. Are you using the latest version (21.6.907)?
- AuthorPosts
- You must be logged in to reply to this topic.