Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #28136
    spiros
    Participant

    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 example

    if the text contains more than 1 instance of
    <span class="bld">
    Do nothing
    Else
    find <span class="bld">A</span> and delete

    How can this be done in a jsee macro?

    #28150
    Yutaka Emura
    Keymaster

    You 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 );
    }
    
    #28151
    spiros
    Participant

    Thank you so much!

    I get an error
    https://ibb.co/JjQfq7C
    https://ibb.co/zZ6sBJd

    When 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);
    #28152
    Yutaka Emura
    Keymaster

    As 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?

    #28153
    spiros
    Participant

    1. 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>

    #28154
    Yutaka Emura
    Keymaster

    I couldn’t reproduce the issue. Are you using the latest version (21.6.907)?

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.