diff --git a/copyparty/web/md.js b/copyparty/web/md.js index 68b0a6a5..d81c8aef 100644 --- a/copyparty/web/md.js +++ b/copyparty/web/md.js @@ -184,11 +184,19 @@ function md_plug_err(ex, js) { errbox.setAttribute('id', 'md_errbox'); errbox.style.cssText = 'position:absolute;top:0;left:0;padding:1em .5em;background:#2b2b2b;color:#fc5' errbox.textContent = msg; + errbox.onclick = function () { + alert('' + ex.stack); + }; if (o) { errbox.appendChild(o); errbox.style.padding = '.25em .5em'; } dom_nav.appendChild(errbox); + + try { + console.trace(); + } + catch (ex2) { } } @@ -338,7 +346,7 @@ function convert_markdown(md_text, dest_dom) { } ext = md_plug['post']; - if (ext) + if (ext && ext[0].render) try { ext[0].render(md_dom); } @@ -347,6 +355,14 @@ function convert_markdown(md_text, dest_dom) { } 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]); + } } diff --git a/srv/extend.md b/srv/extend.md index fd25a8e4..ab8c2f6f 100644 --- a/srv/extend.md +++ b/srv/extend.md @@ -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 +in addition to the markdown extension functions, `ctor` will be called on document init + ### these/ and this one becomes ./except/these/ @@ -36,6 +38,13 @@ whic hshoud be ./except/also-this.md # ok 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` | ex:foo | bar | ex:baz | @@ -43,6 +52,8 @@ the values in the `ex:` columns are linkified to `example.com/$value` | asdf | nice | fgsfds | | 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 @@ -123,5 +134,8 @@ render(dom) { } } } +}, +render2(dom) { + window.makeSortable(dom.getElementsByTagName('table')[0]); } ```