Skip to content

Commit 042e25a

Browse files
committed
feat(Children): Added support for custom children
1 parent 89ab0c4 commit 042e25a

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ new RemarkableReactRenderer({
140140
// Use this to also handle your custom remarkable tokens!
141141
custom_token: 'custom_component',
142142
},
143+
144+
// This enables you to quickly configure how children are rendered for tokens.
145+
// By default the `content` of a token is mapped to `children`.
146+
children: {
147+
footnote_anchor: () => `↩`,
148+
},
143149
});
144150
```
145151

‎src/Renderer.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import assign from './assign';
3+
import defaultChildren from './defaultChildren';
34
import defaultComponents from './defaultComponents';
45
import defaultRemarkableProps from './defaultRemarkableProps';
56
import defaultTokens from './defaultTokens';
@@ -10,6 +11,7 @@ export default class Renderer {
1011
this.options = assign({
1112
keyGen: (token, index) => index,
1213
}, options, {
14+
children: assign({}, defaultChildren, options.children),
1315
components: assign({}, defaultComponents, options.components),
1416
remarkableProps: assign({}, defaultRemarkableProps, options.remarkableProps),
1517
tokens: assign({}, defaultTokens, options.tokens),

‎src/TokenTree.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export default class TokenTree {
3636
return ({
3737
type,
3838
props: this.buildTokenProps(type, token),
39-
children: token.content,
39+
children: children || (this.options.children[token.type]
40+
? this.options.children[token.type](token, this.rOptions)
41+
: token.content),
4042
});
4143
}
4244

‎src/defaultChildren.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
htmlblock: ({ content }, { html }) => html ? null : content,
3+
};

0 commit comments

Comments
 (0)