Skip to content

Commit f025d35

Browse files
committed
fallback for admonitions
sometimes innerHTML for 2nd td is undefined, need to figure out which case this is.
1 parent f04da31 commit f025d35

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/markdown-for-llm.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let nhm
77
const customTranslators = {
88
DIV: ({ visitor }) => ({
99
surroundingNewlines: 2,
10-
postprocess: ({ nodeMetadata, node }) => {
10+
postprocess: ({ content, nodeMetadata, node }) => {
1111
// <div class="admonitionblock note">
1212
if (node.classList.contains('admonitionblock')) {
1313

@@ -16,13 +16,11 @@ const customTranslators = {
1616
find(v => v != 'admonitionblock') || 'NOTE'
1717
).toUpperCase()
1818

19-
const content = (
20-
nhm.translate(
21-
node.querySelector('td:nth-child(2)')
22-
.innerHTML
23-
).replace(/^/mg, '> '))
19+
const admonition = node.querySelector('td:nth-child(2)')?.innerHTML || `BAD ADMONITION ${content}`
20+
const body = (
21+
nhm.translate(admonition).replace(/^/mg, '> '))
2422

25-
return `> [!${type}]\n${content}`
23+
return `> [!${type}]\n${body}`
2624
}
2725
}
2826
})

0 commit comments

Comments
 (0)