Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/parse5/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export namespace DefaultTreeAdapterTypes {
export type DefaultTreeAdapterMap = DefaultTreeAdapter.DefaultTreeAdapterMap;
}
export type { TreeAdapter, TreeAdapterTypeMap } from './tree-adapters/interface.js';
export { type ParserOptions, /** @internal */ Parser } from './parser/index.js';
export { type ParserOptions, /** @internal */ Parser, InsertionMode } from './parser/index.js';
export { serialize, serializeOuter, type SerializerOptions } from './serializer/index.js';
export { ERR as ErrorCodes, type ParserError, type ParserErrorHandler } from './common/error-codes.js';

Expand Down
11 changes: 10 additions & 1 deletion packages/parse5/lib/parser/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { it, assert, describe, beforeEach, afterEach, vi, expect } from 'vitest';
import { parseFragment, parse } from 'parse5';
import { parseFragment, parse, InsertionMode } from 'parse5';
import type { Element, TextNode } from '../tree-adapters/default.js';
import { generateParsingTests } from 'parse5-test-utils/utils/generate-parsing-tests.js';
import { treeAdapters } from 'parse5-test-utils/utils/common.js';
Expand Down Expand Up @@ -152,3 +152,12 @@ describe('parser', () => {
});
});
});

describe('InsertionMode', () => {
it('should be exported and have stable numeric values', () => {
assert.strictEqual(InsertionMode.INITIAL, 0);
assert.strictEqual(InsertionMode.BEFORE_HTML, 1);
assert.strictEqual(InsertionMode.IN_BODY, 6);
assert.strictEqual(InsertionMode.AFTER_AFTER_FRAMESET, 22);
});
});
48 changes: 24 additions & 24 deletions packages/parse5/lib/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ const AA_OUTER_LOOP_ITER = 8;
const AA_INNER_LOOP_ITER = 3;

//Insertion modes
enum InsertionMode {
INITIAL,
BEFORE_HTML,
BEFORE_HEAD,
IN_HEAD,
IN_HEAD_NO_SCRIPT,
AFTER_HEAD,
IN_BODY,
TEXT,
IN_TABLE,
IN_TABLE_TEXT,
IN_CAPTION,
IN_COLUMN_GROUP,
IN_TABLE_BODY,
IN_ROW,
IN_CELL,
IN_SELECT,
IN_SELECT_IN_TABLE,
IN_TEMPLATE,
AFTER_BODY,
IN_FRAMESET,
AFTER_FRAMESET,
AFTER_AFTER_BODY,
AFTER_AFTER_FRAMESET,
export enum InsertionMode {
INITIAL = 0,
BEFORE_HTML = 1,
BEFORE_HEAD = 2,
IN_HEAD = 3,
IN_HEAD_NO_SCRIPT = 4,
AFTER_HEAD = 5,
IN_BODY = 6,
TEXT = 7,
IN_TABLE = 8,
IN_TABLE_TEXT = 9,
IN_CAPTION = 10,
IN_COLUMN_GROUP = 11,
IN_TABLE_BODY = 12,
IN_ROW = 13,
IN_CELL = 14,
IN_SELECT = 15,
IN_SELECT_IN_TABLE = 16,
IN_TEMPLATE = 17,
AFTER_BODY = 18,
IN_FRAMESET = 19,
AFTER_FRAMESET = 20,
AFTER_AFTER_BODY = 21,
AFTER_AFTER_FRAMESET = 22,
}

const BASE_LOC = {
Expand Down