Skip to content

Commit 4e96c4e

Browse files
authored
Merge pull request #2704 from PolicyEngine/fix/remove-markdown-for-ai
Use conditional chaining to prevent MarkdownFormatter breakage
2 parents 2030b9f + 0b8c2d3 commit 4e96c4e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/layout/MarkdownFormatter.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export function MarkdownFormatter({ markdown, backgroundColor, dict, pSize }) {
319319
.props.children.find(
320320
(child) => child?.props?.node.tagName === "a",
321321
).props.node.properties.href;
322-
value = footnoteLinkBack.split("-").pop();
322+
value = footnoteLinkBack?.split("-").pop() || "";
323323
validValue = /^-?\d+$/.test(value);
324324
} catch (e) {
325325
// Do nothing
@@ -369,7 +369,7 @@ export function MarkdownFormatter({ markdown, backgroundColor, dict, pSize }) {
369369
// If href=#user-content-fn-1, id should be user-content-fnref-1 and vice versa
370370
if (href.startsWith("#user-content-fn-")) {
371371
id = href.replace("#user-content-fn-", "user-content-fnref-");
372-
footnoteNumber = parseInt(id.split("-").pop());
372+
footnoteNumber = parseInt(id?.split("-").pop() || "0");
373373
} else if (href.startsWith("#user-content-fnref-")) {
374374
id = href.replace("#user-content-fnref-", "user-content-fn-");
375375
} else {
@@ -475,7 +475,7 @@ export function MarkdownFormatter({ markdown, backgroundColor, dict, pSize }) {
475475
}
476476
},
477477
h2: ({ children: headerText }) => {
478-
if (!headerText.split) {
478+
if (!headerText?.split) {
479479
headerText = "";
480480
}
481481
// Remove slashes and commas, and replace spaces with dashes to create a

0 commit comments

Comments
 (0)