md: add render2 plugin func

This commit is contained in:
ed 2020-11-29 19:34:08 +01:00
parent 2f6c4e0e34
commit 37567844af
2 changed files with 31 additions and 1 deletions

View file

@ -184,11 +184,19 @@ function md_plug_err(ex, js) {
errbox.setAttribute('id', 'md_errbox'); errbox.setAttribute('id', 'md_errbox');
errbox.style.cssText = 'position:absolute;top:0;left:0;padding:1em .5em;background:#2b2b2b;color:#fc5' errbox.style.cssText = 'position:absolute;top:0;left:0;padding:1em .5em;background:#2b2b2b;color:#fc5'
errbox.textContent = msg; errbox.textContent = msg;
errbox.onclick = function () {
alert('' + ex.stack);
};
if (o) { if (o) {
errbox.appendChild(o); errbox.appendChild(o);
errbox.style.padding = '.25em .5em'; errbox.style.padding = '.25em .5em';
} }
dom_nav.appendChild(errbox); dom_nav.appendChild(errbox);
try {
console.trace();
}
catch (ex2) { }
} }
@ -338,7 +346,7 @@ function convert_markdown(md_text, dest_dom) {
} }
ext = md_plug['post']; ext = md_plug['post'];
if (ext) if (ext && ext[0].render)
try { try {
ext[0].render(md_dom); ext[0].render(md_dom);
} }
@ -347,6 +355,14 @@ function convert_markdown(md_text, dest_dom) {
} }
copydom(md_dom, dest_dom, 0); copydom(md_dom, dest_dom, 0);
if (ext && ext[0].render2)
try {
ext[0].render2(dest_dom);
}
catch (ex) {
md_plug_err(ex, ext[1]);
}
} }

View file

@ -18,6 +18,8 @@ this one becomes a hyperlink to ./except/ thanks to
it is a passthrough to the markdown extension api, see https://marked.js.org/using_pro it is a passthrough to the markdown extension api, see https://marked.js.org/using_pro
in addition to the markdown extension functions, `ctor` will be called on document init
### these/ ### these/
and this one becomes ./except/these/ and this one becomes ./except/these/
@ -36,6 +38,13 @@ whic hshoud be ./except/also-this.md
# ok # ok
now for another extension type, `copyparty_post` which is called to manipulate the generated dom instead now for another extension type, `copyparty_post` which is called to manipulate the generated dom instead
`copyparty_post` can have the following functions, all optional
* `ctor` is called on document init
* `render` is called when the dom is done but still in-memory
* `render2` is called with the live browser dom as-displayed
## post example
the values in the `ex:` columns are linkified to `example.com/$value` the values in the `ex:` columns are linkified to `example.com/$value`
| ex:foo | bar | ex:baz | | ex:foo | bar | ex:baz |
@ -43,6 +52,8 @@ the values in the `ex:` columns are linkified to `example.com/$value`
| asdf | nice | fgsfds | | asdf | nice | fgsfds |
| more one row | hi hello | aaa | | more one row | hi hello | aaa |
and the table can be sorted by clicking the headers
the difference is that with `copyparty_pre` you'll probably break various copyparty features but if you use `copyparty_post` then future copyparty versions will probably break you the difference is that with `copyparty_pre` you'll probably break various copyparty features but if you use `copyparty_post` then future copyparty versions will probably break you
@ -123,5 +134,8 @@ render(dom) {
} }
} }
} }
},
render2(dom) {
window.makeSortable(dom.getElementsByTagName('table')[0]);
} }
``` ```