mdream 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/plugins.d.mts +2 -2
- package/dist/plugins.d.ts +2 -2
- package/dist/plugins.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -206,7 +206,7 @@ const adBlockPlugin = createPlugin({
|
|
|
206
206
|
Extract specific elements and their content during HTML processing for data analysis or content discovery:
|
|
207
207
|
|
|
208
208
|
```ts
|
|
209
|
-
import type { ExtractedElement } from 'mdream/plugins'
|
|
209
|
+
import type { ExtractedElement, MdreamRuntimeState } from 'mdream/plugins'
|
|
210
210
|
import { extractionPlugin, htmlToMarkdown } from 'mdream'
|
|
211
211
|
|
|
212
212
|
const html: string = `
|
|
@@ -219,12 +219,14 @@ const html: string = `
|
|
|
219
219
|
|
|
220
220
|
// Extract elements using CSS selectors
|
|
221
221
|
const plugin = extractionPlugin({
|
|
222
|
-
'h2': (element: ExtractedElement): void => {
|
|
222
|
+
'h2': (element: ExtractedElement, state: MdreamRuntimeState): void => {
|
|
223
223
|
console.log('Heading:', element.textContent) // "Getting Started"
|
|
224
|
+
console.log('Depth:', state.depth) // Current nesting depth
|
|
224
225
|
},
|
|
225
|
-
'img[alt]': (element: ExtractedElement): void => {
|
|
226
|
+
'img[alt]': (element: ExtractedElement, state: MdreamRuntimeState): void => {
|
|
226
227
|
console.log('Image:', element.attributes.src, element.attributes.alt)
|
|
227
228
|
// "Image: /hero.jpg Hero image"
|
|
229
|
+
console.log('Context:', state.options) // Access to conversion options
|
|
228
230
|
}
|
|
229
231
|
})
|
|
230
232
|
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as Plugin, b as ElementNode } from './shared/mdream.-SGj02be.mjs';
|
|
1
|
+
import { P as Plugin, b as ElementNode, d as MdreamRuntimeState } from './shared/mdream.-SGj02be.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Create a plugin that implements the Plugin interface with improved type inference
|
|
@@ -10,7 +10,7 @@ declare function createPlugin<T extends Partial<Plugin>>(plugin: T): Plugin;
|
|
|
10
10
|
interface ExtractedElement extends ElementNode {
|
|
11
11
|
textContent: string;
|
|
12
12
|
}
|
|
13
|
-
declare function extractionPlugin(selectors: Record<string, (element: ExtractedElement) => void>): Plugin;
|
|
13
|
+
declare function extractionPlugin(selectors: Record<string, (element: ExtractedElement, state: MdreamRuntimeState) => void>): Plugin;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Plugin that filters nodes based on CSS selectors.
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as Plugin, b as ElementNode } from './shared/mdream.-SGj02be.js';
|
|
1
|
+
import { P as Plugin, b as ElementNode, d as MdreamRuntimeState } from './shared/mdream.-SGj02be.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Create a plugin that implements the Plugin interface with improved type inference
|
|
@@ -10,7 +10,7 @@ declare function createPlugin<T extends Partial<Plugin>>(plugin: T): Plugin;
|
|
|
10
10
|
interface ExtractedElement extends ElementNode {
|
|
11
11
|
textContent: string;
|
|
12
12
|
}
|
|
13
|
-
declare function extractionPlugin(selectors: Record<string, (element: ExtractedElement) => void>): Plugin;
|
|
13
|
+
declare function extractionPlugin(selectors: Record<string, (element: ExtractedElement, state: MdreamRuntimeState) => void>): Plugin;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Plugin that filters nodes based on CSS selectors.
|
package/dist/plugins.mjs
CHANGED
|
@@ -29,14 +29,14 @@ function extractionPlugin(selectors) {
|
|
|
29
29
|
currentParent = currentParent.parent;
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
-
onNodeExit(element) {
|
|
32
|
+
onNodeExit(element, state) {
|
|
33
33
|
const tracked = trackedElements.get(element);
|
|
34
34
|
if (tracked) {
|
|
35
35
|
const extractedElement = {
|
|
36
36
|
...element,
|
|
37
37
|
textContent: tracked.textContent.trim()
|
|
38
38
|
};
|
|
39
|
-
tracked.callback(extractedElement);
|
|
39
|
+
tracked.callback(extractedElement, state);
|
|
40
40
|
trackedElements.delete(element);
|
|
41
41
|
}
|
|
42
42
|
}
|