Skip to content

Commit

Permalink
md: add render2 plugin func
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed Nov 29, 2020
1 parent 2f6c4e0 commit 3756784
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
18 changes: 17 additions & 1 deletion copyparty/web/md.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}


Expand Down Expand Up @@ -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);
}
Expand All @@ -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]);
}
}


Expand Down
14 changes: 14 additions & 0 deletions srv/extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -36,13 +38,22 @@ 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 |
| ------------ | -------- | ------ |
| 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


Expand Down Expand Up @@ -123,5 +134,8 @@ render(dom) {
}
}
}
},
render2(dom) {
window.makeSortable(dom.getElementsByTagName('table')[0]);
}
```

0 comments on commit 3756784

Please sign in to comment.