MCPcopy Create free account
hub / github.com/Thinkmill/react-markings / customize

Function customize

index.js:79–113  ·  view source on GitHub ↗
(opts /*: Options */)

Source from the content-addressed store, hash-verified

77*/
78
79function customize(opts /*: Options */) {
80 var renderers = opts.renderers || {};
81
82 return function markings(strings /*: Array<string> */ /*::, ...values: Array<ReactNode> */) {
83 var values = Array.prototype.slice.call(arguments, 1);
84 var input = stripIndent(strings.join(PLACEHOLDER));
85 var parser = new Parser();
86 var ast = parser.parse(input);
87
88 if (!validate(ast)) {
89 throw new Error('react-markings cannot interpolate React elements non-block positions');
90 }
91
92 var index = 0;
93 var renderer = new Renderer({
94 renderers: Object.assign({}, renderers, {
95 Paragraph: function(props) {
96 if (props.children.length === 1 && props.children[0] === PLACEHOLDER) {
97 var value = values[index];
98 index = index + 1 < values.length ? index + 1 : 0;
99 return value;
100 } else if (renderers.Paragraph) {
101 return renderers.Paragraph(props);
102 } else if (renderers.paragraph) {
103 return renderers.paragraph(props);
104 } else {
105 return React.createElement('p', {}, props.children);
106 }
107 },
108 })
109 });
110
111 return React.createElement('div', {}, renderer.render(ast));
112 }
113}
114
115var md = customize({});
116md.customize = customize;

Callers 1

index.jsFile · 0.85

Calls 2

stripIndentFunction · 0.85
validateFunction · 0.85

Tested by

no test coverage detected