First I thought I could just use the id attributes in the
heading tags Parsoid provides[2].
Example from [1]:
<h2 id="mwCA">Template truncation</h2>
But then I thought about links to specific sections. Those
would not use the same ids Parsoid generates.[3] They would
use the anchorencoded tocline strings.[4]
Since I have not found an npm module which does
anchorencoding in JavaScript I wrote a small library function
to do the same. It uses the phpjs npm module to take into
account the PHP specific way URLencoding is done. Would you
mind checking the anchorencode.js
file and the associate test file anchorencode-test.js in my
patch[5]?
If there is a JS implementation of this I'd be happy to
hear about that, of course.
Thanks,
Bernd