Skip to content

Documentation / RSML npm

RSML npm Package

Client-side annotation UI widget and syntax engine for Rich Speech Markup Language.

What the package does

The published rsml package provides RSMLAnnotator, a ready-to-use editor widget for browsers. It connects a source textarea to a live preview pane, provides tag auto-completion and syntax highlighting, and supports switching between verbatim and normalized views. When attached to a <textarea> and a preview container, it handles:

  • Real-time parsing and rendering: Transforms raw RSML tokens (like @umm, #ORG[गूगल](Google) and !en[office](office)) into styled interactive badges.
  • Dual-mode preview: Lets annotators toggle between Normalized and Verbatim views, with an optional switch to hide disfluencies.
  • Smart editor enhancements: Upgrades the textarea with CodeMirror 6 when it can be loaded, for inline tag highlighting and trigger-based auto-complete (@, #, !, $, $$, !!).
  • Source jumping: Double-clicking any rendered token focuses the caret on the exact tag span in the editor.

When to use it

Reach for it whenever you are building an annotation portal, a transcription verification UI, or reviewing multilingual speech dataset labels in React, Vue, or vanilla web apps.

Installation

Install with your package manager, or load it from a CDN.

Package manager

npm
npm install rsml
yarn
yarn add rsml
pnpm
pnpm add rsml

CDN (no build step)

Import the ES module directly in a browser:

<script type="module">
  import RSMLAnnotator from "https://cdn.jsdelivr.net/npm/rsml@latest/rsml.esm.js";
</script>

In production, replace @latest with an exact version so that a new release cannot change your app unexpectedly.

TypeScript

The package does not ship type declarations. In a TypeScript project, declare the module once:

rsml.d.ts
declare module "rsml";

Getting Started

All you need are two DOM nodes: a textarea for typing and a container for rendered output.

Minimal quick start

index.html
<textarea id="editor" rows="8" placeholder="Type @ for tags, # for entities..."></textarea>
<div id="preview" style="min-height: 120px; border: 1px solid #ddd; padding: 12px;"></div>

<script type="module">
  import RSMLAnnotator from "https://cdn.jsdelivr.net/npm/rsml@latest/rsml.esm.js";

  const annotator = new RSMLAnnotator({
    textarea: "#editor",
    output: "#preview",
    demoText: true,
  });
</script>

With a bundler (Vite, webpack, Next.js), install the package and use import RSMLAnnotator from "rsml" instead of the CDN URL.

Type @ for tags, # for entities and ! for languages.

Usage

Extend the vocabulary, mark dialects and domains, and control the preview.

Extending the vocabulary

Every configurable tag, entity or language list can be grown after construction with add(category, value, label) and remove(category, value). An already-open editor picks up the change immediately, with no re-render or retyping needed.

annotator.add("hesitations", "@meh");
annotator.add("entities", "PRODUCT", "Product Name");
annotator.add("languages", "kok", "Konkani");
annotator.remove("entities", "PRODUCT");
Vocabulary categories
categoryvaluelabel
hesitationsan @tag (with or without the @)—
isolatedParalinguisticsan @tag—
isolatedOtheran @tag—
disfluencySpansa span base name (no @, no -start/-end)—
paralinguisticSpansa span base name—
prosodySpansa span base name—
entitiesa #-prefixed entity type codedisplay label (optional)
languagesa !-prefixed language codedisplay label (optional)
dialectsa $$-prefixed dialect codedisplay label (optional)
domainsa !!-prefixed domain codedisplay label (optional)

add and remove return true if they changed something and false for a no-op (for example, removing a name that was never registered). They throw on an unknown category, an invalid or empty value, or, for the @tag and span families (each shares one namespace across its sibling categories), a name already registered under a different category in that family.

Dialect and domain markup

Alongside ! (code-mix / language) and # (entity), two more bracket prefixes are available, each backed by its own vocabulary:

annotator.add("dialects", "TG", "Telangana Telugu");
annotator.add("domains", "MED", "Medical");

// Source text:
// $$TG[వస్తున్నా](వస్తున్నాను)
// !!MED[BP](రక్తపోటు)

The type code after the prefix is optional: $$[…](…) and !![…](…) render as an unspecified dialect or domain.

Display settings

A settings button next to the Verbatim/Normalized switch opens a popup with a Hide disfluencies checkbox, which is on by default. It hides hesitations, disfluency spans and the other isolated tags in the rendered output. The source text is untouched, so toggling it never loses anything.

A repair span written with the reparandum - repair convention is a special case: only the reparandum and separator are hidden, keeping the corrected text visible. A repair span without the separator is hidden wholesale.

Source:  @repair-start ఢిల్లీ కాదు - ముంబై @repair-end వెళ్ళాను.
Shown (disfluencies visible): ఢిల్లీ కాదు - ముంబై వెళ్ళాను.
Shown (disfluencies hidden):  ముంబై వెళ్ళాను.

API Reference

Constructor options and instance methods of RSMLAnnotator.

new RSMLAnnotator(options)

Initializes the annotator, injects its core styles into the document head and binds listeners. It throws if textarea or output cannot be found. Passing a list or map option replaces its default; use add() to extend it instead.

Constructor options
OptionTypeDefaultDescription
textarea (required)string | HTMLTextAreaElement—Source textarea selector or element.
output (required)string | HTMLElement—Preview container selector or element.
demoTextbooleanfalsePopulate the textarea with a sample Hindi utterance.
disableCodeMirrorbooleanfalseSkip loading CodeMirror from the CDN and keep the plain textarea.
editorFontFamilystringtextarea fontFont family used by the CodeMirror editor.
hesitationsstring[]@umm, @uhh, @hmm, …Isolated hesitation tokens.
isolatedParalinguisticsstring[]@laughter, @cough, …Isolated non-verbal sounds.
isolatedOtherstring[]@unintelligible, @stutter-block, @short-pause, @long-pauseOther isolated tokens.
disfluencySpansstring[]filler, repetition, broken-word, repair, false-start, prolongationSpan base names, without @ or -start/-end.
paralinguisticSpansstring[]crying, yelling, laughing, singing, humming, whistling, whispering, chantingSpan base names.
prosodySpansstring[]emphasis, falling-pitch, raising-pitch, high-pitch, low-pitch, fast-speech, slow-speechSpan base names.
entitiesRecord<string, string>20 types (PER, GPE, ORG, …)Entity codes mapped to labels for #TYPE markup.
languagesRecord<string, string>23 codes (en, hi, te, …)Language codes mapped to names for !lang markup.
dialectsRecord<string, string>{}Dialect codes mapped to names for $$dialect markup.
domainsRecord<string, string>{}Domain codes mapped to names for !!domain markup.

Instance methods

Instance methods
MethodDescription
getValue(): stringReturns the current raw RSML text.
setValue(text: string): voidReplaces the editor content, syncs CodeMirror if active, and re-renders.
add(category, value, label?): booleanRegisters a tag or code without re-mounting.
remove(category, value): booleanUnregisters a tag or vocabulary entry.
undo()Undoes the last edit. Only has an effect when CodeMirror is active.
redo()Redoes the last undone edit. Only has an effect when CodeMirror is active.
destroy(): voidRemoves listeners, destroys the CodeMirror instance and removes the status bar.

Examples

Copy-pasteable integrations for common setups.

React + TypeScript

In React (Next.js, Vite, or similar), initialize inside a useEffect. RSML requires browser DOM APIs, so run it on the client and always clean up with annotator.destroy() on unmount. Wrap onChange in useCallback so the editor is not recreated on every render.

RsmlEditor.tsx
"use client";

import React, { useEffect, useRef } from "react";
// rsml publishes ESM default export: RSMLAnnotator
import RSMLAnnotator from "rsml";

interface RsmlEditorProps {
  initialValue?: string;
  onChange?: (value: string) => void;
}

export function RsmlEditor({ initialValue, onChange }: RsmlEditorProps) {
  const textareaRef = useRef<HTMLTextAreaElement | null>(null);
  const outputRef = useRef<HTMLDivElement | null>(null);
  const annotatorRef = useRef<any>(null);

  useEffect(() => {
    // Ensure both DOM nodes exist and prevent duplicate initialization (e.g. React StrictMode)
    if (!textareaRef.current || !outputRef.current || annotatorRef.current) {
      return;
    }

    const annotator = new RSMLAnnotator({
      textarea: textareaRef.current,
      output: outputRef.current,
      demoText: false,
    });

    annotatorRef.current = annotator;

    if (initialValue) {
      annotator.setValue(initialValue);
    }

    // Optional listener to bubble text changes back to React state
    const handleInput = () => {
      onChange?.(annotator.getValue());
    };
    textareaRef.current.addEventListener("input", handleInput);

    return () => {
      textareaRef.current?.removeEventListener("input", handleInput);
      annotator.destroy();
      annotatorRef.current = null;
    };
  }, [initialValue, onChange]);

  return (
    <div style={{ display: "flex", gap: "1.5rem", flexWrap: "wrap", width: "100%" }}>
      <div style={{ flex: 1, minWidth: "300px" }}>
        <label htmlFor="rsml-source">RSML Source Editor</label>
        <textarea
          id="rsml-source"
          ref={textareaRef}
          rows={10}
          placeholder="Type @ for tags, # for entities, ! for languages..."
          style={{ width: "100%", padding: "0.75rem", fontFamily: "monospace" }}
        />
      </div>

      <div style={{ flex: 1, minWidth: "300px" }}>
        <span>Live Preview</span>
        <div
          ref={outputRef}
          style={{ minHeight: "220px", maxHeight: "350px", overflowY: "auto", padding: "0.75rem" }}
        />
      </div>
    </div>
  );
}

Plain HTML with Bootstrap

index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>RSML Example</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css" />
</head>
<body>
  <div class="container mt-4">
    <div class="row mt-3">
      <div class="col-12 col-md-6 mb-3 mb-md-0">
        <textarea id="tag-textarea" class="form-control" rows="10"
          placeholder="Type @ for tags, # for entities, ! for languages..."></textarea>
      </div>
      <div class="col-12 col-md-6">
        <div id="rendered-transcript" class="card p-3"
          style="height: 250px; overflow-y: auto; background: #f9f9f9"></div>
      </div>
    </div>
  </div>

  <script type="module">
    import RSMLAnnotator from "https://cdn.jsdelivr.net/npm/rsml@latest/rsml.esm.js";

    new RSMLAnnotator({
      textarea: "#tag-textarea",
      output: "#rendered-transcript",
    });
  </script>
</body>
</html>

Configuration

Setup notes and common pitfalls when embedding the annotator in production.

Server-side rendering: rsml.js relies on browser globals (window, document, DOMParser). In the Next.js App Router, mark the component "use client" or import it dynamically with ssr: false.

CodeMirror CDN and strict CSP

By default the annotator dynamically imports CodeMirror modules from https://esm.sh. Behind a strict Content Security Policy, or offline, disable it. The annotator then uses the native textarea, with live preview and validation still working.

new RSMLAnnotator({
  textarea: "#editor",
  output: "#preview",
  disableCodeMirror: true,
});

Option defaults are listed in the API reference.

Tooltips (optional Bootstrap)

Hover tooltips on entity chips use window.bootstrap.Tooltip. If Bootstrap JS is on the page they initialize automatically; otherwise chips show standard HTML titles without errors.

Duplicate instances in React StrictMode

React 18+ mounts effects twice in development. Store the instance in a ref, check that none exists before calling new RSMLAnnotator(), and call annotator.destroy() in the effect cleanup.