mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-10-22 15:05:50 +00:00
Fix html in header IDs
This commit is contained in:
parent
64d05765fc
commit
9485472792
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"workbench.colorCustomizations": {
|
"workbench.colorCustomizations": {
|
||||||
"activityBar.background": "#88d7ea",
|
"activityBar.background": "#88d7ea",
|
||||||
|
"activityBar.activeBorder": "#de41bf",
|
||||||
"activityBar.foreground": "#15202b",
|
"activityBar.foreground": "#15202b",
|
||||||
"activityBar.inactiveForeground": "#15202b99",
|
"activityBar.inactiveForeground": "#15202b99",
|
||||||
"activityBarBadge.background": "#de41bf",
|
"activityBarBadge.background": "#de41bf",
|
||||||
|
8
src/utils/cleanHeaders.ts
Normal file
8
src/utils/cleanHeaders.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
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;
|
@ -118,7 +118,7 @@ const getHomePage = (): SilverstripeDocument | null => {
|
|||||||
return __home;
|
return __home;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCurrentVersion = (): string | null => __currentVersion;
|
const getCurrentVersion = (): string => __currentVersion || '4';
|
||||||
|
|
||||||
const setCurrentNode = (slug: string): void => {
|
const setCurrentNode = (slug: string): void => {
|
||||||
const currentNode = getNodes().find(n => n.slug === slug) || null;
|
const currentNode = getNodes().find(n => n.slug === slug) || null;
|
||||||
|
@ -8,6 +8,8 @@ import cleanCalloutTags from './cleanCalloutTags';
|
|||||||
import { ReactElement } from 'react';
|
import { ReactElement } from 'react';
|
||||||
import rewriteTable from './rewriteTable';
|
import rewriteTable from './rewriteTable';
|
||||||
import rewriteHeader from './rewriteHeader';
|
import rewriteHeader from './rewriteHeader';
|
||||||
|
import cleanHeaders from './cleanHeaders';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace all the [CHILDREN] with proper React components.
|
* Replace all the [CHILDREN] with proper React components.
|
||||||
* @param html
|
* @param html
|
||||||
@ -19,6 +21,7 @@ const parseHTML = (html: string): ReactElement | ReactElement[] | string => {
|
|||||||
cleanHTML = cleanCalloutTags(cleanHTML);
|
cleanHTML = cleanCalloutTags(cleanHTML);
|
||||||
cleanHTML = cleanWhitespace(cleanHTML);
|
cleanHTML = cleanWhitespace(cleanHTML);
|
||||||
cleanHTML = cleanApiTags(cleanHTML);
|
cleanHTML = cleanApiTags(cleanHTML);
|
||||||
|
cleanHTML = cleanHeaders(cleanHTML);
|
||||||
|
|
||||||
const parseOptions = {
|
const parseOptions = {
|
||||||
replace(domNode: DomElement): ReactElement | object | undefined | false {
|
replace(domNode: DomElement): ReactElement | object | undefined | false {
|
||||||
|
@ -2,7 +2,7 @@ import { createElement, ReactElement } from 'react';
|
|||||||
import { domToReact, DomElement, HTMLReactParserOptions } from 'html-react-parser';
|
import { domToReact, DomElement, HTMLReactParserOptions } from 'html-react-parser';
|
||||||
import { Link } from 'gatsby';
|
import { Link } from 'gatsby';
|
||||||
import rewriteAPILink from './rewriteAPILink';
|
import rewriteAPILink from './rewriteAPILink';
|
||||||
import { getCurrentNode } from '../utils/nodes';
|
import { getCurrentNode, getCurrentVersion } from '../utils/nodes';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
interface LinkAttributes {
|
interface LinkAttributes {
|
||||||
@ -21,6 +21,7 @@ const rewriteLink = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentNode = getCurrentNode();
|
const currentNode = getCurrentNode();
|
||||||
|
const version = getCurrentVersion();
|
||||||
|
|
||||||
// api links
|
// api links
|
||||||
if (href.match(/^api\:/)) {
|
if (href.match(/^api\:/)) {
|
||||||
@ -42,10 +43,13 @@ const rewriteLink = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Relative to root
|
// Relative to root
|
||||||
if (href.substring(0, 1) === '/') {
|
if (href.startsWith('/')) {
|
||||||
return createElement(
|
return createElement(
|
||||||
Link,
|
Link,
|
||||||
{ to: href, className: 'gatsby-link' },
|
{
|
||||||
|
to: path.join('en', version, href),
|
||||||
|
className: 'gatsby-link'
|
||||||
|
},
|
||||||
domToReact(children, parseOptions)
|
domToReact(children, parseOptions)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user