Skip to content

API Reference

Complete API reference for HTML Layout Parser v0.0.1.

Overview

HTML Layout Parser provides a simple yet powerful API for parsing HTML/CSS and extracting character-level layout information.

Main Class

HtmlLayoutParser

The main parser class. See HtmlLayoutParser for full documentation.

typescript
import { HtmlLayoutParser } from 'html-layout-parser';

const parser = new HtmlLayoutParser();
await parser.init();

// Load font
const fontId = parser.loadFont(fontData, 'Arial');
parser.setDefaultFont(fontId);

// Parse HTML
const layouts = parser.parse(html, { viewportWidth: 800 });

// Clean up
parser.destroy();

Quick Reference

Initialization

MethodDescription
init(wasmPath?)Initialize the WASM module
isInitialized()Check if parser is ready
getEnvironment()Get runtime environment
getVersion()Get parser version

Font Management

MethodDescription
loadFont(data, name)Load font from binary data
loadFontFromFile(path, name)Load font from file (Node.js)
unloadFont(fontId)Unload a specific font
setDefaultFont(fontId)Set default fallback font
getLoadedFonts()List all loaded fonts
clearAllFonts()Remove all fonts

Parsing

MethodDescription
parse(html, options)Parse HTML and get layouts
parseWithCSS(html, css, options)Parse with external CSS
parseWithDiagnostics(html, options)Parse with full diagnostics
getLastParseResult()Get last parse diagnostics

Memory Management

MethodDescription
getMetrics()Get memory metrics
getTotalMemoryUsage()Get total memory in bytes
checkMemoryThreshold()Check if exceeds 50MB
getMemoryMetrics()Get detailed metrics
destroy()Release all resources

Factory Function

typescript
import { createParser } from 'html-layout-parser';

const parser = createParser();
await parser.init();

Environment Detection

typescript
import { detectEnvironment } from 'html-layout-parser';

const env = detectEnvironment(); // 'web' | 'worker' | 'node' | 'unknown'

Environment-Specific Imports

typescript
import { HtmlLayoutParser } from 'html-layout-parser';
typescript
import { HtmlLayoutParser } from 'html-layout-parser';
typescript
import { HtmlLayoutParser } from 'html-layout-parser';
typescript
import { HtmlLayoutParser } from 'html-layout-parser';

Released under the MIT License.