pure/site/components/SectionHeader.js

19 lines
552 B
JavaScript
Raw Normal View History

import React from 'react';
2020-05-16 18:09:14 +00:00
function SectionHeader({ heading, TagName = 'h2' }) {
// Remove HTML entities, and all chars except whitespace, word chars, and from the `heading`.
const id = heading.toLowerCase()
2020-05-16 18:09:14 +00:00
.replace(/&[^\s;]+;?/g, '')
.replace(/[^\s\w-]+/g, '')
.replace(/\s+/g, '-');
return (
<TagName id={id} className="content-subhead">
{heading}
<a href={`#${id}`} className="content-link" title="Heading anchor"></a>
</TagName>
);
}
export default SectionHeader;