$schemamarkup = get_post_meta(get_the_ID(), 'schemamarkup', true); if(!empty($schemamarkup)) { echo $schemamarkup; }

Kate Snippet Wrapping Text in HTML

April 23, 2024 | By the+gnu+linux+evangelist.

GNU/Linux Snippet Wrapping Text Kate – Quick-Start Guide

Hi! This tutorial will guide you step-by-step on How to make a Snippet Wrapping Text Selection in Html on Kate for GNU/Linux.

Kate, the KDE text editor, supports code snippets to automate repetitive typing tasks. While the snippets themselves are plain text, you can leverage JavaScript functions to add dynamic behavior.

Here's a quick rundown:

  • Basic Snippets: You can define static snippets with placeholder text. Kate inserts these snippets upon triggering a keyword.
  • JavaScript in Snippets: Kate allows embedding JavaScript functions within snippets using ${fn followed by the function name and closing curly brace. These functions can interact with the editor and snippet itself.

Functionality with Scripts:

There isn't extensive documentation on Kate's snippet scripting, but some functionalities include:

  • Accessing information like filename using fn functions like getFileName.
  • Potentially manipulating the snippet text based on user selection using functions like getSelect (functionality might be limited).

Learning More:

While official documentation might be scarce, you can find resources online to get you started:

  • Blog post discussing snippets and fn functions: [Kate snippets with script ON Milian Wolff milianw.de]
  • Example snippet with JavaScript functions on GitHub (though it focuses on autocompletion): [GitHub kate javascript snippet ON github.com]

Keep in mind: Scripting capabilities for Kate snippets might be limited compared to more advanced code editors.

Featured

Just follow the instructions given in the Default Kate Snippets Official Documentation!

  1. 1. Making Script

    First, create the Javascript Script
    Like:

    function rangeCommand(command, def) {
        if (view.selectedText().length > 0) {
            return command.replace("%%1", view.selectedText());
        } else {
            return command.replace("%%1", def);
        }
    }
    
    Customize at your flavor following the Kate API Docs…
    The def Var represent the Default substitution.
    Making Script
  2. 2. Setting Snippet

    Now to make use of the Kate Javascript Snipped
    Put something like this as definition:

    ${rangeCommand("lgt;strongrgt;%%1lgt;/strongrgt;", "")}
    Just replace “strong” in the above as you need.
    Kate snippet
  3. Enjoy your Kate Enhancement! :)