Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Here's a blog post about extending XhtmlString and parsing/updating the output content -- different goals, but could be one approach for you:
Might be easier to do client side?
$( document ).ready(function() {
// Get the main body and look for h2
var countItems = 0;
$('#mainBody').find('h2').each(function () {
// don't show h2 that editors have said to hide
if(!$(this).hasClass('hideFromAuto')){
// add a uniquie id for anchor
$(this).attr('id', 'autoAnchor' + countItems);
// add the on this page link
$('#anchorItems').append('<li><a href="#autoAnchor' + countItems + '">' + $(this).text() + '</a></li>');
countItems++;
}
});
if (countItems > 0) {
// if we found items show the on this page section
$("#anchor-links").removeClass('is-hidden');
}
});
Normally, if you want to render the contents of a XhtmlString then we can just write the code below. Hovever, I need to iterate through the contents of a XhtmlString and add an ID to all <h2 tags>