Need macro to italicize all text between <i> and </i>

My genealogical program can output rich text , using xxx and yyy for italics. I wish to italicize the marked passages in large documents once I;ve loaded them into LibreOffice Writer.

xxx and yyy use angle brackets i and angle brackets /i which I don’t seem to be able to reproduce in this forum.

The documents are in rich text format, not HTML. Here is an example: “the passenger manifest of the S.S. Batavia out of Hamburg.”

Really RTF (Rich Text Format) or HTML?

Tell us more about your goal. If your genealogical program outputs HTML, it is more simpler to open this HTML file with Writer (procedure depends on OS which you didn’t mention, usually based on a right-click on the file icon). Once in Writer, File>Save as in .odt format does the trick.

Please do not use Add Answer but edit your original question to enhance the details of your question (answers are reserved for solutions to a problem on this Q&A site).

Are you aware that the W3C Web Accessibility Initiative (WAI) standards recommend using em and /em instead of i and /i. (Sorry that I can’t put my finger on the exact document at the moment.) Many web accessibility testing tools will flag your use of i and /i as a violation. (Angle brackets omitted because it confuses the formatting here.)

I’m not interested in web accessibility. I just want to print out the documents on paper with the marked sections properly italicized.

meaning emphasized. I think current aemphsizing mode can be italic, but isn’t explicitly specified this way.
See HTML Text Formatting.

If the document is truly RTF, open it directly in Writer (eventually give it extension .rtf but this is not strictly necessary). Writer has an input/output filter to import/export RTF files. But be prepared for some errors if your genealogical program uses a different version of RTF specification.

Thank you. I experimented by opening the file as RTF and writing it out as ODT. It didn’t work, but I may not have attended to the filters you mention. I think the macro supplied by Lupp will do the job.

Thanks to all.

“I’m not interested in web accessibility.”

Sorry, I thought your intention was to post your genealogy data on the web. My mistake.

I do, but via a different route. I use John Cardinal’s GedSite program; see example at Nine Generations - Home (he said proudly) :slight_smile:

Raw code. No checks. no restriction to selected ranges…

Sub applyStyleToAllTextPortionsTaggedHtml4( _
      Optional pCharStyle As String, Optional pTagLetters As String)
REM pCharStyle is expected to be the name of a CharacterStylle having
REM the attribute set. If the style doesnt exist an error is expected,
REM If the name is empty or not passed at all, the default attribute 
REM italic (CharPosture = 1) is set by direct formatting.
If IsMissing(pTagLetters) Then pTagLetters = "i"
searchString = "<" & pTagLetters & ">(.*?)</" & pTagLetters & ">"
If IsMissing(pCharStyle) Then pCharStyle = ""
doc = ThisComponent
searchDescriptor = doc.createSearchDescriptor()
With searchDescriptor
  .SearchRegularExpression = True
  .SearchString = searchString '"<i>(.*?)</i>"
  .ReplaceString = "$1"
  foundRanges = doc.findAll(searchDescriptor)
  u = foundRanges.Count - 1
  For j = 0 To u
    j_rg = foundRanges(j)
    If pCharStyle="" Then
      j_rg.CharPosture = 1
    Else
      j_rg.CharStyleName = pCharStyle
    End If
  Next j
  doc.replaceAll(searchDescriptor)
End With
End Sub

I think it was explained before on other thread, To do it without macros, can be done in two steps. First using Search&Replace with your regular expression to find all the text to change, at this point all the wanted text it’s selected, so a style or a direct format can be applied to all at once.

Suppose you mean the linked thread concerning the (roughly) reverse task? I also considered to refer to this interactive way and mention the needed changes. However, I’m not so strict in dissuading from relying on user code if a specifice action may repeatedly occur. I personally tend to not feel really well with repeating manual sequences of actions.

I only wanted to show another way, not really other, but with or without macro.