@portabletext/markdown 2.1.0 → 2.2.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.
- package/README.md +145 -3
- package/dist/index.d.ts +415 -186
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +908 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -359,196 +359,24 @@ interface Serializable<T> {
|
|
|
359
359
|
}
|
|
360
360
|
type Options$1 = Partial<PortableTextRenderers> & {
|
|
361
361
|
blockSpacing?: BlockSpacingRenderer;
|
|
362
|
+
/**
|
|
363
|
+
* Compiled schema that gates the built-in type renderers; it never
|
|
364
|
+
* validates the value. A default renderer runs only when the schema
|
|
365
|
+
* declares its type (`blockObjects` for block position, `inlineObjects`
|
|
366
|
+
* for inline); undeclared types render through `unknownType`, whose
|
|
367
|
+
* default output reparses back to the same value. The gate checks the
|
|
368
|
+
* type name only, so declare the type's fields too:
|
|
369
|
+
* `markdownToPortableText` cannot rebuild a value from a fieldless
|
|
370
|
+
* declaration. Renderers passed in `types` are never gated. Pass the
|
|
371
|
+
* same schema to `markdownToPortableText` to keep the round trip
|
|
372
|
+
* consistent. Omitted, all default renderers stay active.
|
|
373
|
+
*/
|
|
374
|
+
schema?: Schema;
|
|
362
375
|
};
|
|
363
376
|
/**
|
|
364
377
|
* @public
|
|
365
378
|
*/
|
|
366
379
|
declare function portableTextToMarkdown<Block extends TypedObject = PortableTextBlock$1 | ArbitraryTypedObject>(blocks: Array<Block>, options?: Options$1): string;
|
|
367
|
-
/**
|
|
368
|
-
* @public
|
|
369
|
-
*/
|
|
370
|
-
declare const DefaultHardBreakRenderer: () => string;
|
|
371
|
-
/**
|
|
372
|
-
* @public
|
|
373
|
-
*/
|
|
374
|
-
declare const DefaultListItemRenderer: PortableTextListItemRenderer;
|
|
375
|
-
type PortableTextBlockRenderer$1 = PortableTextRenderer<PortableTextBlock$1>;
|
|
376
|
-
/**
|
|
377
|
-
* @public
|
|
378
|
-
*/
|
|
379
|
-
declare const DefaultNormalRenderer: PortableTextBlockRenderer$1;
|
|
380
|
-
/**
|
|
381
|
-
* @public
|
|
382
|
-
*/
|
|
383
|
-
declare const DefaultBlockquoteRenderer: PortableTextBlockRenderer$1;
|
|
384
|
-
/**
|
|
385
|
-
* @public
|
|
386
|
-
*/
|
|
387
|
-
declare const DefaultH1Renderer: PortableTextBlockRenderer$1;
|
|
388
|
-
/**
|
|
389
|
-
* @public
|
|
390
|
-
*/
|
|
391
|
-
declare const DefaultH2Renderer: PortableTextBlockRenderer$1;
|
|
392
|
-
/**
|
|
393
|
-
* @public
|
|
394
|
-
*/
|
|
395
|
-
declare const DefaultH3Renderer: PortableTextBlockRenderer$1;
|
|
396
|
-
/**
|
|
397
|
-
* @public
|
|
398
|
-
*/
|
|
399
|
-
declare const DefaultH4Renderer: PortableTextBlockRenderer$1;
|
|
400
|
-
/**
|
|
401
|
-
* @public
|
|
402
|
-
*/
|
|
403
|
-
declare const DefaultH5Renderer: PortableTextBlockRenderer$1;
|
|
404
|
-
/**
|
|
405
|
-
* @public
|
|
406
|
-
*/
|
|
407
|
-
declare const DefaultH6Renderer: PortableTextBlockRenderer$1;
|
|
408
|
-
/**
|
|
409
|
-
* @public
|
|
410
|
-
*/
|
|
411
|
-
declare const DefaultEmRenderer: PortableTextMarkRenderer;
|
|
412
|
-
/**
|
|
413
|
-
* @public
|
|
414
|
-
*/
|
|
415
|
-
declare const DefaultStrongRenderer: PortableTextMarkRenderer;
|
|
416
|
-
/**
|
|
417
|
-
* Renders a `code` decorator from the raw span text, bypassing the escaped
|
|
418
|
-
* `children`: code content is verbatim, never markdown syntax. The
|
|
419
|
-
* backtick fence is widened past the longest run of backticks already in
|
|
420
|
-
* the text (CommonMark: the fence must be longer than any run it encloses).
|
|
421
|
-
*
|
|
422
|
-
* A space is padded on each side when the content starts or ends with a
|
|
423
|
-
* backtick, so the fence and the content's own backtick never merge into
|
|
424
|
-
* one run, and also when the content starts and ends with a space and
|
|
425
|
-
* isn't all whitespace (`text.trim() !== ''`; an all-space code span has
|
|
426
|
-
* nothing else for CommonMark's strip rule to leave behind, so padding it
|
|
427
|
-
* would only add visible spaces), because CommonMark itself would
|
|
428
|
-
* otherwise strip one such space per side on reparse; the padding
|
|
429
|
-
* pre-compensates for that strip.
|
|
430
|
-
*
|
|
431
|
-
* @public
|
|
432
|
-
*/
|
|
433
|
-
declare const DefaultCodeRenderer: PortableTextMarkRenderer;
|
|
434
|
-
/**
|
|
435
|
-
* @public
|
|
436
|
-
*/
|
|
437
|
-
declare const DefaultUnderlineRenderer: PortableTextMarkRenderer;
|
|
438
|
-
/**
|
|
439
|
-
* @public
|
|
440
|
-
*/
|
|
441
|
-
declare const DefaultStrikeThroughRenderer: PortableTextMarkRenderer;
|
|
442
|
-
interface DefaultLink extends TypedObject {
|
|
443
|
-
_type: 'link';
|
|
444
|
-
href: string;
|
|
445
|
-
title: string | undefined;
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* @public
|
|
449
|
-
*/
|
|
450
|
-
declare const DefaultLinkRenderer: PortableTextMarkRenderer<DefaultLink>;
|
|
451
|
-
/**
|
|
452
|
-
* @public
|
|
453
|
-
*/
|
|
454
|
-
declare const DefaultCodeBlockRenderer: PortableTextTypeRenderer<{
|
|
455
|
-
_type: 'code';
|
|
456
|
-
code: string;
|
|
457
|
-
language: string | undefined;
|
|
458
|
-
}>;
|
|
459
|
-
/**
|
|
460
|
-
* @public
|
|
461
|
-
*/
|
|
462
|
-
declare const DefaultHorizontalRuleRenderer: PortableTextTypeRenderer;
|
|
463
|
-
/**
|
|
464
|
-
* @public
|
|
465
|
-
*/
|
|
466
|
-
declare const DefaultHtmlRenderer: PortableTextTypeRenderer<{
|
|
467
|
-
_type: 'html';
|
|
468
|
-
html: string;
|
|
469
|
-
}>;
|
|
470
|
-
/**
|
|
471
|
-
* @public
|
|
472
|
-
*/
|
|
473
|
-
declare const DefaultImageRenderer: PortableTextTypeRenderer<{
|
|
474
|
-
_type: 'image';
|
|
475
|
-
src: string;
|
|
476
|
-
alt: string | undefined;
|
|
477
|
-
title: string | undefined;
|
|
478
|
-
}>;
|
|
479
|
-
/**
|
|
480
|
-
* Renders a Portable Text table block-object back to Markdown.
|
|
481
|
-
*
|
|
482
|
-
* The PT `headerRows` field decides the header. Missing `headerRows` and
|
|
483
|
-
* `headerRows === 0` both render headerless: GFM has no headerless form, so
|
|
484
|
-
* an empty header row is emitted and every row goes in the body (that empty
|
|
485
|
-
* header reads back as `headerRows: 0` via `markdownToPortableText`).
|
|
486
|
-
* `headerRows >= 1` promotes `rows[0]` to the header. GFM allows exactly one
|
|
487
|
-
* header row, so header rows beyond the first flatten into the body, lossy,
|
|
488
|
-
* but the extra rows stay on the Portable Text side.
|
|
489
|
-
*
|
|
490
|
-
* Asymmetric tables (rows of varying cell counts) are widened to match
|
|
491
|
-
* the row with the most cells. Narrower rows are padded with empty cells
|
|
492
|
-
* so a GFM parser doesn't silently drop the extra cells in wider rows.
|
|
493
|
-
*
|
|
494
|
-
* @public
|
|
495
|
-
*/
|
|
496
|
-
declare const DefaultTableRenderer: PortableTextTypeRenderer<{
|
|
497
|
-
_type: 'table';
|
|
498
|
-
headerRows: number | undefined;
|
|
499
|
-
alignment: Array<'left' | 'center' | 'right' | null> | undefined;
|
|
500
|
-
rows: Array<{
|
|
501
|
-
_key: string;
|
|
502
|
-
cells: Array<{
|
|
503
|
-
_key: string;
|
|
504
|
-
value: Array<PortableTextBlock$1>;
|
|
505
|
-
}>;
|
|
506
|
-
}>;
|
|
507
|
-
}>;
|
|
508
|
-
/**
|
|
509
|
-
* @public
|
|
510
|
-
*/
|
|
511
|
-
declare const DefaultCalloutRenderer: PortableTextTypeRenderer<{
|
|
512
|
-
_type: 'callout';
|
|
513
|
-
tone: string;
|
|
514
|
-
content: Array<PortableTextBlock$1>;
|
|
515
|
-
}>;
|
|
516
|
-
/**
|
|
517
|
-
* Renders a structural blockquote block-object (the `types.blockquote` shape
|
|
518
|
-
* produced by `markdownToPortableText` when a `types.blockquote` matcher is
|
|
519
|
-
* provided) back to Markdown. Each content block is rendered via the
|
|
520
|
-
* recursive renderer pipeline, joined with blank lines, and every line is
|
|
521
|
-
* prefixed with `> ` to form a Markdown blockquote.
|
|
522
|
-
*
|
|
523
|
-
* Distinct from `DefaultBlockquoteRenderer`, which renders flat-path text
|
|
524
|
-
* blocks with `style: 'blockquote'`.
|
|
525
|
-
*
|
|
526
|
-
* @public
|
|
527
|
-
*/
|
|
528
|
-
declare const DefaultBlockquoteObjectRenderer: PortableTextTypeRenderer<{
|
|
529
|
-
_type: 'blockquote';
|
|
530
|
-
content: Array<PortableTextBlock$1>;
|
|
531
|
-
}>;
|
|
532
|
-
/**
|
|
533
|
-
* Renders a structural list block-object (the `types.list` shape produced by
|
|
534
|
-
* `markdownToPortableText` when a `types.list` matcher is provided) back to
|
|
535
|
-
* Markdown. Items render as `- ` for `kind: 'bullet'`, `1. `/`2. ` for `'number'`,
|
|
536
|
-
* and `- [x] ` / `- [ ] ` for `'task'`. Items can hold any blocks - text blocks,
|
|
537
|
-
* code blocks, callouts, images, and nested lists - and content other than the
|
|
538
|
-
* leading text block is indented to keep it inside the item.
|
|
539
|
-
*
|
|
540
|
-
* @public
|
|
541
|
-
*/
|
|
542
|
-
declare const DefaultListRenderer: PortableTextTypeRenderer<{
|
|
543
|
-
_type: 'list';
|
|
544
|
-
kind: 'bullet' | 'number' | 'task';
|
|
545
|
-
items: Array<{
|
|
546
|
-
_type: 'list-item';
|
|
547
|
-
_key: string;
|
|
548
|
-
checked?: boolean;
|
|
549
|
-
content: Array<PortableTextBlock$1 | TypedObject>;
|
|
550
|
-
}>;
|
|
551
|
-
}>;
|
|
552
380
|
/**
|
|
553
381
|
* Matcher function for mapping markdown elements to Portable Text block styles.
|
|
554
382
|
*
|
|
@@ -642,6 +470,11 @@ type Degradation = {
|
|
|
642
470
|
snippet?: string;
|
|
643
471
|
};
|
|
644
472
|
type Options = {
|
|
473
|
+
/**
|
|
474
|
+
* Compiled schema deciding which Portable Text constructs the
|
|
475
|
+
* conversion may build; pairs with the same option on
|
|
476
|
+
* `portableTextToMarkdown` to keep the round trip consistent.
|
|
477
|
+
*/
|
|
645
478
|
schema?: Schema;
|
|
646
479
|
keyGenerator?: () => string;
|
|
647
480
|
/**
|
|
@@ -751,5 +584,401 @@ type Options = {
|
|
|
751
584
|
* @public
|
|
752
585
|
*/
|
|
753
586
|
declare function markdownToPortableText(markdown: string, options?: Options): Array<PortableTextBlock>;
|
|
754
|
-
|
|
587
|
+
/**
|
|
588
|
+
* @public
|
|
589
|
+
*/
|
|
590
|
+
type ApplyMarkdownEditOptions = {
|
|
591
|
+
/**
|
|
592
|
+
* One compiled schema governing both conversion directions, the same
|
|
593
|
+
* object the standalone converters accept. Taking it once is what
|
|
594
|
+
* keeps the internal canonical dialect consistent: serializing and
|
|
595
|
+
* reparsing under different schemas would change node counts or
|
|
596
|
+
* types, refuse the origin trace, and reset keys document-wide.
|
|
597
|
+
*/
|
|
598
|
+
schema?: Schema;
|
|
599
|
+
/**
|
|
600
|
+
* Options for the markdown → Portable Text conversion of
|
|
601
|
+
* `editedMarkdown` (matchers, `keyGenerator`). The same options
|
|
602
|
+
* also govern the internal canonicalization of `storedPortableText`
|
|
603
|
+
* used to align the two documents, except `onDegradation`, which is
|
|
604
|
+
* scoped to `editedMarkdown` alone: `keyGenerator` supplies every
|
|
605
|
+
* fresh key the function mints, both for new content and for the
|
|
606
|
+
* sibling-uniqueness key-rename sweep.
|
|
607
|
+
*/
|
|
608
|
+
deserialize?: Omit<NonNullable<Parameters<typeof markdownToPortableText>[1]>, 'schema'>;
|
|
609
|
+
/**
|
|
610
|
+
* Options for the Portable Text → markdown conversion. Pass the same
|
|
611
|
+
* options that produced the markdown that was edited: key
|
|
612
|
+
* resolution aligns the edit against a fresh canonical serialization
|
|
613
|
+
* of `storedPortableText`, so the two serializations must agree for
|
|
614
|
+
* that alignment to be meaningful.
|
|
615
|
+
*/
|
|
616
|
+
serialize?: Omit<NonNullable<Parameters<typeof portableTextToMarkdown>[1]>, 'schema'>;
|
|
617
|
+
/**
|
|
618
|
+
* Reports how stored `_key`s were reconciled onto the converted
|
|
619
|
+
* value. Reconciliation here is key restoration against the exact
|
|
620
|
+
* snapshot that produced the markdown, never a merge of concurrent
|
|
621
|
+
* edits: those are the caller's job (see the README's Concurrent
|
|
622
|
+
* edits section). Called at most once, and exactly once whenever the
|
|
623
|
+
* option is set and `applyMarkdownEdit` returns (a conversion that
|
|
624
|
+
* throws never reports), synchronously, immediately before the
|
|
625
|
+
* return, including when key matching is skipped outright: that is
|
|
626
|
+
* when a caller needs the report most. A node absent from a performed report's
|
|
627
|
+
* `preservedKeys` was not preserved from the stored value, whether
|
|
628
|
+
* it is a fresh key or a `json:object` payload key that carried its
|
|
629
|
+
* own; the report does not distinguish the two. Which keys
|
|
630
|
+
* survived, every `key` and `path`, and `renamedKeys` are facts of
|
|
631
|
+
* that invocation, safe to branch on for that invocation; a skipped
|
|
632
|
+
* report's `reason` is advisory only, since near the evidence caps
|
|
633
|
+
* it can vary with machine speed, and should never drive behavior.
|
|
634
|
+
*
|
|
635
|
+
* @beta
|
|
636
|
+
*/
|
|
637
|
+
onReconciliation?: (report: ReconciliationReport) => void;
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* A path segment into the value `applyMarkdownEdit` returns: a string
|
|
641
|
+
* field name for container nesting (`rows`, `cells`, `value`, and the
|
|
642
|
+
* like), `{_key}` wherever the path lands on a keyed array element,
|
|
643
|
+
* and a number wherever it lands on a keyless one instead. A block's
|
|
644
|
+
* own path is a single `{_key}` segment, or a single number for a
|
|
645
|
+
* keyless top-level block; a child's path is
|
|
646
|
+
* `[{_key: <block key>}, 'children', {_key: <child key>}]`. A keyless
|
|
647
|
+
* node (a `json:object` payload without a `_key` of its own, at the
|
|
648
|
+
* top level or wrapping keyed content in a nested array) contributes
|
|
649
|
+
* its index as a number segment instead of a `{_key}` segment.
|
|
650
|
+
*
|
|
651
|
+
* @beta
|
|
652
|
+
*/
|
|
653
|
+
type ReconciliationKeyPath = Array<{
|
|
654
|
+
_key: string;
|
|
655
|
+
} | string | number>;
|
|
656
|
+
/**
|
|
657
|
+
* What `applyMarkdownEdit` did with every key, delivered through
|
|
658
|
+
* `onReconciliation`. `keyMatching: 'skipped'` means key matching gave
|
|
659
|
+
* up on the whole document rather than at some local point: the
|
|
660
|
+
* returned value is the plain markdown→Portable Text conversion, so
|
|
661
|
+
* every key in it is fresh except a `json:object` payload key carried
|
|
662
|
+
* through the markdown verbatim, and no preserved key or local key
|
|
663
|
+
* fallback can have happened. `preservedKeys` and `renamedKeys` list
|
|
664
|
+
* their entries in document order, each block before its children and
|
|
665
|
+
* its mark definitions after them; `keyFallbacks` groups by kind
|
|
666
|
+
* instead: `ambiguous-region-too-large` entries in the order their
|
|
667
|
+
* gaps were resolved, then `annotation-key-conflict` entries. `basis`
|
|
668
|
+
* names the matching method that preserved a key, not the edit's
|
|
669
|
+
* semantics: a swap reports one block `content-moved` and its partner
|
|
670
|
+
* `content-unchanged`. The report carries no edit intent: a deleted
|
|
671
|
+
* stored node is not listed at all, so derive deletions as stored
|
|
672
|
+
* keys minus the keys `applyMarkdownEdit` returned.
|
|
673
|
+
*
|
|
674
|
+
* @beta
|
|
675
|
+
*/
|
|
676
|
+
type ReconciliationReport = {
|
|
677
|
+
keyMatching: 'performed';
|
|
678
|
+
/**
|
|
679
|
+
* One entry per node whose stored `_key` key resolution
|
|
680
|
+
* preserved, at every depth (blocks, spans and other inline
|
|
681
|
+
* children, and mark definitions). A node absent from this list
|
|
682
|
+
* did not have its key preserved from the stored value: that
|
|
683
|
+
* covers both a freshly generated key and a `json:object`
|
|
684
|
+
* payload key carried through the markdown verbatim, which the
|
|
685
|
+
* report does not distinguish. `basis` names the tier that
|
|
686
|
+
* matched: `content-unchanged` for an exact content match (a
|
|
687
|
+
* block-level anchor, a uniquely matched child, a preserved
|
|
688
|
+
* empty-block run, or a mark definition uniquely matched by
|
|
689
|
+
* content); `content-moved` for a unique leftover matched
|
|
690
|
+
* across gaps; `content-split` for a fragment that kept its
|
|
691
|
+
* source block's key; `content-merged` for a merge that kept
|
|
692
|
+
* its first contributor's key; `same-position` for an
|
|
693
|
+
* equal-count in-order pairing (also a same-content
|
|
694
|
+
* mark-definition tie, or a single leftover mark definition
|
|
695
|
+
* paired positionally); `similar-content` for a mutual-best
|
|
696
|
+
* match under an unequal count.
|
|
697
|
+
*/
|
|
698
|
+
preservedKeys: Array<{
|
|
699
|
+
basis: 'content-unchanged' | 'content-moved' | 'content-split' | 'content-merged' | 'same-position' | 'similar-content';
|
|
700
|
+
key: string;
|
|
701
|
+
path: ReconciliationKeyPath;
|
|
702
|
+
}>;
|
|
703
|
+
/**
|
|
704
|
+
* One entry per local point where key resolution gave up rather
|
|
705
|
+
* than adopt, while the rest of the document still resolves
|
|
706
|
+
* keys: `ambiguous-region-too-large` when a gap's residual
|
|
707
|
+
* similarity pairing crossed the evidence pair cap, listing the
|
|
708
|
+
* affected result block keys that fell back to fresh;
|
|
709
|
+
* `annotation-key-conflict` when an adopted mark definition key
|
|
710
|
+
* would have collided with a sibling. The span-merge pair cap,
|
|
711
|
+
* the per-diff similarity timeout, and the gap's earlier
|
|
712
|
+
* concatenation-search cap degrade the same way but are not
|
|
713
|
+
* reported: `ambiguous-region-too-large` covers the residual
|
|
714
|
+
* similarity tier only (a gap that trips the concatenation cap
|
|
715
|
+
* trips it too).
|
|
716
|
+
*/
|
|
717
|
+
keyFallbacks: Array<{
|
|
718
|
+
type: 'ambiguous-region-too-large';
|
|
719
|
+
keys: Array<string>;
|
|
720
|
+
} | {
|
|
721
|
+
type: 'annotation-key-conflict';
|
|
722
|
+
path: ReconciliationKeyPath;
|
|
723
|
+
}>;
|
|
724
|
+
/**
|
|
725
|
+
* One entry per key `applyMarkdownEdit` rewrote to keep
|
|
726
|
+
* siblings unique, most commonly a `json:object` payload
|
|
727
|
+
* duplicating a key already present elsewhere in the document.
|
|
728
|
+
*/
|
|
729
|
+
renamedKeys: Array<{
|
|
730
|
+
previousKey: string;
|
|
731
|
+
key: string;
|
|
732
|
+
path: ReconciliationKeyPath;
|
|
733
|
+
}>;
|
|
734
|
+
} | {
|
|
735
|
+
keyMatching: 'skipped';
|
|
736
|
+
/**
|
|
737
|
+
* `round-trip-mismatch` when the stored value's own
|
|
738
|
+
* canonicalization changed its node count, type sequence, or
|
|
739
|
+
* per-position text; `document-too-large` when the document
|
|
740
|
+
* holds more distinct block forms than alignment can token.
|
|
741
|
+
* Advisory only, since near the evidence caps it can vary with
|
|
742
|
+
* machine speed, and should never drive behavior.
|
|
743
|
+
*/
|
|
744
|
+
reason: 'round-trip-mismatch' | 'document-too-large';
|
|
745
|
+
/**
|
|
746
|
+
* One entry per key `applyMarkdownEdit` rewrote to keep
|
|
747
|
+
* siblings unique, most commonly a `json:object` payload
|
|
748
|
+
* duplicating a key already present elsewhere in the document.
|
|
749
|
+
* The sibling-uniqueness pass still runs on a skipped document:
|
|
750
|
+
* a pasted duplicate `json:object` fence key still gets
|
|
751
|
+
* renamed even though nothing else adopted.
|
|
752
|
+
*/
|
|
753
|
+
renamedKeys: Array<{
|
|
754
|
+
previousKey: string;
|
|
755
|
+
key: string;
|
|
756
|
+
path: ReconciliationKeyPath;
|
|
757
|
+
}>;
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* Converts edited markdown to Portable Text, restores stored keys, and
|
|
761
|
+
* restores fields the markdown dialect cannot express (dropped by
|
|
762
|
+
* serialization, so the edit could not have touched them); a field
|
|
763
|
+
* markdown does express follows the edit. The same rule covers a
|
|
764
|
+
* custom style or decorator markdown has no syntax for, coerced to a
|
|
765
|
+
* built-in on the round trip. An empty or whitespace-only text block
|
|
766
|
+
* is the same case taken to the whole block: markdown has no form for
|
|
767
|
+
* either, so it is restored next to its surviving neighbor and
|
|
768
|
+
* dropped along with that neighbor if the neighbor does not survive.
|
|
769
|
+
* Keys aim for what the
|
|
770
|
+
* same edit would have produced in an editor:
|
|
771
|
+
* unchanged, moved, and rewritten-in-place content keeps its keys
|
|
772
|
+
* (rewriting a paragraph in place keeps its identity, like typing over
|
|
773
|
+
* it), a split keeps the key on its first non-empty fragment, a merge
|
|
774
|
+
* keeps the first source block's key, and a `json:object` payload keeps
|
|
775
|
+
* the key it carries, unless reconciliation matches it to stored
|
|
776
|
+
* content, which takes the stored key even over a differing key in the
|
|
777
|
+
* payload. When an insertion or deletion makes positions ambiguous,
|
|
778
|
+
* only clear similarity evidence adopts a key and everything else gets
|
|
779
|
+
* a new one; gathering that evidence is time-capped, so on very large
|
|
780
|
+
* ambiguous edits the set of adopted keys can differ across machine
|
|
781
|
+
* speeds, degrading toward fresh keys.
|
|
782
|
+
* Output keys are unique among siblings. The function does not mutate
|
|
783
|
+
* `storedPortableText` and returns a value, not patches. The `schema`
|
|
784
|
+
* is taken once and governs both directions; pass the same `serialize`
|
|
785
|
+
* options that produced the markdown that was edited. A throwing or
|
|
786
|
+
* stateful custom matcher or renderer propagates or degrades matching
|
|
787
|
+
* respectively.
|
|
788
|
+
* Reconciliation never merges concurrent edits: compare the stored
|
|
789
|
+
* field against the live document before writing the result back.
|
|
790
|
+
* The trades in one line: same-position replacement inherits identity,
|
|
791
|
+
* a count-preserving rewrite pairs positionally (block-level and
|
|
792
|
+
* sibling-level alike), and evidence gathering is capped, degrading to
|
|
793
|
+
* fresh keys.
|
|
794
|
+
*
|
|
795
|
+
* @public
|
|
796
|
+
*/
|
|
797
|
+
declare function applyMarkdownEdit(storedPortableText: ReadonlyArray<PortableTextBlock>, editedMarkdown: string, options?: ApplyMarkdownEditOptions): Array<PortableTextBlock>;
|
|
798
|
+
/**
|
|
799
|
+
* @public
|
|
800
|
+
*/
|
|
801
|
+
declare const DefaultHardBreakRenderer: () => string;
|
|
802
|
+
/**
|
|
803
|
+
* @public
|
|
804
|
+
*/
|
|
805
|
+
declare const DefaultListItemRenderer: PortableTextListItemRenderer;
|
|
806
|
+
type PortableTextBlockRenderer$1 = PortableTextRenderer<PortableTextBlock$1>;
|
|
807
|
+
/**
|
|
808
|
+
* @public
|
|
809
|
+
*/
|
|
810
|
+
declare const DefaultNormalRenderer: PortableTextBlockRenderer$1;
|
|
811
|
+
/**
|
|
812
|
+
* @public
|
|
813
|
+
*/
|
|
814
|
+
declare const DefaultBlockquoteRenderer: PortableTextBlockRenderer$1;
|
|
815
|
+
/**
|
|
816
|
+
* @public
|
|
817
|
+
*/
|
|
818
|
+
declare const DefaultH1Renderer: PortableTextBlockRenderer$1;
|
|
819
|
+
/**
|
|
820
|
+
* @public
|
|
821
|
+
*/
|
|
822
|
+
declare const DefaultH2Renderer: PortableTextBlockRenderer$1;
|
|
823
|
+
/**
|
|
824
|
+
* @public
|
|
825
|
+
*/
|
|
826
|
+
declare const DefaultH3Renderer: PortableTextBlockRenderer$1;
|
|
827
|
+
/**
|
|
828
|
+
* @public
|
|
829
|
+
*/
|
|
830
|
+
declare const DefaultH4Renderer: PortableTextBlockRenderer$1;
|
|
831
|
+
/**
|
|
832
|
+
* @public
|
|
833
|
+
*/
|
|
834
|
+
declare const DefaultH5Renderer: PortableTextBlockRenderer$1;
|
|
835
|
+
/**
|
|
836
|
+
* @public
|
|
837
|
+
*/
|
|
838
|
+
declare const DefaultH6Renderer: PortableTextBlockRenderer$1;
|
|
839
|
+
/**
|
|
840
|
+
* @public
|
|
841
|
+
*/
|
|
842
|
+
declare const DefaultEmRenderer: PortableTextMarkRenderer;
|
|
843
|
+
/**
|
|
844
|
+
* @public
|
|
845
|
+
*/
|
|
846
|
+
declare const DefaultStrongRenderer: PortableTextMarkRenderer;
|
|
847
|
+
/**
|
|
848
|
+
* Renders a `code` decorator from the raw span text, bypassing the escaped
|
|
849
|
+
* `children`: code content is verbatim, never markdown syntax. The
|
|
850
|
+
* backtick fence is widened past the longest run of backticks already in
|
|
851
|
+
* the text (CommonMark: the fence must be longer than any run it encloses).
|
|
852
|
+
*
|
|
853
|
+
* A space is padded on each side when the content starts or ends with a
|
|
854
|
+
* backtick, so the fence and the content's own backtick never merge into
|
|
855
|
+
* one run, and also when the content starts and ends with a space and
|
|
856
|
+
* isn't all whitespace (`text.trim() !== ''`; an all-space code span has
|
|
857
|
+
* nothing else for CommonMark's strip rule to leave behind, so padding it
|
|
858
|
+
* would only add visible spaces), because CommonMark itself would
|
|
859
|
+
* otherwise strip one such space per side on reparse; the padding
|
|
860
|
+
* pre-compensates for that strip.
|
|
861
|
+
*
|
|
862
|
+
* @public
|
|
863
|
+
*/
|
|
864
|
+
declare const DefaultCodeRenderer: PortableTextMarkRenderer;
|
|
865
|
+
/**
|
|
866
|
+
* @public
|
|
867
|
+
*/
|
|
868
|
+
declare const DefaultUnderlineRenderer: PortableTextMarkRenderer;
|
|
869
|
+
/**
|
|
870
|
+
* @public
|
|
871
|
+
*/
|
|
872
|
+
declare const DefaultStrikeThroughRenderer: PortableTextMarkRenderer;
|
|
873
|
+
interface DefaultLink extends TypedObject {
|
|
874
|
+
_type: 'link';
|
|
875
|
+
href: string;
|
|
876
|
+
title: string | undefined;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* @public
|
|
880
|
+
*/
|
|
881
|
+
declare const DefaultLinkRenderer: PortableTextMarkRenderer<DefaultLink>;
|
|
882
|
+
/**
|
|
883
|
+
* @public
|
|
884
|
+
*/
|
|
885
|
+
declare const DefaultCodeBlockRenderer: PortableTextTypeRenderer<{
|
|
886
|
+
_type: 'code';
|
|
887
|
+
code: string;
|
|
888
|
+
language: string | undefined;
|
|
889
|
+
}>;
|
|
890
|
+
/**
|
|
891
|
+
* @public
|
|
892
|
+
*/
|
|
893
|
+
declare const DefaultHorizontalRuleRenderer: PortableTextTypeRenderer;
|
|
894
|
+
/**
|
|
895
|
+
* @public
|
|
896
|
+
*/
|
|
897
|
+
declare const DefaultHtmlRenderer: PortableTextTypeRenderer<{
|
|
898
|
+
_type: 'html';
|
|
899
|
+
html: string;
|
|
900
|
+
}>;
|
|
901
|
+
/**
|
|
902
|
+
* @public
|
|
903
|
+
*/
|
|
904
|
+
declare const DefaultImageRenderer: PortableTextTypeRenderer<{
|
|
905
|
+
_type: 'image';
|
|
906
|
+
src: string;
|
|
907
|
+
alt: string | undefined;
|
|
908
|
+
title: string | undefined;
|
|
909
|
+
}>;
|
|
910
|
+
/**
|
|
911
|
+
* Renders a Portable Text table block-object back to Markdown.
|
|
912
|
+
*
|
|
913
|
+
* The PT `headerRows` field decides the header. Missing `headerRows` and
|
|
914
|
+
* `headerRows === 0` both render headerless: GFM has no headerless form, so
|
|
915
|
+
* an empty header row is emitted and every row goes in the body (that empty
|
|
916
|
+
* header reads back as `headerRows: 0` via `markdownToPortableText`).
|
|
917
|
+
* `headerRows >= 1` promotes `rows[0]` to the header. GFM allows exactly one
|
|
918
|
+
* header row, so header rows beyond the first flatten into the body, lossy,
|
|
919
|
+
* but the extra rows stay on the Portable Text side.
|
|
920
|
+
*
|
|
921
|
+
* Asymmetric tables (rows of varying cell counts) are widened to match
|
|
922
|
+
* the row with the most cells. Narrower rows are padded with empty cells
|
|
923
|
+
* so a GFM parser doesn't silently drop the extra cells in wider rows.
|
|
924
|
+
*
|
|
925
|
+
* @public
|
|
926
|
+
*/
|
|
927
|
+
declare const DefaultTableRenderer: PortableTextTypeRenderer<{
|
|
928
|
+
_type: 'table';
|
|
929
|
+
headerRows: number | undefined;
|
|
930
|
+
alignment: Array<'left' | 'center' | 'right' | null> | undefined;
|
|
931
|
+
rows: Array<{
|
|
932
|
+
_key: string;
|
|
933
|
+
cells: Array<{
|
|
934
|
+
_key: string;
|
|
935
|
+
value: Array<PortableTextBlock$1>;
|
|
936
|
+
}>;
|
|
937
|
+
}>;
|
|
938
|
+
}>;
|
|
939
|
+
/**
|
|
940
|
+
* @public
|
|
941
|
+
*/
|
|
942
|
+
declare const DefaultCalloutRenderer: PortableTextTypeRenderer<{
|
|
943
|
+
_type: 'callout';
|
|
944
|
+
tone: string;
|
|
945
|
+
content: Array<PortableTextBlock$1>;
|
|
946
|
+
}>;
|
|
947
|
+
/**
|
|
948
|
+
* Renders a structural blockquote block-object (the `types.blockquote` shape
|
|
949
|
+
* produced by `markdownToPortableText` when a `types.blockquote` matcher is
|
|
950
|
+
* provided) back to Markdown. Each content block is rendered via the
|
|
951
|
+
* recursive renderer pipeline, joined with blank lines, and every line is
|
|
952
|
+
* prefixed with `> ` to form a Markdown blockquote.
|
|
953
|
+
*
|
|
954
|
+
* Distinct from `DefaultBlockquoteRenderer`, which renders flat-path text
|
|
955
|
+
* blocks with `style: 'blockquote'`.
|
|
956
|
+
*
|
|
957
|
+
* @public
|
|
958
|
+
*/
|
|
959
|
+
declare const DefaultBlockquoteObjectRenderer: PortableTextTypeRenderer<{
|
|
960
|
+
_type: 'blockquote';
|
|
961
|
+
content: Array<PortableTextBlock$1>;
|
|
962
|
+
}>;
|
|
963
|
+
/**
|
|
964
|
+
* Renders a structural list block-object (the `types.list` shape produced by
|
|
965
|
+
* `markdownToPortableText` when a `types.list` matcher is provided) back to
|
|
966
|
+
* Markdown. Items render as `- ` for `kind: 'bullet'`, `1. `/`2. ` for `'number'`,
|
|
967
|
+
* and `- [x] ` / `- [ ] ` for `'task'`. Items can hold any blocks - text blocks,
|
|
968
|
+
* code blocks, callouts, images, and nested lists - and content other than the
|
|
969
|
+
* leading text block is indented to keep it inside the item.
|
|
970
|
+
*
|
|
971
|
+
* @public
|
|
972
|
+
*/
|
|
973
|
+
declare const DefaultListRenderer: PortableTextTypeRenderer<{
|
|
974
|
+
_type: 'list';
|
|
975
|
+
kind: 'bullet' | 'number' | 'task';
|
|
976
|
+
items: Array<{
|
|
977
|
+
_type: 'list-item';
|
|
978
|
+
_key: string;
|
|
979
|
+
checked?: boolean;
|
|
980
|
+
content: Array<PortableTextBlock$1 | TypedObject>;
|
|
981
|
+
}>;
|
|
982
|
+
}>;
|
|
983
|
+
export { type AnnotationMatcher, type ApplyMarkdownEditOptions, type BlockSpacingRenderer, type DecoratorMatcher, DefaultBlockSpacingRenderer, DefaultBlockquoteObjectRenderer, DefaultBlockquoteRenderer, DefaultCalloutRenderer, DefaultCodeBlockRenderer, DefaultCodeRenderer, DefaultEmRenderer, DefaultH1Renderer, DefaultH2Renderer, DefaultH3Renderer, DefaultH4Renderer, DefaultH5Renderer, DefaultH6Renderer, DefaultHardBreakRenderer, DefaultHorizontalRuleRenderer, DefaultHtmlRenderer, DefaultImageRenderer, DefaultLinkRenderer, DefaultListItemRenderer, DefaultListRenderer, DefaultNormalRenderer, DefaultStrikeThroughRenderer, DefaultStrongRenderer, DefaultTableRenderer, DefaultUnderlineRenderer, type Degradation, type ListItemMatcher, type ObjectMatcher, type PortableTextBlockRenderer, type PortableTextListItemRenderer, type PortableTextMarkRenderer, type PortableTextMarkRendererOptions, type PortableTextRenderer, type PortableTextRendererOptions, type PortableTextRenderers, type PortableTextTypeRenderer, type PortableTextTypeRendererOptions, type ReconciliationKeyPath, type ReconciliationReport, type StyleMatcher, applyMarkdownEdit, markdownToPortableText, portableTextToMarkdown };
|
|
755
984
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../node_modules/.pnpm/@portabletext+types@4.0.2/node_modules/@portabletext/types/dist/index.d.ts","../src/from-portable-text/renderers/block-spacing.ts","../src/from-portable-text/types.ts","../src/from-portable-text/portable-text-to-markdown.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../node_modules/.pnpm/@portabletext+types@4.0.2/node_modules/@portabletext/types/dist/index.d.ts","../src/from-portable-text/renderers/block-spacing.ts","../src/from-portable-text/types.ts","../src/from-portable-text/portable-text-to-markdown.ts","../src/to-portable-text/matchers.ts","../src/to-portable-text/markdown-to-portable-text.ts","../src/apply-markdown-edit.ts","../src/from-portable-text/renderers/hard-break.ts","../src/from-portable-text/renderers/list-item.ts","../src/from-portable-text/renderers/style.ts","../src/from-portable-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