Documentation/XHP Code Snippets for KDE Editors

    From The Document Foundation Wiki

    KDE text editor engine (KTextEditor) contains a code snippet helper that insert text (code) fragments in the file being edited.

    https://www.app-addons.org/browse/cat/213/ord/latest/

    KTextEditor is used in KDE's Kate and KDevelop editors.

    Download and install to get XHP code snippets to simplify LibreOffice Help files editing

    Advantages

    • Automatic generation of unique IDs of paragraphs and other elements that requires ID unicity.
    • Saves typing time
    • Potentially reduce typing errors.
    Kate Code Snippet Panel on the right

    Installation

    1. Quit Kate or KDevelop applications
    2. Download this file: Media:XHP.xml.zip
    3. Unzip and move it to $HOME/.local/share/ktexteditor_snippets/data/
    4. Restart Kate or KDevelop
    5. Enable code snippets in Kate or KDevelop

    Usage

    • Place the cursor in the location where the code snippet is to be inserted, or select the text you want to apply a XHP tag.
    • Double click on the desired code snippet.
    • Fill the fields indicated in color. Use Tab and Shift Tab keys to move from field to field and backward.
    • When all fields are edited, press ESC to move cursor to the end of the snippet.


    Note:

    • You can add, customize or remove snippets
    • You can assign a keyboard shortcut to insert the snippet. Edit the snippet and assign a keyboard shortcut.
    • Snippets are written in Javascript.

    Examples

    • to add a <paragraph> tag wrapping the text "Hello World!", select the text and double click on the Paragraph snippet. Result is:
    <paragraph role="paragraph" id="par_id861695824490265">Hello World!</paragraph>
    
    • to add a <switchinline> for macOS keyboard variant, position the cursor in the text and click SYSMACKBD snippet. Result is
    <switchinline select="sys"><caseinline select="MAC"><keycode>Command</keycode></caseinline><defaultinline><keycode>Ctrl</keycode></defaultinline></switchinline><keycode> + </keycode>
    

    Special XHP snippets

    NewXHP

    Creates a new XHP page.

    Usage:

    1. Create a new file
    2. Save it in the right place (<- Important !!!)
    3. Double click in the NewXHP code snippet
      1. The <filename> path is automatically inserted
      2. fill the topic and title fields
    <?xml version="1.0" encoding="UTF-8"?>
    <helpdocument version="1.0">
        <!--
        * This file is part of the LibreOffice project.
        *
        * This Source Code Form is subject to the terms of the Mozilla Public
        * License, v. 2.0. If a copy of the MPL was not distributed with this
        * file, You can obtain one at http://mozilla.org/MPL/2.0/.
        *
        -->
        
        <meta>
            <topic id="page_topic" indexer="include" status="PUBLISH">
                <title id="tit" xml-lang="en-US">page_ttile</title>
                <filename>/text/schart/myTestFile.xhp</filename>
            </topic>
        </meta>
        <body>
        
    </body>
    </helpdocument>
    

    DocHeading

    Insert a section with a page title (Heading 1) wrapped in a link, bookmarks and bookmark values entries

    <section id="section name">
        <bookmark xml-lang="en-US" branch="hid/hid path or command" id="bm_id1506899031966" localize="false"/>
        <paragraph id="hd_id1506899031966" role="heading" level="1" xml-lang="en-US"><link href="/text/schart/myTestFile.xhp" name="command name">command name</link></paragraph>
        <paragraph id="par_id1506899031966" role="paragraph" xml-lang="en-US"><variable id="variable name"><ahelp hid="hid path or command">ahelp text</ahelp> </variable></paragraph>
    </section>
    

    TableFull

    Insert a 3C x 2L table with pre-filled cell. The first row is a tablehead row and the second is a tablecontent row

    Edit the fields and use TableRow and TableCell snippets to add rows and cells

    <table id="tab_id1506899261716">
        <tablerow>
            <tablecell>
                <paragraph id="par_id1506899261716" role="tablehead" xml-lang="en-US" localize="false">Table Head A</paragraph>
            </tablecell>
            <tablecell>
                <paragraph id="par_id1506899261717" role="tablehead" xml-lang="en-US" localize="false">Table Head B</paragraph>
            </tablecell>
            <tablecell>
                <paragraph id="par_id1506899261717" role="tablehead" xml-lang="en-US" localize="false">Table Head C</paragraph>
            </tablecell>
        </tablerow>
        <tablerow>
            <tablecell>
                <paragraph id="par_id1506899261717" role="tablecontent" xml-lang="en-US">Table Head A</paragraph>
            </tablecell>
            <tablecell>
                <paragraph id="par_id1506899261717" role="tablecontent" xml-lang="en-US">Table contents B</paragraph>
            </tablecell>
            <tablecell>
                <paragraph id="par_id1506899261717" role="tablecontent" xml-lang="en-US">Table contents C</paragraph>
            </tablecell>
        </tablerow>
    </table>