-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathform.jsx
More file actions
158 lines (148 loc) · 4.77 KB
/
form.jsx
File metadata and controls
158 lines (148 loc) · 4.77 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import * as React from 'react';
import { MathpixMarkdownModel as MM } from 'mathpix-markdown-it';
class ConvertForm extends React.Component {
constructor(props) {
super(props);
this.state = {
value: '\\[\n' +
'y = \\frac { \\sum _ { i } w _ { i } y _ { i } } { \\sum _ { i } w _ { i } } , i = 1,2 \\ldots k\n' +
'\\]' +
'\n' +
'\n' +
'\\begin{center}\n' +
' \\begin{tabular}{ l | c | r }\n' +
' \\hline\n' +
' 1 & 2 & 3 \\\\ \\hline\n' +
' 4 & 5 & 6 \\\\ \\hline\n' +
' 7 & 8 & 9 \\\\\n' +
' \\hline\n' +
' \\end{tabular}\n' +
'\\end{center}',
result: '',
include_mathml: true,
include_asciimath: true,
include_typst: true,
include_latex: true,
include_svg: true,
include_tsv: true,
include_table_html: true,
formats: ''
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleInputChange = this.handleInputChange.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleInputChange(event) {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({
[name]: value
});
}
handleSubmit(event) {
event.preventDefault();
const options = {
outMath: {
include_mathml: this.state.include_mathml,
include_asciimath: this.state.include_asciimath,
include_typst: this.state.include_typst,
include_latex: this.state.include_latex,
include_svg: this.state.include_svg,
include_tsv: this.state.include_tsv,
include_table_html: this.state.include_table_html,
}
};
const html = MM.markdownToHTML(this.state.value, options);
const formats = MM.parseMarkdownByHTML(html);
this.setState({result: html})
this.setState({formats: formats})
}
render() {
return (
<div>
<form onSubmit={this.handleSubmit}>
<h1>Input Text with Latex:</h1>
<div className='inputs'>
<textarea value={this.state.value} onChange={this.handleChange} />
<div className="includes">
<h4>Includes formats:</h4>
<label>
<input
name="include_mathml"
type="checkbox"
checked={this.state.include_mathml}
onChange={this.handleInputChange} />
mathml
</label>
<label>
<input
name="include_asciimath"
type="checkbox"
checked={this.state.include_asciimath}
onChange={this.handleInputChange} />
asciimath
</label>
<label>
<input
name="include_typst"
type="checkbox"
checked={this.state.include_typst}
onChange={this.handleInputChange} />
typst
</label>
<label>
<input
name="include_latex"
type="checkbox"
checked={this.state.include_latex}
onChange={this.handleInputChange} />
latex
</label>
<label>
<input
name="include_svg"
type="checkbox"
checked={this.state.include_svg}
onChange={this.handleInputChange} />
svg
</label>
<label>
<input
name="include_tsv"
type="checkbox"
checked={this.state.include_tsv}
onChange={this.handleInputChange} />
tsv
</label>
<label>
<input
name="include_table_html"
type="checkbox"
checked={this.state.include_table_html}
onChange={this.handleInputChange} />
table html
</label>
</div>
</div>
<input type="submit" value="Convert" />
</form>
<div id='preview-content' dangerouslySetInnerHTML={{__html: this.state.result}}/>
<div className="formats">
{this.state.formats && this.state.formats.length > 0 &&
this.state.formats.map((item, index) => {
return <div className="item" key={index}>
<div>{item.type}</div>
<code>{item.value}</code>
</div>
})
}
</div>
</div>
);
}
}
export default ConvertForm;