New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.0.2

@eigenpal/docx-editor-core/prosemirror/template/prosemirror-plugin

Template ProseMirror Plugin

Simple plugin that finds template tags using regex and creates decorations. No separate parsing layer - everything happens here.

Functions(4)

Create the template plugin

declare function createTemplatePlugin(): Plugin<TemplatePluginState>;

Get tags from editor state

declare function getTemplateTags(state: prosemirror_state.EditorState): TemplateTag[];

Set hovered tag

declare function setHoveredElement(view: EditorView, id: string | undefined): void;

Set selected tag

declare function setSelectedElement(view: EditorView, id: string | undefined): void;

Interfaces(1)

A found template tag

interface TemplateTag
MemberTypeSummary
fromnumber
idstring
insideSection?booleanTrue if this variable is inside a section (shown in section's nested vars)
namestring
nestedVars?string[]For sections: nested variable names
rawTagstring
tonumber
typeTagType

Type aliases(1)

Template tag types

type TagType = 'variable' | 'sectionStart' | 'sectionEnd' | 'invertedStart' | 'raw';

Variables(2)

CSS styles for template decorations

TEMPLATE_DECORATION_STYLES = "\n.docx-template-tag {\n  cursor: pointer;\n  transition: background-color 0.1s;\n}\n\n.docx-template-tag:hover,\n.docx-template-tag.hovered {\n  filter: brightness(0.95);\n}\n\n.docx-template-tag.selected {\n  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);\n}\n"

Plugin key

templatePluginKey: PluginKey<TemplatePluginState>