Skip to content

Commit d2b6014

Browse files
committed
fix(share): HTML tags displayed escaped in headings
1 parent 94d62f8 commit d2b6014

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

apps/server/src/services/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ export function formatSize(size: number | null | undefined) {
497497
}
498498
}
499499

500-
export function slugify(text: string) {
500+
function slugify(text: string) {
501501
return text
502502
.normalize("NFKD") // handles accents like é → e
503503
.toLowerCase()
@@ -540,6 +540,7 @@ export default {
540540
safeExtractMessageAndStackFromError,
541541
sanitizeSqlIdentifier,
542542
stripTags,
543+
slugify,
543544
timeLimit,
544545
toBase64,
545546
toMap,

apps/server/src/share/routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import log from "../services/log.js";
1414
import type SNote from "./shaca/entities/snote.js";
1515
import type SBranch from "./shaca/entities/sbranch.js";
1616
import type SAttachment from "./shaca/entities/sattachment.js";
17-
import utils, { isDev, safeExtractMessageAndStackFromError, slugify } from "../services/utils.js";
17+
import utils, { isDev, safeExtractMessageAndStackFromError } from "../services/utils.js";
1818
import options from "../services/options.js";
1919
import { t } from "i18next";
2020
import ejs from "ejs";
@@ -176,7 +176,7 @@ function register(router: Router) {
176176
showLoginInShareTheme,
177177
t,
178178
isDev,
179-
slugify
179+
utils
180180
};
181181
let useDefaultView = true;
182182

packages/share-theme/src/templates/page.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ const themeClass = currentTheme === "light" ? " theme-light" : " theme-dark";
9191
const headingRe = /(<h[1-6]>)(.+?)(<\/h[1-6]>)/g;
9292
const headingMatches = [...content.matchAll(headingRe)];
9393
content = content.replaceAll(headingRe, (...match) => {
94-
match[0] = match[0].replace(match[3], `<a id="${slugify(match[2])}" class="toc-anchor" name="${slugify(match[2])}" href="#${slugify(match[2])}">#</a>${match[3]}`);
94+
const slug = utils.slugify(utils.stripTags(match[2]));
95+
match[0] = match[0].replace(match[3], `<a id="${slug}" class="toc-anchor" name="${slug}" href="#${slug}">#</a>${match[3]}`);
9596
return match[0];
9697
});
9798
%>

packages/share-theme/src/templates/toc_item.ejs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<%
2-
const slug = slugify(entry.name);
2+
const strippedName = utils.stripTags(entry.name);
3+
const slug = utils.slugify(strippedName);
34
%>
45

5-
66
<li>
77
<a href="#<%= slug %>">
8-
<span><%= entry.name %></span>
8+
<span><%= strippedName %></span>
99
</a>
1010

1111
<% if (entry.children.length) { %>

0 commit comments

Comments
 (0)