@portabletext/html 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ import { n as TypedObject, t as DeserializerRule } from "./_chunks-dts/types.js";
2
+ import * as _portabletext_schema3 from "@portabletext/schema";
3
+ import { PortableTextObject, Schema, SchemaDefinition } from "@portabletext/schema";
4
+ /**
5
+ * Matcher function for mapping HTML objects to Portable Text block or inline objects.
6
+ *
7
+ * @public
8
+ */
9
+ type ObjectMatcher<TValue extends Record<string, unknown> = Record<string, never>> = ({
10
+ context,
11
+ value,
12
+ isInline
13
+ }: {
14
+ context: {
15
+ schema: Schema;
16
+ keyGenerator: () => string;
17
+ };
18
+ value: TValue;
19
+ isInline: boolean;
20
+ }) => PortableTextObject | undefined;
21
+ /**
22
+ * @public
23
+ */
24
+ declare function buildObjectMatcher<TDefinition extends {
25
+ name: string;
26
+ }>(definition: TDefinition): ObjectMatcher<ExtractValue<TDefinition>>;
27
+ /**
28
+ * @public
29
+ */
30
+ type ExtractValue<TDefinition extends NonNullable<SchemaDefinition['blockObjects']>[0]> = TDefinition extends {
31
+ fields: ReadonlyArray<{
32
+ name: infer TNames;
33
+ }>;
34
+ } ? Record<TNames & string, unknown> : Record<string, never>;
35
+ /**
36
+ * Options for converting HTML to Portable Text
37
+ *
38
+ * @public
39
+ */
40
+ type HtmlToPortableTextOptions = {
41
+ schema?: Schema;
42
+ keyGenerator?: () => string;
43
+ parseHtml?: (html: string) => Document;
44
+ rules?: DeserializerRule[];
45
+ whitespaceMode?: 'preserve' | 'remove' | 'normalize';
46
+ types?: {
47
+ image?: ObjectMatcher<{
48
+ src?: string;
49
+ alt?: string;
50
+ }>;
51
+ };
52
+ };
53
+ /**
54
+ * Convert HTML to Portable Text
55
+ *
56
+ * @param html - The HTML string to convert
57
+ * @param options - Options for the conversion
58
+ * @returns Array of Portable Text blocks
59
+ * @public
60
+ */
61
+ declare function htmlToPortableText(html: string, options?: HtmlToPortableTextOptions): (Omit<TypedObject | _portabletext_schema3.PortableTextTextBlock<TypedObject | _portabletext_schema3.PortableTextSpan>, "_key"> & {
62
+ _key: string;
63
+ })[];
64
+ /**
65
+ * The default schema for converting HTML to Portable Text.
66
+ *
67
+ * @public
68
+ */
69
+ declare const defaultSchema: _portabletext_schema3.Schema;
70
+ export { type DeserializerRule, type HtmlToPortableTextOptions, type ObjectMatcher, buildObjectMatcher, defaultSchema, htmlToPortableText };
71
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/matchers.ts","../src/html-to-portable-text.ts","../src/default-schema.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAuJY,6BACK,0BAA0B;;;;;;YAMvB;;;SACX;;MAEH;;;;iBAKU;;eACF,cACX,cAAc,aAAa;;;;KAqClB,iCACU,YAAY,wCAC9B;UAA6B;;;IAC7B,OAAO,4BACP;;AA1DJ;;;;AAIE,KC9IU,yBAAA,GD8IV;EACA,MAAA,CAAA,EC9IS,MD8IT;EAEkB,YAAA,CAAA,EAAA,GAAA,GAAA,MAAA;EACX,SAAA,CAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GC/IuB,QD+IvB;EAEH,KAAA,CAAA,EChJI,gBDgJJ,EAAA;EAAkB,cAAA,CAAA,EAAA,UAAA,GAAA,QAAA,GAAA,WAAA;EAKR,KAAA,CAAA,EAAA;IACF,KAAA,CAAA,ECnJF,aDmJE,CAAA;MACgB,GAAA,CAAA,EAAA,MAAA;MAAb,GAAA,CAAA,EAAA,MAAA;IAAd,CAAA,CAAA;EAAa,CAAA;AAqChB,CAAA;;;;;;;;;iBC7KgB,kBAAA,yBAEL,6BAA8B,KAAA,WAAA,GAAA,qBAAA,CAAA,sBAAA,WAAA,GAAA,qBAAA,CAAA;EArB7B,IAAA,EAAA,MAAA;CACD,CAAA,EAAA;;;;;;cCuHE,eAgCZ,qBAAA,CAhCyB"}