File tree Expand file tree Collapse file tree 2 files changed +42
-16
lines changed
src/components/md-to-html Expand file tree Collapse file tree 2 files changed +42
-16
lines changed Original file line number Diff line number Diff line change 1- PlainBelt
2- =========
1+ [ ![ Test] ( https://github.com/plainbelt/plainbelt/actions/workflows/test.yml/badge.svg )] ( https://github.com/plainbelt/plainbelt/actions/workflows/test.yml )
32
4- > A toolbelt for all your plain text
3+ # PlainBelt
54
5+ > A toolbelt for your plain text
66
77## Development setup
88
1111yarn start
1212```
1313
14- Enjoy!
14+ ## Build binary
15+
16+ ```
17+ yarn package
18+ ```
19+
20+ Checkout the ` release ` folder and enjoy!
Original file line number Diff line number Diff line change 1+ /* eslint-disable react/no-danger */
12import React , { useState } from 'react' ;
23import marked from 'marked' ;
34
45const Md2Html = ( ) => {
56 const [ md , setMd ] = useState ( '# Hello\n> This is a quote' ) ;
7+ const [ preview , setPreview ] = useState ( false ) ;
68
79 const handleChange = ( evt : { target : { value : string } } ) =>
810 setMd ( evt . target . value ) ;
911
1012 return (
11- < div className = "flex min-h-full" >
12- < textarea
13- onChange = { handleChange }
14- className = "flex-1 min-h-full bg-white p-4"
15- value = { md }
16- />
17- < div className = "mx-1" />
18- < textarea
19- className = "flex-1 min-h-full bg-blue-100 p-4"
20- value = { marked ( md ) }
21- disabled
22- />
13+ < div className = "min-h-full flex flex-col" >
14+ < div className = "flex justify-end mb-1" >
15+ < button
16+ type = "button"
17+ className = "rounded bg-gray-300 px-2 py-1 outline-none text-sm text-gray-600"
18+ onClick = { ( ) => setPreview ( ! preview ) }
19+ >
20+ { preview ? 'Raw HTML' : 'Preview' }
21+ </ button >
22+ </ div >
23+ < div className = "flex min-h-full flex-1" >
24+ < textarea
25+ onChange = { handleChange }
26+ className = "flex-1 min-h-full bg-white p-4"
27+ value = { md }
28+ />
29+ < div className = "mx-1" />
30+ { preview ? (
31+ < section
32+ className = "flex-1 min-h-full bg-blue-50 p-4 prose"
33+ dangerouslySetInnerHTML = { { __html : marked ( md ) } }
34+ />
35+ ) : (
36+ < textarea
37+ className = "flex-1 min-h-full bg-blue-100 p-4"
38+ value = { marked ( md ) }
39+ disabled
40+ />
41+ ) }
42+ </ div >
2343 </ div >
2444 ) ;
2545} ;
You can’t perform that action at this time.
0 commit comments