RoryOF wrote:Is there any way (some Escape sequence) to tell OpenOffice not to parse the selected text into XML, but to pass it through unchanged to the file?
I think there is no method to pass XML directly into the document. However perhaps you can use a technique I created to work with hyperlinks in a spreadsheet. There are two types: those created with the
=HYPERLINK() function, and those created with the Insert → Hyperlink dialog. I normally use the former, which I call call "dynamic" since the link's name and URL can be manipulated by functions or the user interface, but sometimes I encounter the latter in documents from others. Those can't be manipulated easily, only by the dialog, so I'll call them "static". For example, one wants to change the URL in static hyperlinks to alter some part of the path. There's no good way to do that for dozens of them. I think Writer only offers static hyperlinks.
My idea was to manipulate the XML to change the link into text. I can manipulate the text with spreadsheet functions/features. Then I change the text back into a link. The latter is similar to what you want to accomplish.
To change the link into text, I change < to «, " to …, and > to ». The method depends on having «…» be otherwise unused in the document. I chose «…» because they are easy to type on a Mac, and are visually similar to the XML characters they represent. One can use others, of course.
p='<text:p><text:a xlink:href="([^"]+)">([^<]+)</text:a></text:p>'
r='<text:p>«text:a xlink:href=…\1…»\2«/text:a»</text:p>'
unzip -p file.ods content.xml | sed -Ee "s|$p|$r|g" >content.xml
zip -m file.ods content.xml
The static hyperlinks are gone and the cells now contain simple text:
«text:a xlink:href=…❴URL❵…»❴Text❵«/text:a» where ❴URL❵ and ❴Text❵ represent the URL and text from the static hyperlink. Now I can use Edit → Find & Replace to change all the URL paths at once. Or all the texts at once. I could also change the text into a
=HYPERLINK() function call.
To change the text back into a link, I change « to <, … to ", and » to >. This is easier since no parsing is needed. -p
pipes the content to tr, which modifies it before creating content.xml. -m
moves content.xml into the zip file, that is, the operation is replace and delete.
unzip -p file.ods content.xml | tr '«…»' '<">' >content.xml
zip -m file.ods content.xml
For your case, I'd insert «text:line-break/» into the document at the desired locations, then use the commands below, since you have no quote to contend with.
unzip -p file.odt content.xml | tr '«»' '<>' >content.xml
zip -m file.odt content.xml
You will no doubt practice first on a copy of the actual file.
I know it is possible to use a macro to access and manipulate the content of static hyperlinks. However the API is complex, and the method I use here is much easier for me than researching which services/interfaces I would need for a macro. This may be especially true in Writer documents where one may have messy situations like hyperlinks in tables, or in sections, or … which the macro will have to navigate to access them all. For your situation you just need to know that
<text:line-break/> is valid XML at the point you want to insert it.
Edit: I see now that line-break is just an example; there are other XML sequences. But if you substitute «» for <>, °¨ for the two quotation marks, and ∞ for & in your sequence, then use unzip/tr/zip to change them, this should cover all cases. You may need to write & as ∞amp;. |
Edit: You may not need a replacement for &. In XML it is used in <, >, ', and ", but you don't need to use those since tr allows you to insert them. |
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).