Skip to content

Commit bbe9713

Browse files
committed
Admonition handling
1 parent ebcdf96 commit bbe9713

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

lib/markdown-for-llm.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
'use strict'
22

33
const { NodeHtmlMarkdown } = require('node-html-markdown')
4-
const nhm = new NodeHtmlMarkdown()
4+
5+
let nhm
6+
const customTranslators = {
7+
DIV: ({ visitor }) => ({
8+
surroundingNewlines: 2,
9+
postprocess: ({ nodeMetadata, node }) => {
10+
// <div class="admonitionblock note">
11+
if (node.classList.contains('admonitionblock')) {
12+
13+
const type = (node
14+
.classList.values().
15+
find(v => v != 'admonitionblock')
16+
.toUpperCase())
17+
18+
const content = (
19+
nhm.translate(
20+
node.querySelector('td:nth-child(2)')
21+
.innerHTML
22+
).replace(/^/mg, '> '))
23+
24+
return `> [!${type}]\n${content}`
25+
}
26+
}
27+
})
28+
}
29+
nhm = new NodeHtmlMarkdown({}, customTranslators)
530

631
const File = require('vinyl')
732

@@ -84,13 +109,17 @@ module.exports.register = function ({ playbook, config }) {
84109
output+=`# Couchbase
85110
86111
> This is the official documentation for Couchbase, a leading NoSQL distributed database platform
87-
> designed for high performance, scalability, and flexibility. The documentation covers comprehensive
88-
> guides for developers and operations teams, including installation and configuration, development
89-
> tutorials, API references, administration, security, cloud deployment, and integration with various
90-
> programming languages and frameworks. Couchbase enables applications to handle massive data volumes
91-
> and high concurrency with its memory-first architecture and flexible JSON document model.\n\n`
112+
> designed for high performance, scalability, and flexibility.
113+
> The documentation covers comprehensive guides for developers and operations
114+
> teams, including installation and configuration, development tutorials, API
115+
> references, administration, security, cloud deployment, and integration with
116+
> various programming languages and frameworks.
117+
> Couchbase enables applications to handle massive data volumes and high
118+
> concurrency with its memory-first architecture and flexible JSON document
119+
> model.
120+
92121
93-
output+=`\n## Docs\n`
122+
## Docs\n`
94123

95124
for (const c of navObj) {
96125
const v = c.versions[0]

0 commit comments

Comments
 (0)