File tree Expand file tree Collapse file tree 2 files changed +31
-50
lines changed
Expand file tree Collapse file tree 2 files changed +31
-50
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Generate a html file in the gernated folder from the passed markdown file
2+ import markdownit from 'markdown-it' ;
3+ import markdownItContainer from 'markdown-it-container' ;
4+
5+ const md = markdownit ( {
6+ highlight : function ( str : string ) {
7+ return '<Codeblock code="' + md . utils . escapeHtml ( str ) . trim ( ) + '" />' ;
8+ }
9+ } ) ;
10+
11+ md . use ( markdownItContainer , 'exercise' , {
12+ render : function ( tokens : any , idx : any ) {
13+
14+ if ( tokens [ idx ] . nesting === 1 ) {
15+ // opening tag
16+ return '<exercise>\n' ;
17+
18+ } else {
19+ // closing tag
20+ return '</exercise>\n' ;
21+ }
22+ }
23+ } ) ;
24+
25+ export function markdownToHtml ( markdown : string ) {
26+ try {
27+ return md . render ( markdown ) ;
28+ } catch ( err ) {
29+ return ( 'Error reading file:' + err ) ;
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments