@@ -143,7 +143,7 @@ The plugin system allows you to customize HTML to Markdown conversion by hooking
143143#### Plugin Hooks
144144
145145- ` beforeNodeProcess ` : Called before any node processing, can skip nodes
146- - ` onNodeEnter ` : Called when entering an element node
146+ - ` onNodeEnter ` : Called when entering an element node
147147- ` onNodeExit ` : Called when exiting an element node
148148- ` processTextNode ` : Called for each text node
149149- ` processAttributes ` : Called to process element attributes
@@ -153,23 +153,23 @@ The plugin system allows you to customize HTML to Markdown conversion by hooking
153153Use ` createPlugin() ` to create a plugin with type safety:
154154
155155``` ts
156+ import type { ElementNode , TextNode } from ' mdream'
156157import { htmlToMarkdown } from ' mdream'
157158import { createPlugin } from ' mdream/plugins'
158- import type { ElementNode , TextNode } from ' mdream'
159159
160160const myPlugin = createPlugin ({
161161 onNodeEnter(node : ElementNode ): string | undefined {
162162 if (node .name === ' h1' ) {
163163 return ' 🔥 '
164164 }
165165 },
166-
167- processTextNode(textNode : TextNode ): { content: string ; skip: boolean } | undefined {
166+
167+ processTextNode(textNode : TextNode ): { content: string , skip: boolean } | undefined {
168168 // Transform text content
169169 if (textNode .parent ?.attributes ?.id === ' highlight' ) {
170- return {
171- content: ` **${textNode .value }** ` ,
172- skip: false
170+ return {
171+ content: ` **${textNode .value }** ` ,
172+ skip: false
173173 }
174174 }
175175 }
@@ -183,19 +183,19 @@ const markdown: string = htmlToMarkdown(html, { plugins: [myPlugin] })
183183#### Example: Content Filter Plugin
184184
185185``` ts
186+ import type { ElementNode , NodeEvent } from ' mdream'
186187import { ELEMENT_NODE } from ' mdream'
187188import { createPlugin } from ' mdream/plugins'
188- import type { NodeEvent , ElementNode } from ' mdream'
189189
190190const adBlockPlugin = createPlugin ({
191191 beforeNodeProcess(event : NodeEvent ): { skip: boolean } | undefined {
192192 const { node } = event
193-
193+
194194 if (node .type === ELEMENT_NODE && node .name === ' div' ) {
195195 const element = node as ElementNode
196196 // Skip ads and promotional content
197- if (element .attributes ?.class ?.includes (' ad' ) ||
198- element .attributes ?.id ?.includes (' promo' )) {
197+ if (element .attributes ?.class ?.includes (' ad' )
198+ || element .attributes ?.id ?.includes (' promo' )) {
199199 return { skip: true }
200200 }
201201 }
@@ -208,8 +208,8 @@ const adBlockPlugin = createPlugin({
208208Extract specific elements and their content during HTML processing for data analysis or content discovery:
209209
210210``` ts
211- import { extractionPlugin , htmlToMarkdown } from ' mdream'
212211import type { ExtractedElement } from ' mdream/plugins'
212+ import { extractionPlugin , htmlToMarkdown } from ' mdream'
213213
214214const html: string = `
215215 <article>
0 commit comments