doc.silverstripe.org/src/utils/cleanHeaders.ts

12 lines
348 B
TypeScript
Raw Permalink Normal View History

2019-11-19 04:29:29 +01:00
/**
* Removes the <em> tags caused by underscores in the {#id_with_underscores}
* @param html
*/
2019-11-14 03:05:03 +01:00
const cleanHeaders = (html: string): string => {
return html.replace(
/<h([0-9])>(.*?)(\{#.*?<\/?em>.*?})/g,
(_, level, title, tag) => `<h${level}>${title} ${tag.replace(/<\/?em>/g, '_')}`
);
};
export default cleanHeaders;