-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-crdt-extensions): 🎸 improve to JSON-ML export
- Loading branch information
Showing
4 changed files
with
56 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {SliceTypeName} from "../slice"; | ||
import type {JsonMlNode} from "../../../json-ml"; | ||
import type {PeritextMlNode} from "../block/types"; | ||
|
||
export const toJsonMl = (json: PeritextMlNode): JsonMlNode => { | ||
if (typeof json === 'string') return json; | ||
const [tag, attr, ...children] = json; | ||
const namedTag = tag === '' ? tag : SliceTypeName[tag as any]; | ||
const htmlTag = namedTag ?? (attr?.inline ? 'span' : 'div'); | ||
const htmlAttr = attr && (attr.data !== void 0) ? {'data-attr': JSON.stringify(attr.data)} : null; | ||
const htmlNode: JsonMlNode = [htmlTag, htmlAttr]; | ||
const length = children.length; | ||
for (let i = 0; i < length; i++) htmlNode.push(toJsonMl(children[i])); | ||
return htmlNode; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export type * from './types'; | ||
export {CursorAnchor, SliceTypeName as CommonSliceType} from './constants'; | ||
export {CursorAnchor, SliceTypeName, SliceTypeName as CommonSliceType} from './constants'; |