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.
defineCodeElementfunction defineCodeElement(): stringRegister the `<aihu-code>` custom element.
defineMarkdownElementfunction defineMarkdownElement(): stringRegister the `<aihu-markdown>` custom element.
ensureLanguageasync function ensureLanguage(lang: string): Promise<string | null>Ensure the tokenizer for `lang` is loaded and registered with the shared highlighter.
getAihuCodeElementfunction getAihuCodeElement(): AihuCodeElementConstructorLazily build (and memoize) the `<aihu-code>` class.
getAihuMarkdownElementfunction getAihuMarkdownElement(): AihuMarkdownElementConstructorLazily build (and memoize) the `<aihu-markdown>` class.
highlightasync function highlight(source: string, lang: string): Promise<HighlightOutput>Highlight `source` as `lang` at runtime, returning scoped-span HTML.
isLanguageRequestedfunction isLanguageRequested(lang: string): booleanWhether a language tokenizer has already been requested (fetch started or completed).
kindlyNotefunction kindlyNote(_config?: Record<string, never>): PluginPlugin factory for `@aihu-plugin/kindly-note`.
renderMarkdownasync function renderMarkdown(src: string, opts?: RenderMarkdownOptions): Promise<string>AIHU_CODE_TAGconst AIHU_CODE_TAGThe `<aihu-code>` tag name.
AIHU_MARKDOWN_TAGconst AIHU_MARKDOWN_TAGThe `<aihu-markdown>` tag name.
AihuCodeElementinterface 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
}AihuMarkdownElementinterface 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
}HighlightOutputinterface 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.
AihuCodeElementConstructortype AihuCodeElementConstructor = (new () => AihuCodeElement) & {
readonly tagName: string
readonly observedAttributes: readonly string[]
}Constructor type for the lazily-created `<aihu-code>` class.
AihuMarkdownElementConstructortype AihuMarkdownElementConstructor = (new () => AihuMarkdownElement) & {
readonly tagName: string
}Constructor type for the lazily-created `<aihu-markdown>` class.
RenderMarkdownOptionstype RenderMarkdownOptions