[Solved-Workaround] Replace paragraph break with line break

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
John_Ha
Volunteer
Posts: 9599
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

[Solved-Workaround] Replace paragraph break with line break

Post by John_Ha »

I would like to replace all paragraph breaks (enter) with line breaks (shift/enter). Is there an expression for line break in the Replace box?

It is easy to replace line breaks with paragraph breaks with Search = \n (finds line break) and Replace = \n (replaces with paragraph break).

I have searched extensively but can only find things saying it cannot be done ...

All help will be appreciated.
Last edited by John_Ha on Fri Feb 14, 2014 9:43 pm, edited 1 time in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
RoryOF
Moderator
Posts: 35063
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Replace paragraph break with line break (soft return)

Post by RoryOF »

This is a very bad idea in OpenOffice (if it is even possible). OpenOffice does not like (read: really hates) paragraphs longer than 64K characters; Line breaks do not read as paragraph breaks, and one can end up with documents that will take no further input.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
John_Ha
Volunteer
Posts: 9599
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Replace paragraph break with line break (soft return)

Post by John_Ha »

Rory
Thanks. I agree wholeheartedly! ...

... but I have a special purpose here which applies only to the text I have in one table, so it doesn't spread to the whole document.

I regularly get sent a fairly complex table where the non-WP-literate person uses about 50 paragraph returns instead of line breaks. I just want to change them to line breaks instead of doing them manually.

I know I could Format > Paragraph and set gap to zero, but that interferes with something else. I really do want line breaks!
Last edited by John_Ha on Fri Feb 14, 2014 4:22 pm, edited 1 time in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Replace paragraph break with line break (soft return)

Post by acknak »

John_Ha wrote:I would like to replace all paragraph breaks (enter) with line breaks (shift/enter). Is there an expression for line break in the Replace box? ...
No--that's the only problem.

OO running on Linux will accept a literal "line feed" character in the "replace with" field, but not on WIndows or Mac.

Hmm ... a simple workaround just occurred to me and it seems to work just fine:

Enter a line break normally and copy it to the clipboard

Edit > Find & Replace
Search for: $
Options/Regular expressions: ON
Click "Find All"

Edit > Paste
AOO4/LO5 • Linux • Fedora 23
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Replace paragraph break with line break (soft return)

Post by JohnV »

Very slick, acknak! A new solution to a very old problem.
User avatar
MrProgrammer
Moderator
Posts: 5266
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Replace paragraph break with line break (soft return)

Post by MrProgrammer »

acknak wrote:OO running on Linux will accept a literal "line feed" character in the "replace with" field, but not on WIndows or Mac.
Macs can easily insert a line feed in the Replace With box using the Mac's Show Character Viewer feature. It works with any application.
Screen shot 2014-02-13 at 20.25.21 .png
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Replace paragraph break with line break (soft return)

Post by acknak »

Oops :oops: Trying to write from memory again. Thanks!

It may work on Windows too, now. It's been a long time (WinXP) since I checked.
AOO4/LO5 • Linux • Fedora 23
John_Ha
Volunteer
Posts: 9599
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Replace paragraph break with line break (soft return)

Post by John_Ha »

acknak wrote:Hmm ... a simple workaround just occurred to me and it seems to work just fine:
acknak
Thanks - that is very neat. All I need to get that to work in a macro is a way to load the clipboard with the copied line break ...

I have tried all possible ways using Find and replace, but the Replace box always refuses to recognise the copied soft line break, and does not accept \x000A or \#09, so it pastes a nul, which effectively deletes the paragraph return. I have the Alt Find & Replace add-on which does exactly what I want using \n as the Replace term so I looked inside the add-on and I think the actual expression it uses (line 3553) is as below (I hope your Czech is better than mine!):

Code: Select all

    case "t" ' vložit tabulator
       prCurs.string = chr(9)  ' vlozit text
       prCurs.collapseToEnd
       
    case "n" ' vložit line break 
       prCurs.text.insertControlCharacter(prCurs, com.sun.star.text.ControlCharacter.LINE_BREAK, false )
       prCurs.collapseToEnd

    case "S" ' vlozit pevnou mezeru 
       prCurs.text.insertControlCharacter(prCurs, com.sun.star.text.ControlCharacter.HARD_SPACE, false )
       prCurs.collapseToEnd
where I think the first case replaces with a tab, the second case with a Line break and the third case with a Hard space. But I am not sure how to put the com.sun.star.text.ControlCharacter.LINE_BREAK into a macro.

I tried to record a macro when I used Alt Find & Replace. It did the changes I want, but the Stop Recording window disappeared and I couldn't save what I had recorded.

I think I will have to use your method (or Alt Find & Replace) manually after the macro has run doing everything else.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Post Reply