Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Fix RDMD backwards compatible anchors. #669

Merged
merged 8 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/markdown/components/Heading/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const React = require('react');
const PropTypes = require('prop-types');

function generateHeadingIdDeprecated(e) {
if (typeof e === 'object') {
return generateHeadingIdDeprecated(e.props.children[0]);
}
return e.toLowerCase().replace(/[^\w]+/g, '-');
}

function Heading({ tag, ...props }) {
if (!props.children) return '';

Expand All @@ -9,6 +16,11 @@ function Heading({ tag, ...props }) {
align: props.align,
};
return React.createElement(tag, attrs, [
<div
key={`heading-anchor-${props.id}-deprecated`}
className="heading-anchor-deprecated"
id={`section-${generateHeadingIdDeprecated(props.id)}`}
/>,
<div key={`heading-anchor-${props.id}`} className="heading-anchor anchor waypoint" id={props.id} />,
<div key={`heading-text-${props.id}`} className="heading-text">
{props.children}
Expand Down
7 changes: 6 additions & 1 deletion packages/markdown/components/Heading/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
.heading-text {
flex: 1 100%;
}
.heading-anchor-deprecated {
position: absolute;
top: 0;
}
.heading-anchor {
top: -1rem !important;
}
.heading-anchor, .heading-anchor-icon {
.heading-anchor,
.heading-anchor-icon {
position: absolute !important;
display: inline !important;
order: -1;
Expand Down
3 changes: 1 addition & 2 deletions packages/markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const {

/* Custom Unified Plugins
*/
const sectionAnchorId = require('./processor/plugin/section-anchor-id');
// const sectionAnchorId = require('./processor/plugin/section-anchor-id');

// Processor Option Defaults
const options = require('./options.json');
Expand Down Expand Up @@ -148,7 +148,6 @@ export function processor(opts = {}) {
.use(!opts.correctnewlines ? remarkBreaks : () => {})
.use(gemojiParser.sanitize(sanitize))
.use(remarkSlug)
.use(sectionAnchorId)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw)
.use(rehypeSanitize, sanitize);
Expand Down