Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 6x 6x 6x 6x 6x 2435x 1605x 1605x 1605x 1605x 1605x 1605x 2183x 1605x 6x 240x 240x 240x 6x 182x 6x 6x 6x | import {SliceTypeName} from '../slice'; import {toText as _toHtml} from 'very-small-parser/lib/html/toText'; import {toHast as _toHast} from 'very-small-parser/lib/html/json-ml/toHast'; import {toBase64} from '@jsonjoy.com/base64/lib/toBase64'; import type {JsonMlNode} from 'very-small-parser/lib/html/json-ml/types'; import type {THtmlToken} from 'very-small-parser/lib/html/types'; import type {PeritextMlNode} from '../block/types'; import type {ViewStyle, ViewRange} from '../editor/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; }; export const toHast = (json: PeritextMlNode): THtmlToken => { const jsonml = toJsonMl(json); // console.log(jsonml); const hast = _toHast(jsonml); return hast; }; export const toHtml = (json: PeritextMlNode, tab?: string, indent?: string): string => _toHtml(toHast(json), tab, indent); /** JSON data embedded as Base64 data attribute into HTML clipboard buffer. */ export interface ClipboardData { view?: ViewRange; style?: ViewStyle[]; } const base64Str = (str: string) => toBase64(new TextEncoder().encode(str)); export const exportHtml = (view: ViewRange, node: PeritextMlNode): string => { const data: ClipboardData = {view}; const json = JSON.stringify(data); const jsonBase64 = base64Str(json); const html = toHtml(node) + '<b data-json-joy-peritext="' + jsonBase64 + '"/>'; return html; }; export const exportStyle = (style: ViewStyle[]): string => { const data: ClipboardData = {style}; const json = JSON.stringify(data); const jsonBase64 = base64Str(json); const html = '<b data-json-joy-peritext="' + jsonBase64 + '"/>'; return html; }; |