I hit the classic Writer issue: want to turn hard paragraph breaks (Enter/¶) into soft line breaks (Shift+Enter/↵). Ctrl+H/regex looks like it should work, but in practice it is inconsistent, and a global replace can also mess with headers/footers.

If you prefer a transparent solution over an extension, here is a small LibreOffice Basic macro that works on the current selection only, and walks backwards so it does not skip paragraphs:

+++ CODE
Sub ParagraphsToLineBreaks
    Dim oDoc As Object, oSel As Object, oRng As Object
    Dim oText As Object, oEnum As Object
    Dim aEnds() As Object
    Dim n As Long, i As Long
    Dim oPara As Object, c As Object

    oDoc = ThisComponent
    oSel = oDoc.getCurrentController().getSelection()

    If oSel.getCount() = 0 Then Exit Sub
    oRng = oSel.getByIndex(0)

    oText = oRng.getText()
    oEnum = oRng.createEnumeration()

    n = 0
    While oEnum.hasMoreElements()
        oPara = oEnum.nextElement()
        ReDim Preserve aEnds(n)
        aEnds(n) = oPara.End
        n = n + 1
    Wend

    For i = n - 2 To 0 Step -1
        c = oText.createTextCursorByRange(aEnds(i))
        On Error Resume Next
        c.goRight(1, True)     ' select ¶
        If Err = 0 Then
            c.String = Chr(10) ' replace with ↵
        End If
        Err = 0
        On Error GoTo 0
    Next i
End Sub
+++ END OF CODE

Usage: select only the body text you want to convert (or copy selection into a new doc first), then run the macro. Non-printing chars: Ctrl+F10 (¶ vs ↵).

Full note/explanation: https://lab.vanderworp.org/notes/writer-replace-paragraph-with-line-break/

--
To unsubscribe e-mail to: [email protected]
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy

Reply via email to