Skip to content

Commit 7fc844f

Browse files
committed
Make markdown replace h tags with p tags with a class as to not confuse web crawlers
1 parent 9d989b7 commit 7fc844f

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

frontend/user/src/lib/styles/markdown.css

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,33 @@
88
line-height: 1.8;
99
}
1010

11-
.markdownDescription>h1 {
11+
p.markdown-header-1 {
1212
font-size: 2.5em;
13-
line-height: 1.1;
13+
line-height: 1.1 !important;
1414
}
1515

16-
.markdownDescription>h2 {
16+
p.markdown-header-2 {
1717
font-size: 1.5em;
1818
}
1919

20-
.markdownDescription>h3 {
20+
p.markdown-header-3 {
2121
font-size: 1.17em;
2222
}
2323

24-
.markdownDescription>h4 {
24+
p.markdown-header-4 {
2525
font-size: 1em;
2626
}
2727

28-
.markdownDescription>h6 {
28+
p.markdown-header-5 {
2929
font-size: 0.67em;
3030
}
3131

32-
.markdownDescription> :is(h1, h2, h3, h4, h5, h6) {
32+
p.markdown-header {
3333
letter-spacing: 0.001rem;
3434
word-spacing: 0.1rem;
3535
width: 100%;
36+
margin-top: auto !important;
37+
line-height: 1.5;
3638
}
3739

3840
.markdownDescription>blockquote {
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import showdown from "showdown";
22

3+
// Replaces all <h#></h#> tags with <p class="markdown-header markdown-header-#"></p>
4+
// To not confuse web crawlers when finding multiple header tags
5+
const headerToParagraph: showdown.ShowdownExtension = {
6+
type: "output",
7+
regex: /^<h([1-6]) id="(.+)">(.+)<\/h[1-6]>/gm,
8+
replace: (_match: string, level: string, id: string, content: string) => {
9+
return `<p id="${id}" class="markdown-header markdown-header-${level}">${content}</p>`;
10+
}
11+
}
12+
313
const converter = new showdown.Converter({
414
openLinksInNewWindow: true,
5-
simpleLineBreaks: true
15+
simpleLineBreaks: true,
16+
extensions: [headerToParagraph]
617
});
718

819
export default function mdToHtml(md: string): string {
20+
console.log(md);
921
return converter.makeHtml(md);
1022
}

0 commit comments

Comments
 (0)