API / @aihu-plugin/kindly-note

@aihu-plugin/kindly-note

Plugins

Runtime syntax highlighting + markdown rendering for aihu — <aihu-code>/<aihu-markdown> custom elements + signal-aware highlight()/renderMarkdown() helpers, powered by published @kindly-note/* packages with lazy loading.

version
0.2.2
exports
17
values
11
types
6
01

defineCodeElement

function
function defineCodeElement(): string

Register the `<aihu-code>` custom element.

02

defineMarkdownElement

function
function defineMarkdownElement(): string

Register the `<aihu-markdown>` custom element.

03

ensureLanguage

function
async function ensureLanguage(lang: string): Promise<string | null>

Ensure the tokenizer for `lang` is loaded and registered with the shared highlighter.

04

getAihuCodeElement

function
function getAihuCodeElement(): AihuCodeElementConstructor

Lazily build (and memoize) the `<aihu-code>` class.

05

getAihuMarkdownElement

function
function getAihuMarkdownElement(): AihuMarkdownElementConstructor

Lazily build (and memoize) the `<aihu-markdown>` class.

06

highlight

function
async function highlight(source: string, lang: string): Promise<HighlightOutput>

Highlight `source` as `lang` at runtime, returning scoped-span HTML.

07

isLanguageRequested

function
function isLanguageRequested(lang: string): boolean

Whether a language tokenizer has already been requested (fetch started or completed).

08

kindlyNote

function
function kindlyNote(_config?: Record<string, never>): Plugin

Plugin factory for `@aihu-plugin/kindly-note`.

09

renderMarkdown

function
async function renderMarkdown(src: string, opts?: RenderMarkdownOptions): Promise<string>
10

AIHU_CODE_TAG

const
const AIHU_CODE_TAG

The `<aihu-code>` tag name.

11

AIHU_MARKDOWN_TAG

const
const AIHU_MARKDOWN_TAG

The `<aihu-markdown>` tag name.

12

AihuCodeElement

interface
interface AihuCodeElement extends HTMLElement {
  /**
   * Language id. Accepts a string or a signal reader `() => string`.
   *
   * Named `language` (not `lang`) so it does not collide with the native
   * `HTMLElement.lang` reflected attribute, whose type is `string`. The
   * declarative `lang="…"` *attribute* still works and feeds this property.
   */
  language: StringOrReader
  /** Source code. Accepts a string or a signal reader `() => string`. */
  code: StringOrReader
}
13

AihuMarkdownElement

interface
interface AihuMarkdownElement extends HTMLElement {
  /** Markdown source. Accepts a string or a signal reader `() => string`. */
  source: StringOrReader
  /** Alias of {@link source}, for ergonomics. Same backing field. */
  markdown: StringOrReader
  /**
   * Render options forwarded to `@kindly-note/render-markdown` (e.g.
   * `classPrefix`, `languages`, `urlPolicy`). Defaults to the engine's
   * security-first defaults when unset.
   */
  options: RenderMarkdownOptions | undefined
}
14

HighlightOutput

interface
interface HighlightOutput {
  /** Scoped-span HTML string (`<span class="kn-...">…</span>`). */
  readonly html: string
  /** Canonical language name resolved by the engine (e.g. `'TypeScript'`),
   *  or `undefined` when the language could not be loaded/registered. */
  readonly language: string | undefined
  /** True when the language id could not be lazy-loaded; `html` is then the
   *  HTML-escaped raw source so the caller still renders safe, readable text. */
  readonly fallback: boolean
}

Result of a single highlight call.

15

AihuCodeElementConstructor

type
type AihuCodeElementConstructor = (new () => AihuCodeElement) & {
  readonly tagName: string
  readonly observedAttributes: readonly string[]
}

Constructor type for the lazily-created `<aihu-code>` class.

16

AihuMarkdownElementConstructor

type
type AihuMarkdownElementConstructor = (new () => AihuMarkdownElement) & {
  readonly tagName: string
}

Constructor type for the lazily-created `<aihu-markdown>` class.

17

RenderMarkdownOptions

type
type RenderMarkdownOptions