mirror of
https://github.com/pure-css/pure.git
synced 2024-12-10 23:44:26 +00:00
19 lines
569 B
JavaScript
19 lines
569 B
JavaScript
import React from 'react';
|
|
|
|
function SectionHeader({ heading, TagName = 'h2' }) {
|
|
// Remove HTML entities, and all chars except whitespace, word chars, and from the `heading`.
|
|
const id = heading.toLowerCase()
|
|
.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;
|