Adding HTML code to ODT manuscript

I recently switched from Word (and before that from WP and WordStar and XyWrite), and am trying to write macros to preprocess documents into HTML. Some of my LibreOffice questions have been answered here, but I haven’t yet been able to find a way to convert all words in italics (“target”) into:
< i >target< /i >
In other words, there are many italicized words in the document. I want a macro that will surround everything in italics with < i > and < /i > (or other codes like < em > < strong > etc).
It would be best if the replacement is in word units, but even single-character units is fine (I can easily delete extraneous < i > and < /i > entries with a different script).

For obvious reasons the HTML code above has extra spaces inserted.

If anyone can provide help or point me to a useful source I’d appreciate it.

Thanks for your time.

Have you tried to export your manually formatted text into HTML format?

Of course, but I simplified the question here to get more direct answers. There is a considerable range of text to be added, not just < i > etc. I can do it in an HTML editor after I get it there, but it would be convenient to run a preprocessor in Writer before transferring it over

try

Sub FindReplaceItalic
	dim oDoc as object, oDesc as object, attr(0) as new com.sun.star.beans.PropertyValue
	oDoc=ThisComponent
	oDesc=oDoc.createReplaceDescriptor
	attr(0).Name="CharPosture" 'property for searching
	attr(0).Value=com.sun.star.awt.FontSlant.ITALIC
	with oDesc 'replace descriptor
		.SearchAttributes=attr
		.SearchRegularExpression=true
		.SearchString="(.+)"
		.ReplaceString="<i>$1</i>"
	end with
	with oDoc
		.lockControllers
		.replaceAll(oDesc)
		.unlockControllers
	end with
End Sub

side note @KamilLanda : wouldn’t you want to revive the dev on AltSearch ?
Alternative search extension not listed - #4 by KamilLanda

165725 – Allow targeting of styles and formatting via regular expressions in Find and Replace

@fpy Unfortunately the modifications of AltSearch aren’t so easy and mostly it isn’t activity for few minutes or 1-2 hours. I thought before few years I will revive the dev of AltSearch, but some things are complicated and I decided I will not spend time with modifications for too complicated system, because there would be the best to programm some things completely new. I remember some reasons from author why some things are programmed so strangely/tangledly in AltSearch - he wasn’t professional programmer but needed some sophisticated functions, so he learned some programming and made some extensions - but cobbled together by hot needle (Czech proverb for fast and not so skilled and really not optimized work).


I hope I will finish the Bin packing problem in next days, and then I need continue on some web projects, so I will not have a time (and probably also mood) to modify the AltSearch in next weeks or months :-(.

1 Like

Impressive!
I understand in general what you did but have to dig into it to be able to utilize it.

So apparently there is a variable $1 (found character string), which easily resolves my problem.
I’ll try it out shortly.

Thanks very much for the input!

OK, I played around with your macro, and it isn’t as simple as I had hoped.
Is there a list of attr(0) values somewhere?
I assume there should be something like, for example:

attr(0).Name=“GrafPosture”
attr(0).Value=com.sun.star.awt.align.center

but it would help if I knew what terms were supported. I was hoping for a more flexible solution that I could adapt to a variety of cases.

LibreOffice: CharacterProperties Service Reference

LibreOffice SDK Programming Guide - The Document Foundation Wiki

List of Regular Expressions

For a full list of supported metacharacters and syntax, see ICU Regular Expressions documentation

see AltSearch previously mentionned.

1 Like

Thank you.
The CharProperties reference is invaluable. And if I get tired of trying to learn a new system, it looks like AltSearch will do what I need one step at a time.

(but you can look at the code to get some more clues)

1 Like