Skip to content

Commit 3dff2ae

Browse files
committed
Merge branch 'release-0.2.5'
2 parents 1bddd1b + b1216fb commit 3dff2ae

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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)
38
Fixed issue that can't be required by ES5.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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": {

tonic-example.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,43 @@ var React = require('react');
22
var ReactDOMServer = require('react-dom/server');
33
var 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+
538
class 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>
1344
ReactDOMServer.renderToString(<MyComponent />);

0 commit comments

Comments
 (0)