Skip to content

Commit 8a6941f

Browse files
save file
1 parent cadb9dc commit 8a6941f

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

utils/editors/markdown-editor/html/output-md/v2.0/output-md-v2.0.html

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{margin-right:5px}
2020

2121

22-
#output
22+
#output, web-editor
2323
{height:100%;border:2px solid lightgray;box-sizing:border-box;padding:10px}
2424

2525

@@ -61,6 +61,8 @@
6161
<div id=output class=markdown-body>
6262
</div>
6363

64+
<web-editor component mode=html style='display:none'></web-editor>
65+
6466
</div>
6567

6668
</template>
@@ -82,8 +84,8 @@
8284

8385
obj.initmod = function(params){
8486

85-
$ = mod.rd(params,'$',$);
86-
debug = mod.rd(params,'debug',debug);
87+
$ = mod.rd(params,'$',$);
88+
debug = mod.rd(params,'debug',debug);
8789

8890
}//initmod
8991

@@ -92,12 +94,18 @@
9294

9395
var md;
9496

97+
var cur = {};
98+
cur.mode = 'md';
99+
cur.txt = null;
100+
95101
var shadow;
96102
var output;
97103
var chk = {};
98104

105+
var editor;
99106

100107
var btn = {};
108+
var show = {};
101109

102110

103111
//:
@@ -106,8 +114,13 @@
106114
obj.init = async function(){
107115
debug=eval(debug);
108116
debug('init',obj.version);
109-
110-
await libs();
117+
editor = mod['web-editor'];
118+
119+
120+
await Promise.all([
121+
libs(),
122+
mod.auto(),
123+
]);
111124

112125

113126
}//init
@@ -161,6 +174,14 @@
161174

162175
btn.mode = function(chk,id){
163176
debug('btn.mode',id);
177+
switch(id){
178+
179+
case 'mode-md' : cur.mode='md'; break;
180+
case 'mode-html' : cur.mode='html'; break;
181+
182+
}//switch
183+
display();
184+
164185
}//mode
165186

166187

@@ -187,10 +208,21 @@
187208
188209
*/
189210

190-
obj.display = async function(txt){
211+
212+
obj.display = async function(txt){return display(txt)}
213+
214+
function displayt(txt){
191215
debug('display');
192216
await libs;
193217

218+
output.replaceChildren();
219+
220+
txt = txt||cur.txt;
221+
if(!txt){
222+
return;
223+
}
224+
cur.txt = txt;
225+
194226
var opts = {
195227
linkTarget : '_blank',
196228
};
@@ -201,27 +233,52 @@
201233
var md = markdownit(opts);
202234
var html = md.render(txt);
203235

204-
output.innerHTML = html;
236+
display[cur.mode](html);
205237

206238
}//show
207239

208240

209-
obj.horiz = function(){
241+
display.md = function(html){
242+
debug('display.md');
243+
output.innerHTML = html;
244+
245+
output.style.display = '';
246+
editor.__host.style.display = 'none';
247+
248+
}//md
210249

250+
251+
display.html = function(html){
252+
debug('display.html');
253+
editor.set(html);
254+
255+
output.style.display = '';
256+
editor.__host.style.display = 'none';
257+
258+
}//html
259+
260+
261+
//:
262+
263+
264+
obj.horiz = function(){
265+
debug('horiz');
211266
host.style.width = '100%';
212267
host.style.height = '50%';
213268

214269
}//horiz
215270

216271

217272
obj.vert = function(){
218-
273+
debug('vert');
219274
host.style.width = '50%';
220275
host.style.height = '100%';
221276

222277
}//vert
223278

224279

280+
281+
225282
//:
226283

227284

0 commit comments

Comments
 (0)