Skip to content

Commit da0553c

Browse files
committed
readme update
1 parent 3f7fa2c commit da0553c

File tree

1 file changed

+58
-60
lines changed

1 file changed

+58
-60
lines changed

README.md

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -323,66 +323,11 @@ And some additional, less used options:
323323

324324
Plugins for **extra** syntax support can be added using any markdown-it compatible plugins - [see plugins](https://www.npmjs.com/browse/keyword/markdown-it-plugin) for documentation from markdown-it. An example for integration follows:
325325

326-
#### Step 1
327-
328-
Inspect what the plugin will output - this can be achieved with the following code, using `markdown-it-block-embed` as an example for adding video support:
329-
330-
```jsx
331-
import Markdown, { MarkdownIt } from 'react-native-markdown-display';
332-
import blockEmbedPlugin from 'markdown-it-block-embed';
333-
334-
const markdownItInstance =
335-
MarkdownIt({typographer: true})
336-
.use(blockEmbedPlugin, {
337-
containerClassName: "video-embed"
338-
});
339-
340-
const copy = `
341-
# Some header
342-
343-
@[youtube](lJIrF4YjHfQ)
344-
`;
345-
346-
// this shows you the tree that is used by the react-native-markdown-display
347-
const astTree = markdownItInstance.parse(copy, {});
348-
console.log(astTree);
349-
350-
//this contains the html that would be generated - not used by react-native-markdown-display but useful for reference
351-
const html = markdownItInstance.render(copy);
352-
console.log(html);
353-
354-
```
355-
356-
The above code will output something like this:
357-
358-
```
359-
astTree:
360-
361-
(4) [Token, Token, Token, Token]
362-
363-
0: Token {type: "heading_open", tag: "h1", attrs: null, map: Array(2), nesting: 1, …}
364-
1: Token {type: "inline", tag: "", attrs: null, map: Array(2), nesting: 0, …}
365-
2: Token {type: "heading_close", tag: "h1", attrs: null, map: null, nesting: -1, …}
366-
3: Token {type: "video", tag: "div", attrs: null, map: Array(2), nesting: 0, …}
367-
368-
length: 4
369-
```
370-
371-
```
372-
html:
373-
374-
375-
<h1>Some header</h1>
376-
<div class="video-embed block-embed-service-youtube"><iframe type="text/html" src="//www.youtube.com/embed/lJIrF4YjHfQ" frameborder="0" width="640" height="390" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>
377-
```
378-
379-
#### Step 2
380326

381-
Identify the new components and integrate the plugin with a rendered compoonent.
327+
#### Step 1
382328

383-
In the example above, the heading_open, inline and heading_close tags are all handled by the existing code base, but we need to handle the **'video'** type.
329+
Identify the new components and integrate the plugin with a rendered compoonent. We can use the `debugPrintTree` property to see what rules we are rendering:
384330

385-
Note, in the example below we use the `debugPrintTree` property to see what rules we are rendering:
386331

387332
```jsx
388333
import React from 'react';
@@ -439,16 +384,16 @@ body
439384
-video
440385
```
441386

442-
with the following error message
387+
With the following error message:
443388

444389
```
445390
Warning, unknown render rule encountered: video. 'unknown' render rule used (by default, returns null - nothing rendered)
446391
```
447392

448393

449-
#### Step 3
394+
#### Step 2
450395

451-
We need to create the render rules and styles to handle this new **'video'** component
396+
We need to create the **render rules** and **styles** to handle this new **'video'** component
452397

453398

454399
```jsx
@@ -538,6 +483,59 @@ And all of the video properties needed to render something meaningful are on the
538483
type: "video"
539484
```
540485

486+
#### Other Debugging
487+
488+
You can do some additional debugging of what the markdown instance is spitting out like this:
489+
490+
```jsx
491+
import Markdown, { MarkdownIt } from 'react-native-markdown-display';
492+
import blockEmbedPlugin from 'markdown-it-block-embed';
493+
494+
const markdownItInstance =
495+
MarkdownIt({typographer: true})
496+
.use(blockEmbedPlugin, {
497+
containerClassName: "video-embed"
498+
});
499+
500+
const copy = `
501+
# Some header
502+
503+
@[youtube](lJIrF4YjHfQ)
504+
`;
505+
506+
// this shows you the tree that is used by the react-native-markdown-display
507+
const astTree = markdownItInstance.parse(copy, {});
508+
console.log(astTree);
509+
510+
//this contains the html that would be generated - not used by react-native-markdown-display but useful for reference
511+
const html = markdownItInstance.render(copy);
512+
console.log(html);
513+
514+
```
515+
516+
The above code will output something like this:
517+
518+
```
519+
astTree:
520+
521+
(4) [Token, Token, Token, Token]
522+
523+
0: Token {type: "heading_open", tag: "h1", attrs: null, map: Array(2), nesting: 1, …}
524+
1: Token {type: "inline", tag: "", attrs: null, map: Array(2), nesting: 0, …}
525+
2: Token {type: "heading_close", tag: "h1", attrs: null, map: null, nesting: -1, …}
526+
3: Token {type: "video", tag: "div", attrs: null, map: Array(2), nesting: 0, …}
527+
528+
length: 4
529+
```
530+
531+
```
532+
html:
533+
534+
535+
<h1>Some header</h1>
536+
<div class="video-embed block-embed-service-youtube"><iframe type="text/html" src="//www.youtube.com/embed/lJIrF4YjHfQ" frameborder="0" width="640" height="390" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>
537+
```
538+
541539

542540
</p>
543541
</details>

0 commit comments

Comments
 (0)