Downgrade all headings inside selected text in LibreOffice Writer

If you’ve ever pasted or imported text into LibreOffice Writer from another source, you might have run into a common formatting headache:
the headings are all too high in the hierarchy.

For example, what should be a “Heading 2” in your document appears as “Heading 1,” bumping your outline out of balance and making your document structure harder to follow.

Why this happens

When content comes from another program — such as a web page, Markdown editor, or PDF — LibreOffice tries to match the original formatting to its built-in paragraph styles. It doesn’t always guess correctly, and often everything gets assigned to the top-level heading style.

The result: your imported section titles are at the wrong outline level, and fixing them manually means tediously selecting each heading and changing it one at a time.

A faster, smarter approach

You can save time by using a small LibreOffice macro that:

  • Works only on the selected text, leaving the rest of your document untouched.
  • Detects built-in heading styles (in English or Finnish).
  • Shifts every heading in the selection down one level — for example, Heading 1 becomes Heading 2, Heading 2 becomes Heading 3, and so on.
  • Keeps both the paragraph style and the document outline structure in sync.

How it works

The macro loops through each paragraph in your selection.
If it finds a heading style, it replaces it with the next-level heading style and adjusts the outline level property so that your Navigator view stays accurate.

This makes it ideal when:

  • You’ve pasted content that should be subordinate to your main document’s headings.
  • You need to merge multiple documents without breaking the hierarchy.
  • You’re working with structured outlines that must remain consistent.

The benefits

With one quick run, you can:

  • Preserve the original heading hierarchy while fitting it into your existing document.
  • Avoid manual, repetitive style changes.
  • Keep your outline and navigation tools accurate and easy to use.

How to Create and Run the Heading-Downgrade Macro in LibreOffice Writer

Follow these steps to add the macro to LibreOffice Writer and use it on your selected text.


1. Open the LibreOffice Macro Editor

  1. In LibreOffice Writer, go to Tools → Macros → Organize Macros → LibreOffice Basic.
  2. In the dialog that appears, select either:
    • My Macros → Standard (makes the macro available in all documents), or
    • Your current document (macro will be saved only with this file).
  3. Click New to create a new module, then give it a name (e.g., HeadingTools).

2. Paste the Macro Code

  1. In the macro editor window, delete any sample code that’s there.
  2. Paste the full macro code into the window (you’ll provide the code in your blog post).
  3. Click the Save icon or press Ctrl+S.
  4. Close the macro editor.

3. Run the Macro

  1. In your Writer document, select the text whose headings you want to downgrade.
  2. Go to Tools → Macros → Run Macro….
  3. In the dialog, navigate to the module where you saved the macro, select DowngradeSelectedHeadings, and click Run.
  4. All headings in your selection will shift down by one level.

The code to paste:

Option Explicit

' --- Utilities ---
Private Function HasUnoProperty(o As Object, propName As String) As Boolean
    On Error GoTo EH
    HasUnoProperty = o.getPropertySetInfo().hasPropertyByName(propName)
    Exit Function
EH:
    HasUnoProperty = False
End Function

Private Function DemoteHeadingStyleName(ByVal s As String) As String
    ' Downgrade “Heading n” (EN) or “Otsikko n” (FI) by one level
    Dim prefixes(1) As String
    prefixes(0) = "Heading"
    prefixes(1) = "Otsikko"

    Dim i As Integer
    For i = LBound(prefixes) To UBound(prefixes)
        Dim pre As String : pre = prefixes(i)
        If Left$(s, Len(pre) + 1) = pre & " " Then
            Dim lvl As Integer : lvl = Val(Mid$(s, Len(pre) + 2))
            If lvl >= 1 And lvl < 10 Then
                DemoteHeadingStyleName = pre & " " & (lvl + 1)
            Else
                DemoteHeadingStyleName = s
            End If
            Exit Function
        End If
    Next i
    DemoteHeadingStyleName = ""  ' not a built-in heading style
End Function

' --- Main ---
Sub DowngradeSelectedHeadings()
    Dim oSel As Object
    oSel = ThisComponent.getCurrentSelection()
    If IsNull(oSel) Then Exit Sub

    If oSel.supportsService("com.sun.star.text.TextRanges") Then
        Dim i As Integer
        For i = 0 To oSel.getCount() - 1
            DemoteInRange oSel.getByIndex(i)
        Next i
    ElseIf oSel.supportsService("com.sun.star.text.TextRange") Then
        DemoteInRange oSel
    Else
        MsgBox "Please select text in Writer.", 64, "Downgrade headings"
    End If
End Sub

Private Sub DemoteInRange(oRange As Object)
    Dim oText As Object, oCursor As Object, oEnum As Object
    oText = oRange.getText()

    ' Create a cursor that spans exactly the selection
    oCursor = oText.createTextCursorByRange(oRange)
    oCursor.gotoRange(oRange.getEnd(), True)

    ' Enumerate paragraphs within the selection
    oEnum = oCursor.createEnumeration()
    Do While oEnum.hasMoreElements()
        Dim oPara As Object
        oPara = oEnum.nextElement()

        ' Safety: only handle real paragraphs
        If oPara.supportsService("com.sun.star.text.Paragraph") Then
            ' 1) Demote outline level if present
            If HasUnoProperty(oPara, "ParaOutlineLevel") Then
                Dim lvl As Integer
                lvl = oPara.ParaOutlineLevel
                If lvl >= 1 And lvl < 10 Then
                    oPara.ParaOutlineLevel = lvl + 1
                End If
            End If

            ' 2) Demote built-in heading style names (EN/FI)
            If HasUnoProperty(oPara, "ParaStyleName") Then
                Dim s As String, sNew As String
                s = oPara.ParaStyleName
                sNew = DemoteHeadingStyleName(s)
                If sNew <> "" Then oPara.ParaStyleName = sNew
            End If
        End If
    Loop
End Sub

Where is the default SyncThing folder in Windows

Syncthing is a great program for file sync between devices.

When you set it up on a new device, it can sometimes be a bit difficult to find a folder that you have shared with the new device in the actual file system. The path might by default look like ~MyFolderName

That actually translates on Windows to C:\Users\SyncthingServiceAcct

So go into that folder and you will be able to find your SynchThing files!

How to pause browser execution when F8 is not working

Let’s break down a simple trick that can help you manipulate and understand your code better.

To begin with, access your developer console. This can usually be found in your browser’s Developer Tools under the ‘Console’ tab. Depending on the browser you’re using, you might need to use different shortcuts (like F12) or methods to open it. But don’t worry, a quick search on how to open the developer console in your specific browser should get you on the right track.

Once you’ve opened the console, the next step involves entering a particular command. All you need to do is simply paste the provided command line in the console. This is what we’re going to use to manipulate our code. After pasting the command, hit the ‘Enter’ key to execute it.

document.addEventListener('keydown', function (e) {

if (e.keyCode == 119) { // F8

debugger;

}

}, {

capture: true

});

Now, your code should still be in an ‘unpaused’ state. But when you press F8 on the keyboard, it should pause. It’s like freezing a moment in time, letting you thoroughly inspect and understand how your code behaves for specific elements. This can be especially useful when debugging hover-effects and mouseovers.

With this simple trick, your web development toolkit has a new superpower! Experiment, explore, and let your code reveal its secrets to you. Happy coding!”

Google Family Link: After Unlocking your child’s device with parental access, how do you re-lock it?

I have been using Google Family Link recently in order to keep my child’s mobile phone online while safeguarding it against mature content.

Sometimes I have logged in to the device using the parent access code and that has brought up a question that doesn’t seem to have great answers in the manual of this software: How does one logout from the child’s device after accessing it with the family link parent code?

Here’s the answer: in order to quit accessing the child’s device as a parent, go to the Google Family Link app on the parent’s device and right beneath the circular image on the top, there should be your child’s device listed. Click on the name of the device and click on “lock”. Now the device should only be available if there is screen time left and the time is withing the allowed time limits.