Preview

Live Preview

An editor MUST provide a live HTML preview of the current AsciiDoc document rendered by Asciidoctor.

An editor MUST support opening the preview in a side-by-side panel alongside the editor. An editor SHOULD support opening the preview as a full tab.

The preview MUST automatically update when the document is saved. An editor SHOULD support configurable auto-refresh on edit, scheduled as described in Refresh Scheduling. An editor SHOULD provide a manual "refresh preview" action.

Refresh Scheduling

Converting a document is expensive, and a conversion started while the author is still typing renders a version that is already outdated. An editor SHOULD schedule the renders triggered by edits so that the preview stays responsive without running more conversions than needed:

  • The first edit after a quiet period SHOULD be rendered immediately. A pure debounce (render only once the author stops typing) SHOULD NOT be used: an author who keeps typing would never see the preview update.

  • An editor MUST NOT run two renders of the same preview at the same time. The edits made during a render MUST be coalesced into a single render of the latest version of the document, read when that render starts, not when it was scheduled.

  • The next render SHOULD start after a delay measured from the end of the previous render, and that delay SHOULD grow with the duration of the last render, so that a document that is slow to convert is rendered less often.

  • The last edit MUST eventually be rendered.

  • A result MUST NOT be displayed if it is older than the content already displayed, or if it belongs to another document than the one the preview now displays (e.g., the preview switched to another document during the conversion).

  • A result SHOULD be displayed even when newer edits were made during the conversion: it is still more recent than the content displayed. Discarding it would freeze the preview for as long as the author keeps typing.

The following pseudocode describes this practice:

onChange:
  dirty = true
  if (rendering) return                    // only one render at a time
  if (timer) return                        // a render is already scheduled
  idle = now - lastRenderEnd > idleThreshold
  timer = setTimeout(render, idle ? 0 : delay())

render:
  rendering = true; dirty = false
  source = displayedDocument               // the latest version, read when rendering, not when scheduling
  html = await convert(source)
  if (source === displayedDocument) post(html)   // even if dirty: renders end in order, so it is newer than what is displayed
  rendering = false; lastRenderEnd = now
  if (dirty) timer = setTimeout(render, delay())

delay() = clamp(k × lastRenderDuration, minDelay, maxDelay)

Where:

minDelay

The minimum time between two renders while typing, typically configurable (a few hundred milliseconds).

k

The ratio between the time left to the editor and the duration of a render. For instance, with k = 2, the conversion uses at most about a third of the time while the author types.

maxDelay

An upper bound, so that a very slow document is still refreshed regularly.

idleThreshold

The time without render after which an edit is rendered immediately, typically minDelay.

An editor SHOULD NOT render a preview that is not visible, and SHOULD render it when it is shown again.

An editor SHOULD run the conversion outside the thread that handles the user interface and the other editor services (e.g., in a worker thread), so that converting a large document does not freeze the display, the typing or the other features of the editor. An editor SHOULD be able to cancel a conversion in progress when it belongs to a document that the preview no longer displays. An editor MAY also cancel a conversion that becomes outdated because of a newer edit, to start a conversion of the latest version, provided the preview is still updated regularly while the author keeps typing (e.g., by not cancelling a conversion when the preview has not been updated for maxDelay). When the conversion cannot be cancelled, the rules above limit the number of outdated conversions.

Rendering Engine

An editor MUST use Asciidoctor (or a compatible implementation) as the rendering engine. The rendering engine MUST support all standard AsciiDoc constructs. The rendering engine SHOULD support Asciidoctor extensions loaded from the project’s .asciidoctor/lib/ directory.

An editor SHOULD expose the Asciidoctor version in use and allow configuring additional attributes passed to the renderer.

Environment Attribute

An editor MUST set an environment attribute in the preview to allow authors to use conditional content for IDE-specific output. Recommended attribute names: env-idea (IntelliJ), env-vscode (VS Code), or the generic env attribute set to the IDE name.

Preview Styling

An editor SHOULD apply the Asciidoctor default stylesheet to the preview by default. An editor SHOULD allow authors to:

  • Switch to the IDE’s own theme-derived stylesheet

  • Supply a custom CSS file via configuration that replaces the default stylesheet

  • Extend the default stylesheet with additional style rules (so authors can tweak the appearance without re-supplying a complete stylesheet)

  • Configure font family, font size, and line height for the preview

An editor MAY support Asciidoctor custom templates (e.g., Slim/ERB templates) that override the default HTML output.

Scroll Synchronization

An editor SHOULD synchronize the preview scroll position with the editor cursor position, so that the preview automatically scrolls to show the content corresponding to the current cursor location.

An editor SHOULD also synchronize in the reverse direction: scrolling the preview should scroll the editor to the corresponding position.

An editor MUST allow users to disable scroll synchronization independently for each direction.

Preview-to-Source Navigation

An editor SHOULD allow authors to navigate from a location in the preview to the corresponding source line in the editor. Recommended interactions: double-click or Ctrl+Click on preview content.

An editor SHOULD highlight the editor line or block corresponding to the currently focused preview element.

Zoom

An editor MAY support zooming the preview in and out (e.g., via Ctrl+scroll wheel).

Security

An editor MUST enforce a content security policy for the preview to protect against script injection.

An editor MUST provide multiple security levels, including at minimum:

Strict

No scripts, no remote content, no file:// access. Safest default.

Allow Insecure Content

Permits mixed http:// and https:// content.

Allow Scripts and Unsafe Content

Permits JavaScript execution and arbitrary remote content loading.

An editor SHOULD default to the strictest security mode. An editor MUST warn users when they downgrade to a less restrictive security mode. An editor SHOULD remember the security level per workspace.

MathML / LaTeX Rendering

An editor SHOULD support rendering of mathematical formulas using MathML or a compatible renderer (e.g., MathJax, KaTeX).

An editor MAY additionally support chemical notation (e.g., the \ce and \pu macros provided by the MathJax mhchem extension) so that chemistry-oriented documents render correctly.

An editor MUST open external URLs (http://, https://) in the system default browser when clicked in the preview.

An editor SHOULD open internal AsciiDoc file links either in the preview or in the editor, based on user configuration.

Locked Preview

An editor MAY support a "locked" preview mode that pins the preview to a specific document and prevents it from switching when the editor focus changes to a different file.

Preview State Preservation

An editor MAY keep the preview rendering in memory when the preview panel is hidden, so that it reloads instantly without re-rendering when shown again.