@inshapardaz/likhari-converters 0.1.45-dev.338 → 0.1.45-dev.340

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,26 @@
1
+ import type { SerializedEditorState } from 'lexical';
2
+ import { type FormatRegistry } from '../registry.js';
3
+ import type { ConverterContext, FormatId } from '../types.js';
4
+ export interface ConvertContentOptions {
5
+ /** The format `content` is in. */
6
+ inputFormat: FormatId;
7
+ /** The format to write. */
8
+ outputFormat: FormatId;
9
+ /** Passed to the parse and the serialize (image URL resolver and the like). */
10
+ context?: ConverterContext;
11
+ /** Defaults to the registry with all four built-in formats. */
12
+ registry?: FormatRegistry;
13
+ }
14
+ /** Reads `content` and returns it as Lexical state. */
15
+ export declare function convertContentToState(content: string, options: Omit<ConvertContentOptions, 'outputFormat'>): SerializedEditorState;
16
+ /**
17
+ * Converts a document from one format to another through the editor's own parsers and
18
+ * serializers, so the result is exactly what the editor would save in that format. Needs no
19
+ * editor or DOM for Markdown, Lexical JSON and plain text (HTML input uses `DOMParser`).
20
+ *
21
+ * Going to a format that holds less than the input (rich text to plain text, a table to
22
+ * Markdown, ...) degrades the way the format's fidelity matrix says; see
23
+ * `docs/lexical-editor-spec.md` and `docs/markdown-dialect.md`.
24
+ */
25
+ export declare function convertContent(content: string, options: ConvertContentOptions): string;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/convert/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAyB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE3D,MAAM,WAAW,qBAAqB;IACpC,kCAAkC;IAClC,WAAW,EAAE,QAAQ,CAAC;IACtB,2BAA2B;IAC3B,YAAY,EAAE,QAAQ,CAAC;IACvB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED,uDAAuD;AACvD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,cAAc,CAAC,GAAG,qBAAqB,CAQlI;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,MAAM,CAGtF"}
@@ -0,0 +1,25 @@
1
+ import { defaultFormatRegistry } from '../registry.js';
2
+ /** Reads `content` and returns it as Lexical state. */
3
+ export function convertContentToState(content, options) {
4
+ const { inputFormat, context, registry = defaultFormatRegistry } = options;
5
+ try {
6
+ return registry.parse(inputFormat, content, context);
7
+ }
8
+ catch (error) {
9
+ const reason = error instanceof Error ? error.message : String(error);
10
+ throw new Error(`convertContent: the input is not valid ${inputFormat}: ${reason}`);
11
+ }
12
+ }
13
+ /**
14
+ * Converts a document from one format to another through the editor's own parsers and
15
+ * serializers, so the result is exactly what the editor would save in that format. Needs no
16
+ * editor or DOM for Markdown, Lexical JSON and plain text (HTML input uses `DOMParser`).
17
+ *
18
+ * Going to a format that holds less than the input (rich text to plain text, a table to
19
+ * Markdown, ...) degrades the way the format's fidelity matrix says; see
20
+ * `docs/lexical-editor-spec.md` and `docs/markdown-dialect.md`.
21
+ */
22
+ export function convertContent(content, options) {
23
+ const registry = options.registry ?? defaultFormatRegistry;
24
+ return registry.serialize(options.outputFormat, convertContentToState(content, options), options.context);
25
+ }
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export { lexicalJsonConverter } from './lexical-json/index.js';
5
5
  export { markdownConverter } from './markdown/index.js';
6
6
  export { htmlConverter } from './html/index.js';
7
7
  export { mergePages, mergePagesToState, type MergePagesOptions, type PageInput } from './merge/index.js';
8
+ export { convertContent, convertContentToState, type ConvertContentOptions } from './convert/index.js';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,KAAK,qBAAqB,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -5,3 +5,4 @@ export { lexicalJsonConverter } from './lexical-json/index.js';
5
5
  export { markdownConverter } from './markdown/index.js';
6
6
  export { htmlConverter } from './html/index.js';
7
7
  export { mergePages, mergePagesToState } from './merge/index.js';
8
+ export { convertContent, convertContentToState } from './convert/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inshapardaz/likhari-converters",
3
- "version": "0.1.45-dev.338",
3
+ "version": "0.1.45-dev.340",
4
4
  "description": "Format transformers (Markdown/HTML/plain-text/Lexical JSON) against the canonical Lexical EditorState, isolated from UI.",
5
5
  "license": "MIT",
6
6
  "repository": {