Skip to content

Instantly share code, notes, and snippets.

@tilomitra
Last active December 21, 2015 11:19
Show Gist options
  • Save tilomitra/6298456 to your computer and use it in GitHub Desktop.
Save tilomitra/6298456 to your computer and use it in GitHub Desktop.
exports.sectionHeading = function (title) {
return Handlebars.helpers.anchor.call(this, "h2", "content-subhead");
};
exports.anchor = function (title, elemType, classes) {
var elem,
anchor = title.toLowerCase()
.replace(/&[^\s;]+;?/g, '') // remove HTML entities
.replace(/[^\s\w\-]+/g, '') // remove all chars except whitespace, word chars, and -
.replace(/\s+/g, '-');
typeof elemType === 'string' || (elemType = 'h2');
typeof classes === 'string' || (classes = 'content-subhead');
elem = '<' + elemType + ' id="' + anchor + '" class="' + classes + '">' + title + '</' + elemType + '>';
return new Handlebars.SafeString(elem);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment