Skip to content

Grouped extensions

Falcion edited this page Jan 26, 2025 · 3 revisions

Grouped extensions functionality may be one of the most advanced user features one can imagine. The concept is very simple but becomes quite advanced in practice—it allows you to assign ANY view registered in Obsidian to an array of extensions, supporting case-insensitive mode in the hierarchy of views-extensions.

This means you can assign any array of extensions to even multiple views (although it's not the most efficient way to "play" with this setting). You can assign different views for default extensions (for example, render .md as video or audio). You can even input pdf/mp4 data into a x/text (txt) file, ask the plugin to render it as pdf/video, and it will work.

Practice

The syntax of grouped extensions is not in JSON or any programming format, making it easy for users unfamiliar with coding. It looks like this:

markdown: json> txt> pgb; pdf: pdf; video: webm;

Note

More about views, registries and etc. read at knowledge base page: "About views and registries"

Possible views (and their ids), both default and custom (by UNITADE) can be checked in specified page: https://github.com/Falcion/UNITADE.md/wiki/Views-and-their-extensions

Let's break this input down:

  1. The symbols before the colon (:) are the views from the Obsidian registry, such as the pdf and markdown views. These are called "key-views."
  2. The array of extensions, separated by the > symbol, represents the extensions that will be rendered as "key-views." For example, json will be rendered as markdown (the default view for .md files in Obsidian).
  3. The semicolon (;) is used to "end" a view group, indicating the start of the next group and its assigned extensions for the "key-views."

Note

For "grouped extensions" to work, you need to enable a specified toggle. This allows you to first configure advanced arrays of views-extensions and then enable them, ensuring they render correctly without error spamming, like in the "vanilla" or mobile extensions input.

It uses some supporting functions, which are not as complex as the "case-insensitive mode" (the example may differ from the source):

/**
 * Parses an input string into a key-value group structure, where each group is separated by a semicolon (`;`)
 * and keys are separated from values by a colon (`:`). Values can be further split by the `>` character.
 * 
 * @param {string} input - The input string to parse into key-value groups.
 * @returns {{ [key: string]: string[] }} - An object where each key has an array of values.
 * 
 * @example
 * const result = parsegroup("group1:val1>val2;group2:val3");
 * console.log(result); 
 * // {
 * //   group1: ['val1', 'val2'],
 * //   group2: ['val3']
 * // }
 */
export function parsegroup(input: string): { [key: string]: string[] } {
    const settings: { [key: string]: string[] } = {};

    const settings_parsed = input.split(';');

    for (const setting of settings_parsed) {
        const [key, values] = setting.trim().split(':').map(x => x.trimStart());

        if (values !== undefined) {
            const arr_values = values.split('>');

            settings[key.trim()] = arr_values;
        } else {
            settings[key.trim()] = [];
        }
    }

    return settings;
}

Minor features

Grouped extensions not only support default views but also any custom view, as long as it has a key name and is registered in the Vault. This allows UNITADE to potentially integrate with other plugins.

  • You can also assign the "code view" (from the "code editor module") as the view for your custom extensions, allowing you to use its features without enabling the "code editor module" itself.
Clone this wiki locally