Selectively clear direct formatting

I have to insert text from MS-Word documents into Writer that have a lot of direct formatting (fonts, font sizes etc.). However, superscript and subscript have here a semantic meaning (formulars, units) and need to be preserved.

When I do Format > Clear direct formatting it removes all formatting and I have to do a lot manual work restoring the superscript/subscript formatting. Is there a more efficient way?

Are you sure, that there is not a character style applied?


There is a much easier way to achieve this, answered by @pierre-yves-samyn:

Original answer

I have used the following workaround:

  1. Search with regular expressions for (.*) with desired style, e.g for bold (see formatting button on lower right corner).

  2. Replace it with e.g <b>$1</b>

  3. Repeat with all other formatting you need, e.g italics and super- or subscript.

  4. Select all, Clear all Formatting. Now your document looks something like “This <b> was bold,</b>, this was <i>italic</i>.”

  5. Do it the other way around. Search for <b>([^<]*)</b> and replace it with $1 and let the replace box have the desired formatting.

And you are done.

BTW, formatting applies to “search for” or “replace with” boxes, depending on which one is selected. So does the “No formatting” button.

Thank you for your reply! Actually I will test another versions, like EuroOffice or something. In OO I was able to assign a shortcut to this function, and have it at one click. And so my colleagues. Compare this to your kind recipe. Looks like someone manages LO development in the way to make it less, and less usable for an average user.

@frankaen, true. But hey, why not write an extension?

Very confusing mistake in the explanation at step 2: you need to use $0, not $1 or the output will be empty. The method is very effective though!

@darioshanghai, no not a mistake at all. $0 returns the whole match, while $1 is just the first group, which means anything inside first pair of parenthesis (). So if your search is (.*) not .*, then it will work just fine. Although for this case using .* and $0 would be 2 characters shorter.

Interesting that in your case Clear Direct Formatting works, because I have some characters formatted more than bold, italic and so on, and CDF removes only this simple formatting, but not advanced, like changed intercharacter space, underline, colour.