-
Notifications
You must be signed in to change notification settings - Fork 0
/
adoc_render.js
106 lines (94 loc) · 2.58 KB
/
adoc_render.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var AsciidoctorEditor = React.createClass({
getInitialState: function() {
// return {value: 'Type some *asciidoctor* here!'};
return {value: `
= Title
:toc:
:sectnums:
:sectnumlevels: 2
== Python
pls, **Hi**
[source, python]
----
import os
print("hello world")
----
== Gradle
[source, gradle]
----
task wrapper(type: Wrapper) {
group "wrapper"
gradleVersion = '3.0'
distributionUrl = distributionUrl.replace("bin", "all")
}
----
`};
},
handleChange: function() {
console.log("handle change")
this.setState({value: this.refs.textarea.value});
},
componentDidMount: function(){
console.log("componentDidMount");
this.highlightCode();
},
componentDidUpdate: function () {
console.log("componentDidUpdate");
this.highlightCode();
},
highlightCode: function () {
var domNode = ReactDOM.findDOMNode(this);
var nodes = domNode.querySelectorAll('pre code');
if (nodes.length > 0) {
for (var i = 0; i < nodes.length; i = i + 1) {
hljs.highlightBlock(nodes[i]);
}
}
},
rawMarkup: function() {
var attrs = Opal.hash({'linkcss': '', 'copycss!': '', 'showtitle': true});
var options = Opal.hash({'doctype': 'article', 'safe': 'safe', 'header_footer': false, 'attributes': attrs,});
var doc = Opal.Asciidoctor.$load(this.state.value, options);
doc.$set_attribute('source-highlighter', 'highlight.js');
return { __html: doc.$convert() };
},
render: function() {
var containerStyle = {
display: 'flex',
flexFlow : 'row',
justifyContent : 'space-around',
} ;
var flexItemStyle = {
display: 'flex',
flexFlow : 'column',
width : '100%',
};
var inputStyle = {
flex: 1,
width: '98%',
fontSize: 14,
};
return (
<div className="container" classID="AsciidoctorEditor" style={containerStyle}>
<div className="flex-item" style={flexItemStyle}>
<a href="http://asciidoctor.org/docs/user-manual/" target="_blank">Asciidoctor User Manual</a>
<h3>Input</h3>
<textarea
className="input"
style={inputStyle}
onChange={this.handleChange}
ref="textarea"
defaultValue={this.state.value}/>
</div>
<div className="flex-item" style={flexItemStyle}>
<h3>Output</h3>
<div
ref="content"
classID="content" dangerouslySetInnerHTML={this.rawMarkup()}>
</div>
</div>
</div>
);
},
});
ReactDOM.render(<AsciidoctorEditor />, document.getElementById('container'));