Front-End Syntaxes

Last modified by superadmin on 2026/12/04 14:25

Content

Syntax configuration components, which declare the features a syntax allows to the editor, with Markdown as example.

Reference

Syntaxes can be declared as components and registered in the dependency injection service. The editor will automatically pick all the registered syntaxes through the container.

Example definition for the Markdown syntax:

import { injectable } from "inversify";
import type {
  SyntaxAllowedFeatures,
  SyntaxConfig,
} from "@xwiki/platform-syntaxes-config";

/**
 * Configuration for the `markdown/1.2` syntax
 *
 * @since 18.6.0RC1
 * @beta
 */
@injectable()
export class MarkdownSyntaxConfig implements SyntaxConfig {
  id = "markdown/1.2";

  features: SyntaxAllowedFeatures = {
    blocks: {
      headings: {
        levels1To3: true,
        levels4To6: true,
      },
      images: {
        basicImages: true,
        altText: true,
        caption: true,
        customBorder: false,
        customDimensions: false,
        insideLinks: true,
      },
      lists: {
        bulletLists: true,
        blockInListItems: true,
        checkableLists: true,
        contiguousNumberedLists: true,
        contiguousNumberedListsAnyStartIndex: true,
        mixableCheckableListItems: false,
        multipleBlocksInListItems: true,
        unorderedNumberedLists: false,
        listsNesting: true,
      },
      quotes: true,
      code: {
        basicCodeBlocks: true,
        language: true,
      },
      dividers: true,
      macros: true,
      nesting: true,
      styling: {
        justifyAlignment: false,
        lcrAlignment: false,
      },
      tables: {
        basicTables: true,
        blockInTableCells: false,
        colRows: false,
        colSpan: false,
        headerColumns: false,
        multipleBlocksInTableCells: false,
        multipleFooterRows: false,
        multipleHeaderRows: false,
        noHeaderRowTable: false,
        singleFooterRow: false,
        singleHeaderRow: true,
      },
    },
    inlineContents: {
      images: true,
      links: {
        basicLinks: true,
        customText: true,
        customTextStyling: true,
        descriptiveTooltip: true,
        metadata: false,
      },
      code: {
        basicInlineCode: true,
        language: false,
      },
      macros: true,
      rawHtml: true,
      textStyles: {
        bold: true,
        italic: true,
        strikethrough: true,
        underline: true,
        nesting: true,
        fontFamily: false,
        fontSize: false,
        subscript: true,
        superscript: true,
      },
    },
  };
}

To register the syntax:

import { MarkdownSyntaxConfig } from "./config";
import { SYNTAX_CONFIG_COMPONENT_GROUP_NAME } from "@xwiki/platform-syntaxes-config";
import { Container } from "inversify";

/**
 * @since 18.6.0RC1
 * @beta
 */
export class ComponentInit {
  constructor(container: Container) {
    container.bind(SYNTAX_CONFIG_COMPONENT_GROUP_NAME).to(MarkdownSyntaxConfig);
  }
}

 

Get Connected