From 373658bf1cc387150cc04cea87515ac27989b6ae Mon Sep 17 00:00:00 2001 From: name Date: Mon, 1 Aug 2022 13:06:07 -0700 Subject: [PATCH 1/3] deploy --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a259d76..5733548 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ [![NPM version](https://badge.fury.io/js/slate-hyperprint.svg)](http://badge.fury.io/js/slate-hyperprint) +Slate's data model has been built with serialization in mind. Specifically, its text nodes are defined in a way that makes them easier to read at a glance, but also easy to serialize to common formats like HTML and Markdown. +And, because Slate uses plain JSON for its data, you can write serialization logic very easily. + A library to convert Slate models to their slate-hyperscript representation. You can use `slate-hyperprint` as a library to: From 4563e8da0dcf353f8b0f13095f6a61355f83b776 Mon Sep 17 00:00:00 2001 From: name Date: Tue, 2 Aug 2022 13:26:49 -0700 Subject: [PATCH 2/3] deploy --- src/bin/booleans.js | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/bin/booleans.js diff --git a/src/bin/booleans.js b/src/bin/booleans.js new file mode 100644 index 0000000..ac08294 --- /dev/null +++ b/src/bin/booleans.js @@ -0,0 +1,57 @@ +// @flow +import isPlainObject from 'is-plain-object'; +import printComplexDataStructure from './printComplexDataStructure'; + +/* +Based on +https://github.com/algolia/react-element-to-jsx-string/blob/master/src/formatter/formatPropValue.js +*/ + +const escape = (s: string): string => s.replace(/"/g, '"'); + +/* + * Print a tag attribute, for example as 'key={value}' or 'key="value"' or 'key' + */ +function printAttributeValue(value: any): string { + if (typeof value === 'number') { + return `{${String(value)}}`; + } + + if (typeof value === 'string') { + return `"${escape(value)}"`; + } + + // > "Symbols (new in ECMAScript 2015, not yet supported in Flow)" + // @see: https://flow.org/en/docs/types/primitives/ + // $FlowFixMe: Flow does not support Symbol + if (typeof value === 'symbol') { + throw new Error('not implemented'); + } + + if (typeof value === 'function') { + throw new Error('not implemented'); + } + + if (value instanceof Date) { + return `{new Date("${value.toISOString()}")}`; + } + + if (isPlainObject(value) || Array.isArray(value)) { + return `{${printComplexDataStructure(value)}}`; + } + + return `{${String(value)}}`; +} + +/* + * Print a tag attribute to 'key={value}' or 'key' for `true` + */ +function printAttribute(key: string, value: any) { + if (value === true) { + return key; + } + + return `${key}=${printAttributeValue(value)}`; +} + +export default printAttribute; From e98c36f35c1d1538783f1e32dacab1edc86a4e96 Mon Sep 17 00:00:00 2001 From: name Date: Wed, 3 Aug 2022 11:37:53 -0700 Subject: [PATCH 3/3] deploy --- tests/fixtures/text-escaping.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/fixtures/text-escaping.js b/tests/fixtures/text-escaping.js index 9421c4d..27167f6 100644 --- a/tests/fixtures/text-escaping.js +++ b/tests/fixtures/text-escaping.js @@ -2,6 +2,8 @@ import h from '../h'; +const verbose = true; + const space = ' '; const input = (