Skip to content

highlightDiff / highlightResult / mountDiff

highlightDiff

typescript
function highlightDiff(text: string, options?: HighlightOptions): string

Takes a diff text string in any of the 4 supported formats and returns an HTML string with syntax-highlighting CSS classes.

Parameters:

ParameterTypeDescription
textstringDiff output text — semantic, rows, JSON, or XML format
options.formatDiffFormatFormat override. Defaults to 'auto' (auto-detect).
options.classNamestringAdditional CSS class appended to the root <pre> element.

Returns: string — HTML string: <pre class="dmn-dh [custom]"><code>...</code></pre>

Example:

typescript
const html = highlightDiff(diffText);
// auto-detect format

const html = highlightDiff(xmlDiff, { format: 'xml', className: 'my-theme' });

highlightResult

typescript
function highlightResult(result: DiffResult, options?: HighlightResultOptions): string

Renders a DiffResult from @veridtools/dmn-diff as semantic-format HTML with syntax-highlighting CSS classes. Always produces semantic output — use highlightDiff with rendered text if you need rows or JSON HTML.

Parameters:

ParameterTypeDescription
resultDiffResultResult from diff()
options.classNamestringAdditional CSS class on the root <pre>.

Returns: string — Highlighted HTML string (semantic format).

Example:

typescript
import { diff } from '@veridtools/dmn-diff';
import { highlightResult } from '@veridtools/dmn-diff-highlight';

const result = diff(fromXml, toXml, { fromFile: 'before.dmn', toFile: 'after.dmn' });

const html = highlightResult(result);
const html = highlightResult(result, { className: 'dark-theme' });

mountDiff

typescript
function mountDiff(
  element: HTMLElement,
  text: string,
  options?: Omit<HighlightOptions, 'className'>,
): void

Convenience function that sets element.innerHTML = highlightDiff(text, options). Useful for plain DOM manipulation.

Parameters:

ParameterTypeDescription
elementHTMLElementTarget DOM element
textstringDiff text to highlight
options.formatDiffFormatFormat override. Defaults to 'auto'.

Example:

typescript
const container = document.getElementById('diff-output')!;
mountDiff(container, diffText);
mountDiff(container, xmlDiff, { format: 'xml' });

detectFormat

typescript
function detectFormat(text: string): Exclude<DiffFormat, 'auto'>

Inspects a diff string and returns the detected format. Used internally by highlightDiff.

Returns: 'semantic' | 'rows' | 'json' | 'xml'

Detection rules (in order, delegated to @veridtools/dmn-diff):

  1. Text starts with {'json'
  2. Text contains <?xml'xml'
  3. Lines starting with +/- match ^[+-]\s*\['rows'
  4. Otherwise → 'semantic'

Released under the MIT License.