Skip to content

Commit c19f7b1

Browse files
committed
docs: add customization example
close #47
1 parent 337dcc7 commit c19f7b1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: README.md

+18
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ md.renderer.rules.footnote_block_open = () => (
111111
);
112112
```
113113

114+
Here's another example that customizes footnotes for epub books:
115+
116+
```js
117+
const backrefLabel = 'back to text';
118+
119+
const epubRules = {
120+
footnote_ref: ['<a', '<a epub:type="noteref"'],
121+
footnote_open: ['<li', '<li epub:type="footnote"'],
122+
footnote_anchor: ['<a', `<a aria-label="${backrefLabel}"`],
123+
}
124+
125+
Object.keys(epubRules).map(rule => {
126+
let defaultRender = md.renderer.rules[rule];
127+
md.renderer.rules[rule] = (tokens, idx, options, env, self) => {
128+
return defaultRender(tokens, idx, options, env, self).replace(...epubRules[rule]);
129+
}
130+
})
131+
```
114132

115133
## License
116134

0 commit comments

Comments
 (0)