Hi,

I'm building the ToC entries from Parsoid HTML content. Another part which caused some struggle is building the correct anchors for the section headings.

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

[1] https://test.wikipedia.org/wiki/Section_edit_links_bug2
[2] view-source:https://test.wikipedia.org/api/rest_v1/page/html/Section_edit_links_bug2
[3] https://test.wikipedia.org/api/rest_v1/page/html/Section_links
[4] https://www.mediawiki.org/wiki/Manual:PAGENAMEE_encoding#Encodings_compared
[5] https://gerrit.wikimedia.org/r/#/c/246100/7