@novastera-oss/react-native-markdown-display 8.0.1

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.
Files changed (69) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +1206 -0
  3. package/dist/cjs/index.js +164 -0
  4. package/dist/cjs/lib/AstRenderer.js +129 -0
  5. package/dist/cjs/lib/data/textStyleProps.js +24 -0
  6. package/dist/cjs/lib/parser.js +22 -0
  7. package/dist/cjs/lib/renderRules.js +148 -0
  8. package/dist/cjs/lib/styles.js +183 -0
  9. package/dist/cjs/lib/util/Token.js +11 -0
  10. package/dist/cjs/lib/util/cleanupTokens.js +61 -0
  11. package/dist/cjs/lib/util/convertAdditionalStyles.js +39 -0
  12. package/dist/cjs/lib/util/flattenInlineTokens.js +17 -0
  13. package/dist/cjs/lib/util/getTokenTypeByToken.js +21 -0
  14. package/dist/cjs/lib/util/getUniqueID.js +8 -0
  15. package/dist/cjs/lib/util/groupTextTokens.js +30 -0
  16. package/dist/cjs/lib/util/hasParents.js +6 -0
  17. package/dist/cjs/lib/util/omitListItemParagraph.js +33 -0
  18. package/dist/cjs/lib/util/openUrl.js +15 -0
  19. package/dist/cjs/lib/util/removeTextStyleProps.js +15 -0
  20. package/dist/cjs/lib/util/renderInlineAsText.js +16 -0
  21. package/dist/cjs/lib/util/splitTextNonTextNodes.js +21 -0
  22. package/dist/cjs/lib/util/stringToTokens.js +13 -0
  23. package/dist/cjs/lib/util/tokensToAST.js +63 -0
  24. package/dist/cjs/types.js +2 -0
  25. package/dist/esm/index.js +112 -0
  26. package/dist/esm/lib/AstRenderer.js +123 -0
  27. package/dist/esm/lib/data/textStyleProps.js +22 -0
  28. package/dist/esm/lib/parser.js +16 -0
  29. package/dist/esm/lib/renderRules.js +143 -0
  30. package/dist/esm/lib/styles.js +180 -0
  31. package/dist/esm/lib/util/Token.js +8 -0
  32. package/dist/esm/lib/util/cleanupTokens.js +55 -0
  33. package/dist/esm/lib/util/convertAdditionalStyles.js +36 -0
  34. package/dist/esm/lib/util/flattenInlineTokens.js +14 -0
  35. package/dist/esm/lib/util/getTokenTypeByToken.js +18 -0
  36. package/dist/esm/lib/util/getUniqueID.js +5 -0
  37. package/dist/esm/lib/util/groupTextTokens.js +24 -0
  38. package/dist/esm/lib/util/hasParents.js +3 -0
  39. package/dist/esm/lib/util/omitListItemParagraph.js +30 -0
  40. package/dist/esm/lib/util/openUrl.js +12 -0
  41. package/dist/esm/lib/util/removeTextStyleProps.js +9 -0
  42. package/dist/esm/lib/util/renderInlineAsText.js +13 -0
  43. package/dist/esm/lib/util/splitTextNonTextNodes.js +18 -0
  44. package/dist/esm/lib/util/stringToTokens.js +10 -0
  45. package/dist/esm/lib/util/tokensToAST.js +57 -0
  46. package/dist/esm/types.js +1 -0
  47. package/dist/types/index.d.ts +23 -0
  48. package/dist/types/lib/AstRenderer.d.ts +16 -0
  49. package/dist/types/lib/data/textStyleProps.d.ts +2 -0
  50. package/dist/types/lib/parser.d.ts +3 -0
  51. package/dist/types/lib/renderRules.d.ts +3 -0
  52. package/dist/types/lib/styles.d.ts +141 -0
  53. package/dist/types/lib/util/Token.d.ts +8 -0
  54. package/dist/types/lib/util/cleanupTokens.d.ts +2 -0
  55. package/dist/types/lib/util/convertAdditionalStyles.d.ts +1 -0
  56. package/dist/types/lib/util/flattenInlineTokens.d.ts +2 -0
  57. package/dist/types/lib/util/getTokenTypeByToken.d.ts +2 -0
  58. package/dist/types/lib/util/getUniqueID.d.ts +1 -0
  59. package/dist/types/lib/util/groupTextTokens.d.ts +2 -0
  60. package/dist/types/lib/util/hasParents.d.ts +2 -0
  61. package/dist/types/lib/util/omitListItemParagraph.d.ts +2 -0
  62. package/dist/types/lib/util/openUrl.d.ts +1 -0
  63. package/dist/types/lib/util/removeTextStyleProps.d.ts +1 -0
  64. package/dist/types/lib/util/renderInlineAsText.d.ts +2 -0
  65. package/dist/types/lib/util/splitTextNonTextNodes.d.ts +7 -0
  66. package/dist/types/lib/util/stringToTokens.d.ts +2 -0
  67. package/dist/types/lib/util/tokensToAST.d.ts +2 -0
  68. package/dist/types/types.d.ts +59 -0
  69. package/package.json +69 -0
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.FitImage = exports.MarkdownImage = exports.textStyleProps = exports.removeTextStyleProps = exports.styles = exports.MarkdownIt = exports.tokensToAST = exports.stringToTokens = exports.parser = exports.AstRenderer = exports.renderRules = exports.hasParents = exports.openUrl = exports.getUniqueID = void 0;
40
+ const jsx_runtime_1 = require("react/jsx-runtime");
41
+ /**
42
+ * Base Markdown component
43
+ * @author Novastera + contributors
44
+ */
45
+ const react_1 = __importStar(require("react"));
46
+ const react_native_1 = require("react-native");
47
+ const markdown_it_1 = __importDefault(require("markdown-it"));
48
+ exports.MarkdownIt = markdown_it_1.default;
49
+ const expo_image_1 = require("expo-image");
50
+ Object.defineProperty(exports, "MarkdownImage", { enumerable: true, get: function () { return expo_image_1.Image; } });
51
+ Object.defineProperty(exports, "FitImage", { enumerable: true, get: function () { return expo_image_1.Image; } });
52
+ const parser_1 = __importDefault(require("./lib/parser"));
53
+ exports.parser = parser_1.default;
54
+ const getUniqueID_1 = __importDefault(require("./lib/util/getUniqueID"));
55
+ exports.getUniqueID = getUniqueID_1.default;
56
+ const hasParents_1 = __importDefault(require("./lib/util/hasParents"));
57
+ exports.hasParents = hasParents_1.default;
58
+ const openUrl_1 = __importDefault(require("./lib/util/openUrl"));
59
+ exports.openUrl = openUrl_1.default;
60
+ const tokensToAST_1 = __importDefault(require("./lib/util/tokensToAST"));
61
+ exports.tokensToAST = tokensToAST_1.default;
62
+ const renderRules_1 = __importDefault(require("./lib/renderRules"));
63
+ exports.renderRules = renderRules_1.default;
64
+ const AstRenderer_1 = __importDefault(require("./lib/AstRenderer"));
65
+ exports.AstRenderer = AstRenderer_1.default;
66
+ const removeTextStyleProps_1 = __importDefault(require("./lib/util/removeTextStyleProps"));
67
+ exports.removeTextStyleProps = removeTextStyleProps_1.default;
68
+ const styles_1 = require("./lib/styles");
69
+ Object.defineProperty(exports, "styles", { enumerable: true, get: function () { return styles_1.styles; } });
70
+ const stringToTokens_1 = require("./lib/util/stringToTokens");
71
+ Object.defineProperty(exports, "stringToTokens", { enumerable: true, get: function () { return stringToTokens_1.stringToTokens; } });
72
+ const textStyleProps_1 = __importDefault(require("./lib/data/textStyleProps"));
73
+ exports.textStyleProps = textStyleProps_1.default;
74
+ // we use StyleSheet.flatten here to make sure we have an object, in case someone
75
+ // passes in a StyleSheet.create result to the style prop
76
+ const getStyle = (mergeStyle, style) => {
77
+ let useStyles = {};
78
+ const styleRecord = (style !== null && style !== void 0 ? style : {});
79
+ if (mergeStyle === true && style) {
80
+ // make sure we get anything user defuned
81
+ Object.keys(styleRecord).forEach((value) => {
82
+ const styleEntry = styleRecord[value];
83
+ useStyles[value] = {
84
+ ...react_native_1.StyleSheet.flatten(styleEntry !== null && styleEntry !== void 0 ? styleEntry : {}),
85
+ };
86
+ });
87
+ // combine any existing styles
88
+ Object.keys(styles_1.styles).forEach((value) => {
89
+ const styleEntry = styleRecord[value];
90
+ useStyles[value] = {
91
+ ...styles_1.styles[value],
92
+ ...react_native_1.StyleSheet.flatten(styleEntry !== null && styleEntry !== void 0 ? styleEntry : {}),
93
+ };
94
+ });
95
+ }
96
+ else {
97
+ useStyles = {
98
+ ...styles_1.styles,
99
+ };
100
+ if (style) {
101
+ Object.keys(styleRecord).forEach((value) => {
102
+ const styleEntry = styleRecord[value];
103
+ useStyles[value] = {
104
+ ...react_native_1.StyleSheet.flatten(styleEntry !== null && styleEntry !== void 0 ? styleEntry : {}),
105
+ };
106
+ });
107
+ }
108
+ }
109
+ Object.keys(useStyles).forEach((value) => {
110
+ useStyles['_VIEW_SAFE_' + value] = (0, removeTextStyleProps_1.default)(useStyles[value]);
111
+ });
112
+ return react_native_1.StyleSheet.create(useStyles);
113
+ };
114
+ const getRenderer = (renderer, rules, style, mergeStyle = true, onLinkPress, maxTopLevelChildren, topLevelMaxExceededItem, allowedImageHandlers, defaultImageHandler, debugPrintTree) => {
115
+ if (renderer && rules) {
116
+ console.warn('react-native-markdown-display you are using renderer and rules at the same time. This is not possible, props.rules is ignored');
117
+ }
118
+ if (renderer && style) {
119
+ console.warn('react-native-markdown-display you are using renderer and style at the same time. This is not possible, props.style is ignored');
120
+ }
121
+ // these checks are here to prevent extra overhead.
122
+ if (renderer) {
123
+ if (typeof renderer === 'function') {
124
+ return renderer;
125
+ }
126
+ if (typeof renderer.render === 'function') {
127
+ return renderer;
128
+ }
129
+ throw new Error('Provided renderer is not compatible with function or AstRenderer. please change');
130
+ }
131
+ const useStyles = getStyle(mergeStyle, style);
132
+ return new AstRenderer_1.default({
133
+ ...renderRules_1.default,
134
+ ...(rules || {}),
135
+ }, useStyles, onLinkPress, maxTopLevelChildren, topLevelMaxExceededItem, allowedImageHandlers, defaultImageHandler, debugPrintTree);
136
+ };
137
+ const Markdown = react_1.default.memo(({ children, renderer, rules, style, mergeStyle = true, markdownit = (0, markdown_it_1.default)({
138
+ typographer: true,
139
+ }), onLinkPress, maxTopLevelChildren = null, topLevelMaxExceededItem = (0, jsx_runtime_1.jsx)(react_native_1.Text, { children: "..." }, "dotdotdot"), allowedImageHandlers = [
140
+ 'data:image/png;base64',
141
+ 'data:image/gif;base64',
142
+ 'data:image/jpeg;base64',
143
+ 'https://',
144
+ 'http://',
145
+ ], defaultImageHandler = 'https://', debugPrintTree = false, }) => {
146
+ const memoizedRenderer = (0, react_1.useMemo)(() => getRenderer(renderer, rules, style, mergeStyle, onLinkPress, maxTopLevelChildren, topLevelMaxExceededItem, allowedImageHandlers, defaultImageHandler, debugPrintTree), [
147
+ maxTopLevelChildren,
148
+ onLinkPress,
149
+ renderer,
150
+ rules,
151
+ style,
152
+ mergeStyle,
153
+ topLevelMaxExceededItem,
154
+ allowedImageHandlers,
155
+ defaultImageHandler,
156
+ debugPrintTree,
157
+ ]);
158
+ const memoizedParser = (0, react_1.useMemo)(() => markdownit, [markdownit]);
159
+ const render = typeof memoizedRenderer === 'function'
160
+ ? memoizedRenderer
161
+ : memoizedRenderer.render;
162
+ return (0, parser_1.default)(children, render, memoizedParser);
163
+ });
164
+ exports.default = Markdown;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_native_1 = require("react-native");
7
+ const getUniqueID_1 = __importDefault(require("./util/getUniqueID"));
8
+ const convertAdditionalStyles_1 = __importDefault(require("./util/convertAdditionalStyles"));
9
+ const textStyleProps_1 = __importDefault(require("./data/textStyleProps"));
10
+ class AstRenderer {
11
+ constructor(renderRules, style, onLinkPress, maxTopLevelChildren, topLevelMaxExceededItem, allowedImageHandlers, defaultImageHandler, debugPrintTree) {
12
+ this.getRenderFunction = (type) => {
13
+ const renderFunction = this._renderRules[type];
14
+ if (!renderFunction) {
15
+ console.warn(`Warning, unknown render rule encountered: ${type}. 'unknown' render rule used (by default, returns null - nothing rendered)`);
16
+ return this._renderRules.unknown;
17
+ }
18
+ return renderFunction;
19
+ };
20
+ this.renderNode = (node, parentNodes, isRoot = false) => {
21
+ var _a, _b;
22
+ const renderFunction = this.getRenderFunction(node.type);
23
+ const parents = [...parentNodes];
24
+ if (this._debugPrintTree === true) {
25
+ let str = '';
26
+ for (let a = 0; a < parents.length; a++) {
27
+ str = str + '-';
28
+ }
29
+ console.log(`${str}${node.type}`);
30
+ }
31
+ parents.unshift(node);
32
+ // calculate the children first
33
+ let children = node.children.map((value) => {
34
+ return this.renderNode(value, parents);
35
+ });
36
+ // render any special types of nodes that have different renderRule function signatures
37
+ if (node.type === 'link' || node.type === 'blocklink') {
38
+ return renderFunction(node, children, parentNodes, this._style, this._onLinkPress);
39
+ }
40
+ if (node.type === 'image') {
41
+ return renderFunction(node, children, parentNodes, this._style, (_a = this._allowedImageHandlers) !== null && _a !== void 0 ? _a : [], (_b = this._defaultImageHandler) !== null && _b !== void 0 ? _b : null);
42
+ }
43
+ // We are at the bottom of some tree - grab all the parent styles
44
+ // this effectively grabs the styles from parents and
45
+ // applies them in order of priority parent (least) to child (most)
46
+ // to allow styling global, then lower down things individually
47
+ // we have to handle list_item seperately here because they have some child
48
+ // pseudo classes that need the additional style props from parents passed down to them
49
+ if (children.length === 0 || node.type === 'list_item') {
50
+ const styleObj = {};
51
+ for (let a = parentNodes.length - 1; a > -1; a--) {
52
+ // grab and additional attributes specified by markdown-it
53
+ let refStyle = {};
54
+ const styleAttr = parentNodes[a].attributes.style;
55
+ if (typeof styleAttr === 'string') {
56
+ refStyle = (0, convertAdditionalStyles_1.default)(styleAttr);
57
+ }
58
+ // combine in specific styles for the object
59
+ if (this._style[parentNodes[a].type]) {
60
+ refStyle = {
61
+ ...refStyle,
62
+ ...react_native_1.StyleSheet.flatten(this._style[parentNodes[a].type]),
63
+ };
64
+ // workaround for list_items and their content cascading down the tree
65
+ if (parentNodes[a].type === 'list_item') {
66
+ let contentStyle = {};
67
+ if (parentNodes[a + 1].type === 'bullet_list') {
68
+ contentStyle = this._style
69
+ .bullet_list_content;
70
+ }
71
+ else if (parentNodes[a + 1].type === 'ordered_list') {
72
+ contentStyle = this._style
73
+ .ordered_list_content;
74
+ }
75
+ refStyle = {
76
+ ...refStyle,
77
+ ...react_native_1.StyleSheet.flatten(contentStyle),
78
+ };
79
+ }
80
+ }
81
+ // then work out if any of them are text styles that should be used in the end.
82
+ const arr = Object.keys(refStyle);
83
+ for (let b = 0; b < arr.length; b++) {
84
+ if (textStyleProps_1.default.includes(arr[b])) {
85
+ styleObj[arr[b]] = refStyle[arr[b]];
86
+ }
87
+ }
88
+ }
89
+ const baseRenderFunction = renderFunction;
90
+ return baseRenderFunction(node, children, parentNodes, this._style, styleObj);
91
+ }
92
+ // cull top level children
93
+ if (isRoot === true &&
94
+ this._maxTopLevelChildren &&
95
+ children.length > this._maxTopLevelChildren) {
96
+ children = children.slice(0, this._maxTopLevelChildren);
97
+ if (this._topLevelMaxExceededItem) {
98
+ children.push(this._topLevelMaxExceededItem);
99
+ }
100
+ }
101
+ // render anythign else that has a normal signature
102
+ const baseRenderFunction = renderFunction;
103
+ return baseRenderFunction(node, children, parentNodes, this._style);
104
+ };
105
+ this.render = (nodes) => {
106
+ const root = {
107
+ type: 'body',
108
+ sourceType: 'body',
109
+ key: (0, getUniqueID_1.default)(),
110
+ content: '',
111
+ markup: '',
112
+ tokenIndex: -1,
113
+ index: 0,
114
+ attributes: {},
115
+ children: nodes,
116
+ };
117
+ return this.renderNode(root, [], true);
118
+ };
119
+ this._renderRules = renderRules;
120
+ this._style = style;
121
+ this._onLinkPress = onLinkPress;
122
+ this._maxTopLevelChildren = maxTopLevelChildren;
123
+ this._topLevelMaxExceededItem = topLevelMaxExceededItem;
124
+ this._allowedImageHandlers = allowedImageHandlers;
125
+ this._defaultImageHandler = defaultImageHandler;
126
+ this._debugPrintTree = debugPrintTree;
127
+ }
128
+ }
129
+ exports.default = AstRenderer;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const textStyleProps = [
4
+ 'textShadowOffset',
5
+ 'color',
6
+ 'fontSize',
7
+ 'fontStyle',
8
+ 'fontWeight',
9
+ 'lineHeight',
10
+ 'textAlign',
11
+ 'textDecorationLine',
12
+ 'textShadowColor',
13
+ 'fontFamily',
14
+ 'textShadowRadius',
15
+ 'includeFontPadding',
16
+ 'textAlignVertical',
17
+ 'fontVariant',
18
+ 'letterSpacing',
19
+ 'textDecorationColor',
20
+ 'textDecorationStyle',
21
+ 'textTransform',
22
+ 'writingDirection',
23
+ ];
24
+ exports.default = textStyleProps;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = parser;
7
+ const tokensToAST_1 = __importDefault(require("./util/tokensToAST"));
8
+ const stringToTokens_1 = require("./util/stringToTokens");
9
+ const cleanupTokens_1 = require("./util/cleanupTokens");
10
+ const groupTextTokens_1 = __importDefault(require("./util/groupTextTokens"));
11
+ const omitListItemParagraph_1 = __importDefault(require("./util/omitListItemParagraph"));
12
+ function parser(source, renderer, markdownIt) {
13
+ if (Array.isArray(source)) {
14
+ return renderer(source);
15
+ }
16
+ let tokens = (0, stringToTokens_1.stringToTokens)(source, markdownIt);
17
+ tokens = (0, cleanupTokens_1.cleanupTokens)(tokens);
18
+ tokens = (0, groupTextTokens_1.default)(tokens);
19
+ tokens = (0, omitListItemParagraph_1.default)(tokens);
20
+ const astTree = (0, tokensToAST_1.default)(tokens);
21
+ return renderer(astTree);
22
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const react_native_1 = require("react-native");
8
+ const expo_image_1 = require("expo-image");
9
+ const openUrl_1 = __importDefault(require("./util/openUrl"));
10
+ const hasParents_1 = __importDefault(require("./util/hasParents"));
11
+ const textStyleProps_1 = __importDefault(require("./data/textStyleProps"));
12
+ const baseRule = (fn) => fn;
13
+ const linkRule = (fn) => fn;
14
+ const imageRule = (fn) => fn;
15
+ const renderRules = {
16
+ // when unknown elements are introduced, so it wont break
17
+ unknown: baseRule(() => null),
18
+ // The main container
19
+ body: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_body, children: children }, node.key))),
20
+ // Headings
21
+ heading1: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_heading1, children: children }, node.key))),
22
+ heading2: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_heading2, children: children }, node.key))),
23
+ heading3: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_heading3, children: children }, node.key))),
24
+ heading4: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_heading4, children: children }, node.key))),
25
+ heading5: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_heading5, children: children }, node.key))),
26
+ heading6: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_heading6, children: children }, node.key))),
27
+ // Horizontal Rule
28
+ hr: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_hr }, node.key))),
29
+ // Emphasis
30
+ strong: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.strong, children: children }, node.key))),
31
+ em: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.em, children: children }, node.key))),
32
+ s: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.s, children: children }, node.key))),
33
+ // Blockquotes
34
+ blockquote: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_blockquote, children: children }, node.key))),
35
+ // Lists
36
+ bullet_list: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_bullet_list, children: children }, node.key))),
37
+ ordered_list: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_ordered_list, children: children }, node.key))),
38
+ // this is a unique and quite annoying render rule because it has
39
+ // child items that can be styled (the list icon and the list content)
40
+ // outside of the AST tree so there are some work arounds in the
41
+ // AST renderer specifically to get the styling right here
42
+ list_item: baseRule((node, children, parent, styles, inheritedStyles = {}) => {
43
+ // we need to grab any text specific stuff here that is applied on the list_item style
44
+ // and apply it onto bullet_list_icon. the AST renderer has some workaround code to make
45
+ // the content classes apply correctly to the child AST tree items as well
46
+ // as code that forces the creation of the inheritedStyles object for list_items
47
+ const refStyle = {
48
+ ...inheritedStyles,
49
+ ...react_native_1.StyleSheet.flatten(styles.list_item),
50
+ };
51
+ const arr = Object.keys(refStyle);
52
+ const modifiedInheritedStylesObj = {};
53
+ for (let b = 0; b < arr.length; b++) {
54
+ if (textStyleProps_1.default.includes(arr[b])) {
55
+ modifiedInheritedStylesObj[arr[b]] = refStyle[arr[b]];
56
+ }
57
+ }
58
+ if ((0, hasParents_1.default)(parent, 'bullet_list')) {
59
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles._VIEW_SAFE_list_item, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [modifiedInheritedStylesObj, styles.bullet_list_icon], accessible: false, children: react_native_1.Platform.select({
60
+ android: '\u2022',
61
+ ios: '\u00B7',
62
+ default: '\u2022',
63
+ }) }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_bullet_list_content, children: children })] }, node.key));
64
+ }
65
+ if ((0, hasParents_1.default)(parent, 'ordered_list')) {
66
+ const orderedListIndex = parent.findIndex((el) => el.type === 'ordered_list');
67
+ const orderedList = parent[orderedListIndex];
68
+ let listItemNumber;
69
+ if (orderedList.attributes && orderedList.attributes.start) {
70
+ listItemNumber = orderedList.attributes.start + node.index;
71
+ }
72
+ else {
73
+ listItemNumber = node.index + 1;
74
+ }
75
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles._VIEW_SAFE_list_item, children: [(0, jsx_runtime_1.jsxs)(react_native_1.Text, { style: [modifiedInheritedStylesObj, styles.ordered_list_icon], children: [listItemNumber, node.markup] }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_ordered_list_content, children: children })] }, node.key));
76
+ }
77
+ // we should not need this, but just in case
78
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_list_item, children: children }, node.key));
79
+ }),
80
+ // Code
81
+ code_inline: baseRule((node, children, parent, styles, inheritedStyles = {}) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [inheritedStyles, styles.code_inline], children: node.content }, node.key))),
82
+ code_block: baseRule((node, children, parent, styles, inheritedStyles = {}) => {
83
+ // we trim new lines off the end of code blocks because the parser sends an extra one.
84
+ let { content } = node;
85
+ if (typeof node.content === 'string' &&
86
+ node.content.charAt(node.content.length - 1) === '\n') {
87
+ content = node.content.substring(0, node.content.length - 1);
88
+ }
89
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [inheritedStyles, styles.code_block], children: content }, node.key));
90
+ }),
91
+ fence: baseRule((node, children, parent, styles, inheritedStyles = {}) => {
92
+ // we trim new lines off the end of code blocks because the parser sends an extra one.
93
+ let { content } = node;
94
+ if (typeof node.content === 'string' &&
95
+ node.content.charAt(node.content.length - 1) === '\n') {
96
+ content = node.content.substring(0, node.content.length - 1);
97
+ }
98
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [inheritedStyles, styles.fence], children: content }, node.key));
99
+ }),
100
+ // Tables
101
+ table: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_table, children: children }, node.key))),
102
+ thead: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_thead, children: children }, node.key))),
103
+ tbody: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_tbody, children: children }, node.key))),
104
+ th: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_th, children: children }, node.key))),
105
+ tr: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_tr, children: children }, node.key))),
106
+ td: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_td, children: children }, node.key))),
107
+ // Links
108
+ link: linkRule((node, children, parent, styles, onLinkPress) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.link, onPress: () => (0, openUrl_1.default)(node.attributes.href, onLinkPress), children: children }, node.key))),
109
+ blocklink: linkRule((node, children, parent, styles, onLinkPress) => ((0, jsx_runtime_1.jsx)(react_native_1.TouchableWithoutFeedback, { onPress: () => (0, openUrl_1.default)(node.attributes.href, onLinkPress), style: styles.blocklink, children: (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.image, children: children }) }, node.key))),
110
+ // Images
111
+ image: imageRule((node, children, parent, styles, allowedImageHandlers, defaultImageHandler) => {
112
+ const { src, alt } = node.attributes;
113
+ if (!src) {
114
+ return null;
115
+ }
116
+ // we check that the source starts with at least one of the elements in allowedImageHandlers
117
+ const show = allowedImageHandlers.filter((value) => {
118
+ return src.toLowerCase().startsWith(value.toLowerCase());
119
+ }).length > 0;
120
+ if (show === false && defaultImageHandler === null) {
121
+ return null;
122
+ }
123
+ const imageUri = show === true ? src : `${defaultImageHandler !== null && defaultImageHandler !== void 0 ? defaultImageHandler : ''}${src}`;
124
+ const imageProps = {
125
+ key: node.key,
126
+ style: styles._VIEW_SAFE_image,
127
+ source: {
128
+ uri: imageUri,
129
+ },
130
+ };
131
+ if (alt) {
132
+ imageProps.accessible = true;
133
+ imageProps.accessibilityLabel = alt;
134
+ }
135
+ return (0, jsx_runtime_1.jsx)(expo_image_1.Image, { ...imageProps });
136
+ }),
137
+ // Text Output
138
+ text: baseRule((node, children, parent, styles, inheritedStyles = {}) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [inheritedStyles, styles.text], children: node.content }, node.key))),
139
+ textgroup: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.textgroup, children: children }, node.key))),
140
+ paragraph: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_paragraph, children: children }, node.key))),
141
+ hardbreak: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.hardbreak, children: '\n' }, node.key))),
142
+ softbreak: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.softbreak, children: '\n' }, node.key))),
143
+ // Believe these are never used but retained for completeness
144
+ pre: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles._VIEW_SAFE_pre, children: children }, node.key))),
145
+ inline: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.inline, children: children }, node.key))),
146
+ span: baseRule((node, children, parent, styles) => ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.span, children: children }, node.key))),
147
+ };
148
+ exports.default = renderRules;
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.styles = void 0;
4
+ const react_native_1 = require("react-native");
5
+ // this is converted to a stylesheet internally at run time with StyleSheet.create(
6
+ exports.styles = {
7
+ // The main container
8
+ body: {},
9
+ // Headings
10
+ heading1: {
11
+ flexDirection: 'row',
12
+ fontSize: 32,
13
+ },
14
+ heading2: {
15
+ flexDirection: 'row',
16
+ fontSize: 24,
17
+ },
18
+ heading3: {
19
+ flexDirection: 'row',
20
+ fontSize: 18,
21
+ },
22
+ heading4: {
23
+ flexDirection: 'row',
24
+ fontSize: 16,
25
+ },
26
+ heading5: {
27
+ flexDirection: 'row',
28
+ fontSize: 13,
29
+ },
30
+ heading6: {
31
+ flexDirection: 'row',
32
+ fontSize: 11,
33
+ },
34
+ // Horizontal Rule
35
+ hr: {
36
+ backgroundColor: '#000000',
37
+ height: 1,
38
+ },
39
+ // Emphasis
40
+ strong: {
41
+ fontWeight: 'bold',
42
+ },
43
+ em: {
44
+ fontStyle: 'italic',
45
+ },
46
+ s: {
47
+ textDecorationLine: 'line-through',
48
+ },
49
+ // Blockquotes
50
+ blockquote: {
51
+ backgroundColor: '#F5F5F5',
52
+ borderColor: '#CCC',
53
+ borderLeftWidth: 4,
54
+ marginLeft: 5,
55
+ paddingHorizontal: 5,
56
+ },
57
+ // Lists
58
+ bullet_list: {},
59
+ ordered_list: {},
60
+ list_item: {
61
+ flexDirection: 'row',
62
+ justifyContent: 'flex-start',
63
+ },
64
+ // @pseudo class, does not have a unique render rule
65
+ bullet_list_icon: {
66
+ marginLeft: 10,
67
+ marginRight: 10,
68
+ },
69
+ // @pseudo class, does not have a unique render rule
70
+ bullet_list_content: {
71
+ flex: 1,
72
+ },
73
+ // @pseudo class, does not have a unique render rule
74
+ ordered_list_icon: {
75
+ marginLeft: 10,
76
+ marginRight: 10,
77
+ },
78
+ // @pseudo class, does not have a unique render rule
79
+ ordered_list_content: {
80
+ flex: 1,
81
+ },
82
+ // Code
83
+ code_inline: {
84
+ borderWidth: 1,
85
+ borderColor: '#CCCCCC',
86
+ backgroundColor: '#f5f5f5',
87
+ padding: 10,
88
+ borderRadius: 4,
89
+ ...react_native_1.Platform.select({
90
+ ['ios']: {
91
+ fontFamily: 'Courier',
92
+ },
93
+ ['android']: {
94
+ fontFamily: 'monospace',
95
+ },
96
+ }),
97
+ },
98
+ code_block: {
99
+ borderWidth: 1,
100
+ borderColor: '#CCCCCC',
101
+ backgroundColor: '#f5f5f5',
102
+ padding: 10,
103
+ borderRadius: 4,
104
+ ...react_native_1.Platform.select({
105
+ ['ios']: {
106
+ fontFamily: 'Courier',
107
+ },
108
+ ['android']: {
109
+ fontFamily: 'monospace',
110
+ },
111
+ }),
112
+ },
113
+ fence: {
114
+ borderWidth: 1,
115
+ borderColor: '#CCCCCC',
116
+ backgroundColor: '#f5f5f5',
117
+ padding: 10,
118
+ borderRadius: 4,
119
+ ...react_native_1.Platform.select({
120
+ ['ios']: {
121
+ fontFamily: 'Courier',
122
+ },
123
+ ['android']: {
124
+ fontFamily: 'monospace',
125
+ },
126
+ }),
127
+ },
128
+ // Tables
129
+ table: {
130
+ borderWidth: 1,
131
+ borderColor: '#000000',
132
+ borderRadius: 3,
133
+ },
134
+ thead: {},
135
+ tbody: {},
136
+ th: {
137
+ flex: 1,
138
+ padding: 5,
139
+ },
140
+ tr: {
141
+ borderBottomWidth: 1,
142
+ borderColor: '#000000',
143
+ flexDirection: 'row',
144
+ },
145
+ td: {
146
+ flex: 1,
147
+ padding: 5,
148
+ },
149
+ // Links
150
+ link: {
151
+ textDecorationLine: 'underline',
152
+ },
153
+ blocklink: {
154
+ flex: 1,
155
+ borderColor: '#000000',
156
+ borderBottomWidth: 1,
157
+ },
158
+ // Images
159
+ image: {
160
+ flex: 1,
161
+ },
162
+ // Text Output
163
+ text: {},
164
+ textgroup: {},
165
+ paragraph: {
166
+ marginTop: 10,
167
+ marginBottom: 10,
168
+ flexWrap: 'wrap',
169
+ flexDirection: 'row',
170
+ alignItems: 'flex-start',
171
+ justifyContent: 'flex-start',
172
+ width: '100%',
173
+ },
174
+ hardbreak: {
175
+ width: '100%',
176
+ height: 1,
177
+ },
178
+ softbreak: {},
179
+ // Believe these are never used but retained for completeness
180
+ pre: {},
181
+ inline: {},
182
+ span: {},
183
+ };