File tree Expand file tree Collapse file tree 3 files changed +40
-4
lines changed
Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 1+ <a name =" 0.2.5 " ></a >
2+ ## [ 0.2.5] ( https://github.com/JimLiu/bbcode-to-react/compare/0.2.4...v0.2.5 ) (2016-11-01)
3+
4+ More example code for tonic-example
5+
16<a name =" 0.2.4 " ></a >
27## [ 0.2.4] ( https://github.com/JimLiu/bbcode-to-react/compare/0.2.3...v0.2.4 ) (2016-11-01)
38Fixed issue that can't be required by ES5.
Original file line number Diff line number Diff line change 11{
22 "name" : " bbcode-to-react" ,
3- "version" : " 0.2.4 " ,
3+ "version" : " 0.2.5 " ,
44 "description" : " A utility for turning raw BBCode into React elements. " ,
55 "main" : " lib/index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -2,12 +2,43 @@ var React = require('react');
22var ReactDOMServer = require ( 'react-dom/server' ) ;
33var bbcode = require ( 'bbcode-to-react' ) ;
44
5+ /* Code for customize tag
6+ class YoutubeTag extends bbcode.Tag {
7+ toReact() {
8+ // using this.getContent(true) to get it's inner raw text.
9+ const attributes = {
10+ src: this.getContent(true),
11+ width: this.params.width || 420,
12+ height: this.params.height || 315,
13+ };
14+ return (
15+ <iframe
16+ {...attributes}
17+ frameBorder="0"
18+ allowFullScreen
19+ />
20+ );
21+ }
22+ }
23+
24+ class BoldTag extends bbcode.Tag {
25+ toReact() {
26+ // using this.getComponents() to get children components.
27+ return (
28+ <b>{this.getComponents()}</b>
29+ );
30+ }
31+ }
32+
33+ // [youtube width="400"]https://www.youtube.com/watch?v=AB6RjNeDII0[/youtube]
34+ bbcode.registerTag('youtube', YoutubeTag); // add new tag
35+ bbcode.registerTag('b', BoldTag); // replace exists tag
36+ */
37+
538class MyComponent extends React . Component {
639 render ( ) {
7- console . log ( bbcode . default ) ;
8- return < p > { bbcode . default . toReact ( '[b]strong[/b]' ) } </ p > ;
40+ return < p > { bbcode . toReact ( '[b]My Video: [/b][youtube width="400"]https://www.youtube.com/watch?v=AB6RjNeDII0[/youtube]' ) } </ p > ;
941 }
1042}
1143
12- // render: <p><strong>strong</strong></p>
1344ReactDOMServer . renderToString ( < MyComponent /> ) ;
You can’t perform that action at this time.
0 commit comments