defuddle-cli 0.2.0 → 0.3.0

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.
Files changed (36) hide show
  1. package/dist/dom/document.d.ts +3 -0
  2. package/dist/dom/document.js +49 -0
  3. package/dist/dom/elements.d.ts +2 -0
  4. package/dist/dom/elements.js +478 -0
  5. package/dist/dom/interfaces/elements/base.d.ts +14 -0
  6. package/dist/dom/interfaces/elements/base.js +46 -0
  7. package/dist/dom/interfaces/elements/form.d.ts +2 -0
  8. package/dist/dom/interfaces/elements/form.js +123 -0
  9. package/dist/dom/interfaces/elements/index.d.ts +2 -0
  10. package/dist/dom/interfaces/elements/index.js +22 -0
  11. package/dist/dom/interfaces/elements/interactive.d.ts +2 -0
  12. package/dist/dom/interfaces/elements/interactive.js +83 -0
  13. package/dist/dom/interfaces/elements/media.d.ts +2 -0
  14. package/dist/dom/interfaces/elements/media.js +43 -0
  15. package/dist/dom/interfaces/elements/table.d.ts +2 -0
  16. package/dist/dom/interfaces/elements/table.js +155 -0
  17. package/dist/dom/interfaces/elements/text.d.ts +2 -0
  18. package/dist/dom/interfaces/elements/text.js +57 -0
  19. package/dist/dom/interfaces/elements.d.ts +2 -0
  20. package/dist/dom/interfaces/elements.js +478 -0
  21. package/dist/dom/interfaces/range.d.ts +1 -1
  22. package/dist/dom/range.d.ts +2 -0
  23. package/dist/dom/range.js +87 -0
  24. package/dist/dom/setup/document.d.ts +3 -0
  25. package/dist/dom/setup/document.js +49 -0
  26. package/dist/dom/setup.d.ts +12 -9
  27. package/dist/dom/setup.js +148 -533
  28. package/dist/dom/types/setup.d.ts +10 -0
  29. package/dist/dom/types/setup.js +1 -0
  30. package/dist/index.js +9 -684
  31. package/package.json +3 -5
  32. package/src/index.ts +9 -772
  33. package/src/dom/interfaces/document.ts +0 -53
  34. package/src/dom/interfaces/range.ts +0 -120
  35. package/src/dom/interfaces/setup.ts +0 -196
  36. package/src/markdown.ts +0 -592
package/dist/index.js CHANGED
@@ -1,602 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
- import { JSDOM, VirtualConsole } from 'jsdom';
4
- import Defuddle from 'defuddle';
3
+ import { JSDOM } from 'jsdom';
4
+ import { Defuddle } from 'defuddle/node';
5
5
  import chalk from 'chalk';
6
- import { readFile, writeFile } from 'fs/promises';
6
+ import { writeFile } from 'fs/promises';
7
7
  import { fileURLToPath } from 'url';
8
8
  import { dirname, resolve } from 'path';
9
- import { createMarkdownContent } from './markdown.js';
10
- import { setupDOMInterfaces } from './dom/interfaces/setup.js';
11
- import { setupRange } from './dom/interfaces/range.js';
12
- import { setupDocumentMethods, setupWindowMethods } from './dom/interfaces/document.js';
13
9
  const __filename = fileURLToPath(import.meta.url);
14
10
  const __dirname = dirname(__filename);
15
- // Define CSS interfaces globally first
16
- globalThis.CSSRule = class {
17
- constructor(type) {
18
- this.type = 1;
19
- if (type !== undefined) {
20
- Object.defineProperty(this, 'type', { value: type });
21
- }
22
- this.cssText = '';
23
- this.parentRule = null;
24
- this.parentStyleSheet = null;
25
- }
26
- };
27
- // Static properties
28
- Object.defineProperties(globalThis.CSSRule, {
29
- STYLE_RULE: { value: 1, writable: false },
30
- CHARSET_RULE: { value: 2, writable: false },
31
- IMPORT_RULE: { value: 3, writable: false },
32
- MEDIA_RULE: { value: 4, writable: false },
33
- FONT_FACE_RULE: { value: 5, writable: false },
34
- PAGE_RULE: { value: 6, writable: false },
35
- KEYFRAMES_RULE: { value: 7, writable: false },
36
- KEYFRAME_RULE: { value: 8, writable: false },
37
- NAMESPACE_RULE: { value: 10, writable: false },
38
- COUNTER_STYLE_RULE: { value: 11, writable: false },
39
- SUPPORTS_RULE: { value: 12, writable: false },
40
- DOCUMENT_RULE: { value: 13, writable: false },
41
- FONT_FEATURE_VALUES_RULE: { value: 14, writable: false },
42
- VIEWPORT_RULE: { value: 15, writable: false },
43
- REGION_STYLE_RULE: { value: 16, writable: false }
44
- });
45
- globalThis.CSSMediaRule = class extends globalThis.CSSRule {
46
- constructor() {
47
- super();
48
- this.conditionText = '';
49
- this.deleteRule = () => { };
50
- this.insertRule = () => 0;
51
- Object.defineProperty(this, 'type', { value: 4 }); // CSSRule.MEDIA_RULE
52
- this.media = {
53
- length: 0,
54
- mediaText: '',
55
- item: () => null,
56
- appendMedium: () => { },
57
- deleteMedium: () => { },
58
- toString: () => '',
59
- [Symbol.iterator]: function* () { yield ''; return undefined; }
60
- };
61
- this.cssRules = {
62
- length: 0,
63
- item: () => null,
64
- [Symbol.iterator]: function* () {
65
- yield new globalThis.CSSRule();
66
- return undefined;
67
- }
68
- };
69
- }
70
- };
71
- globalThis.CSSStyleSheet = class {
72
- constructor() {
73
- this.type = 'text/css';
74
- this.href = null;
75
- this.ownerNode = null;
76
- this.parentStyleSheet = null;
77
- this.title = null;
78
- this.disabled = false;
79
- this.ownerRule = null;
80
- this.addRule = () => 0;
81
- this.removeRule = () => { };
82
- this.replace = async () => this;
83
- this.replaceSync = () => { };
84
- this.media = {
85
- length: 0,
86
- mediaText: '',
87
- item: () => null,
88
- appendMedium: () => { },
89
- deleteMedium: () => { },
90
- toString: () => '',
91
- [Symbol.iterator]: function* () { yield ''; return undefined; }
92
- };
93
- this.cssRules = {
94
- length: 0,
95
- item: () => null,
96
- [Symbol.iterator]: function* () {
97
- yield new globalThis.CSSRule();
98
- return undefined;
99
- }
100
- };
101
- this.rules = this.cssRules;
102
- }
103
- insertRule(rule, index) {
104
- return 0;
105
- }
106
- deleteRule(index) { }
107
- };
108
- // Define SVGElement globally
109
- globalThis.SVGElement = class {
110
- constructor() {
111
- this.id = '';
112
- this.className = '';
113
- this.style = {
114
- cssText: '',
115
- length: 0,
116
- parentRule: null,
117
- getPropertyPriority: () => '',
118
- getPropertyValue: () => '',
119
- item: () => '',
120
- removeProperty: () => '',
121
- setProperty: () => '',
122
- [Symbol.iterator]: function* () { yield ''; return undefined; }
123
- };
124
- this.ownerSVGElement = null;
125
- this.viewportElement = null;
126
- this.tagName = '';
127
- this.namespaceURI = null;
128
- this.prefix = null;
129
- this.localName = '';
130
- this.baseURI = '';
131
- this.textContent = '';
132
- this.innerHTML = '';
133
- this.outerHTML = '';
134
- this.hidden = false;
135
- this.slot = '';
136
- this.attributes = {
137
- length: 0,
138
- getNamedItem: () => null,
139
- getNamedItemNS: () => null,
140
- item: () => null,
141
- removeNamedItem: () => null,
142
- removeNamedItemNS: () => null,
143
- setNamedItem: () => null,
144
- setNamedItemNS: () => null,
145
- [Symbol.iterator]: function* () { yield null; return undefined; }
146
- };
147
- this.childNodes = {
148
- length: 0,
149
- item: () => null,
150
- forEach: () => { },
151
- entries: function* () { yield [0, null]; return undefined; },
152
- keys: function* () { yield 0; return undefined; },
153
- values: function* () { yield null; return undefined; },
154
- [Symbol.iterator]: function* () { yield null; return undefined; }
155
- };
156
- this.firstChild = null;
157
- this.lastChild = null;
158
- this.nextSibling = null;
159
- this.previousSibling = null;
160
- this.parentNode = null;
161
- this.parentElement = null;
162
- this.childElementCount = 0;
163
- this.firstElementChild = null;
164
- this.lastElementChild = null;
165
- this.nextElementSibling = null;
166
- this.previousElementSibling = null;
167
- this.children = {
168
- length: 0,
169
- item: () => null,
170
- namedItem: () => null,
171
- [Symbol.iterator]: function* () { yield null; return undefined; }
172
- };
173
- // Initialize any required properties
174
- }
175
- getAttribute(name) {
176
- return null;
177
- }
178
- getAttributeNS(namespaceURI, localName) {
179
- return null;
180
- }
181
- setAttribute(name, value) { }
182
- setAttributeNS(namespaceURI, qualifiedName, value) { }
183
- removeAttributeNS(namespaceURI, localName) { }
184
- hasAttribute(name) {
185
- return false;
186
- }
187
- hasAttributeNS(namespaceURI, localName) {
188
- return false;
189
- }
190
- getBoundingClientRect() {
191
- return {
192
- top: 0,
193
- left: 0,
194
- bottom: 0,
195
- right: 0,
196
- width: 0,
197
- height: 0,
198
- x: 0,
199
- y: 0,
200
- toJSON: function () { return this; }
201
- };
202
- }
203
- getClientRects() {
204
- return {
205
- length: 0,
206
- item: function () { return null; },
207
- [Symbol.iterator]: function* () { }
208
- };
209
- }
210
- getElementsByClassName(classNames) {
211
- return {
212
- length: 0,
213
- item: () => null,
214
- namedItem: () => null,
215
- [Symbol.iterator]: function* () { yield null; return undefined; }
216
- };
217
- }
218
- getElementsByTagName(qualifiedName) {
219
- return {
220
- length: 0,
221
- item: () => null,
222
- namedItem: () => null,
223
- [Symbol.iterator]: function* () { yield null; return undefined; }
224
- };
225
- }
226
- getElementsByTagNameNS(namespaceURI, localName) {
227
- return {
228
- length: 0,
229
- item: () => null,
230
- namedItem: () => null,
231
- [Symbol.iterator]: function* () { yield null; return undefined; }
232
- };
233
- }
234
- querySelector(selectors) {
235
- return null;
236
- }
237
- querySelectorAll(selectors) {
238
- return {
239
- length: 0,
240
- item: () => null,
241
- forEach: () => { },
242
- entries: function* () { yield [0, null]; return undefined; },
243
- keys: function* () { yield 0; return undefined; },
244
- values: function* () { yield null; return undefined; },
245
- [Symbol.iterator]: function* () { yield null; return undefined; }
246
- };
247
- }
248
- matches(selectors) {
249
- return false;
250
- }
251
- closest(selectors) {
252
- return null;
253
- }
254
- contains(other) {
255
- return false;
256
- }
257
- append(...nodes) { }
258
- prepend(...nodes) { }
259
- after(...nodes) { }
260
- before(...nodes) { }
261
- replaceWith(...nodes) { }
262
- remove() { }
263
- insertAdjacentElement(where, element) {
264
- return null;
265
- }
266
- insertAdjacentText(where, data) { }
267
- insertAdjacentHTML(position, text) { }
268
- replaceChildren(...nodes) { }
269
- };
270
- // Define HTMLImageElement globally
271
- globalThis.HTMLImageElement = class {
272
- constructor() {
273
- this.alt = '';
274
- this.src = '';
275
- this.srcset = '';
276
- this.sizes = '';
277
- this.crossOrigin = null;
278
- this.useMap = '';
279
- this.isMap = false;
280
- this.width = 0;
281
- this.height = 0;
282
- this.naturalWidth = 0;
283
- this.naturalHeight = 0;
284
- this.complete = false;
285
- this.name = '';
286
- this.lowsrc = '';
287
- this.align = '';
288
- this.hspace = 0;
289
- this.vspace = 0;
290
- this.longDesc = '';
291
- this.border = '';
292
- this.x = 0;
293
- this.y = 0;
294
- this.currentSrc = '';
295
- this.decoding = 'auto';
296
- this.fetchPriority = 'auto';
297
- this.loading = 'eager';
298
- this.referrerPolicy = '';
299
- // Initialize any required properties
300
- }
301
- decode() {
302
- return Promise.resolve();
303
- }
304
- };
305
- // Create a virtual console
306
- const virtualConsole = new VirtualConsole();
307
- // Create a virtual DOM
308
- const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', {
309
- virtualConsole,
310
- runScripts: 'dangerously',
311
- resources: 'usable',
312
- pretendToBeVisual: true,
313
- beforeParse(window) {
314
- setupDOMInterfaces(window);
315
- setupRange(window);
316
- setupDocumentMethods(window);
317
- setupWindowMethods(window);
318
- }
319
- });
320
- // Get the window object
321
- const window = dom.window;
322
- // Add window to global scope
323
- globalThis.window = window;
324
- // Add document to global scope
325
- globalThis.document = window.document;
326
- // Add required DOM interfaces to global scope
327
- globalThis.Element = window.Element;
328
- globalThis.Node = window.Node;
329
- globalThis.NodeFilter = window.NodeFilter;
330
- globalThis.Range = window.Range;
331
- globalThis.DOMParser = window.DOMParser;
332
- globalThis.XMLSerializer = window.XMLSerializer;
333
- // Handle navigator property
334
- if (!globalThis.navigator || Object.getOwnPropertyDescriptor(globalThis, 'navigator')?.configurable) {
335
- Object.defineProperty(globalThis, 'navigator', {
336
- value: window.navigator,
337
- writable: false,
338
- configurable: true
339
- });
340
- }
341
- globalThis.HTMLElement = window.HTMLElement;
342
- // Define DOMSettableTokenList
343
- globalThis.DOMSettableTokenList = class {
344
- constructor() {
345
- this.length = 0;
346
- this.value = '';
347
- }
348
- add(token) { }
349
- contains(token) { return false; }
350
- item(index) { return null; }
351
- remove(token) { }
352
- replace(oldToken, newToken) { return false; }
353
- supports(token) { return false; }
354
- toggle(token, force) { return false; }
355
- [Symbol.iterator]() {
356
- return function* () { yield ''; return undefined; }();
357
- }
358
- };
359
- // Define HTML element types
360
- globalThis.HTMLIFrameElement = class extends globalThis.HTMLElement {
361
- constructor() {
362
- super();
363
- this.align = '';
364
- this.allow = '';
365
- this.allowFullscreen = false;
366
- this.contentDocument = null;
367
- this.contentWindow = null;
368
- this.frameBorder = '';
369
- this.height = '';
370
- this.longDesc = '';
371
- this.marginHeight = '';
372
- this.marginWidth = '';
373
- this.name = '';
374
- this.referrerPolicy = '';
375
- this.sandbox = {
376
- length: 0,
377
- value: '',
378
- add: () => { },
379
- contains: () => false,
380
- item: () => null,
381
- remove: () => { },
382
- replace: () => false,
383
- supports: () => false,
384
- toggle: () => false,
385
- [Symbol.iterator]: function* () { yield ''; return undefined; }
386
- };
387
- this.scrolling = '';
388
- this.src = '';
389
- this.srcdoc = '';
390
- this.width = '';
391
- }
392
- };
393
- globalThis.HTMLOListElement = class extends globalThis.HTMLElement {
394
- constructor() {
395
- super();
396
- this.type = '';
397
- this.compact = false;
398
- this.reversed = false;
399
- this.start = 0;
400
- }
401
- };
402
- globalThis.HTMLUListElement = class extends globalThis.HTMLElement {
403
- constructor() {
404
- super();
405
- this.type = '';
406
- this.compact = false;
407
- }
408
- };
409
- globalThis.HTMLTableElement = class extends globalThis.HTMLElement {
410
- constructor() {
411
- super();
412
- this.caption = null;
413
- this.tHead = null;
414
- this.tFoot = null;
415
- this.tBodies = {
416
- length: 0,
417
- item: () => null,
418
- namedItem: () => null,
419
- [Symbol.iterator]: function* () { yield null; return undefined; }
420
- };
421
- this.rows = {
422
- length: 0,
423
- item: () => null,
424
- namedItem: () => null,
425
- [Symbol.iterator]: function* () { yield null; return undefined; }
426
- };
427
- this.align = '';
428
- this.bgColor = '';
429
- this.border = '';
430
- this.cellPadding = '';
431
- this.cellSpacing = '';
432
- this.frame = '';
433
- this.rules = '';
434
- this.summary = '';
435
- this.width = '';
436
- }
437
- createCaption() {
438
- return new globalThis.HTMLTableCaptionElement();
439
- }
440
- deleteCaption() { }
441
- createTHead() {
442
- return new globalThis.HTMLTableSectionElement();
443
- }
444
- deleteTHead() { }
445
- createTFoot() {
446
- return new globalThis.HTMLTableSectionElement();
447
- }
448
- deleteTFoot() { }
449
- createTBody() {
450
- return new globalThis.HTMLTableSectionElement();
451
- }
452
- insertRow(index) {
453
- return new globalThis.HTMLTableRowElement();
454
- }
455
- deleteRow(index) { }
456
- };
457
- globalThis.HTMLTableRowElement = class extends globalThis.HTMLElement {
458
- constructor() {
459
- super();
460
- this.rowIndex = 0;
461
- this.sectionRowIndex = 0;
462
- this.cells = {
463
- length: 0,
464
- item: () => null,
465
- namedItem: () => null,
466
- [Symbol.iterator]: function* () { yield null; return undefined; }
467
- };
468
- this.align = '';
469
- this.bgColor = '';
470
- this.ch = '';
471
- this.chOff = '';
472
- this.vAlign = '';
473
- }
474
- insertCell(index) {
475
- return new globalThis.HTMLTableCellElement();
476
- }
477
- deleteCell(index) { }
478
- };
479
- globalThis.HTMLTableCellElement = class extends globalThis.HTMLElement {
480
- constructor() {
481
- super();
482
- this.colSpan = 1;
483
- this.rowSpan = 1;
484
- this.headers = {
485
- length: 0,
486
- value: '',
487
- add: () => { },
488
- contains: () => false,
489
- item: () => null,
490
- remove: () => { },
491
- replace: () => false,
492
- supports: () => false,
493
- toggle: () => false,
494
- [Symbol.iterator]: function* () { yield ''; return undefined; }
495
- };
496
- this.cellIndex = 0;
497
- this.scope = '';
498
- this.abbr = '';
499
- this.align = '';
500
- this.axis = '';
501
- this.bgColor = '';
502
- this.ch = '';
503
- this.chOff = '';
504
- this.height = '';
505
- this.noWrap = false;
506
- this.vAlign = '';
507
- this.width = '';
508
- }
509
- };
510
- globalThis.HTMLTableSectionElement = class extends globalThis.HTMLElement {
511
- constructor() {
512
- super();
513
- this.rows = {
514
- length: 0,
515
- item: () => null,
516
- namedItem: () => null,
517
- [Symbol.iterator]: function* () { yield null; return undefined; }
518
- };
519
- this.align = '';
520
- this.ch = '';
521
- this.chOff = '';
522
- this.vAlign = '';
523
- }
524
- insertRow(index) {
525
- return new globalThis.HTMLTableRowElement();
526
- }
527
- deleteRow(index) { }
528
- };
529
- globalThis.HTMLTableCaptionElement = class extends globalThis.HTMLElement {
530
- constructor() {
531
- super();
532
- this.align = '';
533
- }
534
- };
535
- globalThis.HTMLButtonElement = class extends globalThis.HTMLElement {
536
- constructor() {
537
- super();
538
- this.disabled = false;
539
- this.form = null;
540
- this.formAction = '';
541
- this.formEnctype = '';
542
- this.formMethod = '';
543
- this.formNoValidate = false;
544
- this.formTarget = '';
545
- this.name = '';
546
- this.type = 'submit';
547
- this.value = '';
548
- this.menu = null;
549
- }
550
- };
551
- // Add HTMLSpanElement interface
552
- globalThis.HTMLSpanElement = class extends globalThis.HTMLElement {
553
- constructor() {
554
- super();
555
- }
556
- };
557
- // Add HTMLDivElement interface
558
- globalThis.HTMLDivElement = class extends globalThis.HTMLElement {
559
- constructor() {
560
- super();
561
- this.align = '';
562
- }
563
- };
564
- globalThis.HTMLAnchorElement = class extends globalThis.HTMLElement {
565
- constructor() {
566
- super();
567
- this.href = '';
568
- this.target = '';
569
- this.download = '';
570
- this.ping = '';
571
- this.rel = '';
572
- this.relList = {
573
- length: 0,
574
- value: '',
575
- add: () => { },
576
- contains: () => false,
577
- item: () => null,
578
- remove: () => { },
579
- replace: () => false,
580
- supports: () => false,
581
- toggle: () => false,
582
- [Symbol.iterator]: function* () { yield ''; return undefined; }
583
- };
584
- this.hreflang = '';
585
- this.type = '';
586
- this.text = '';
587
- this.referrerPolicy = '';
588
- this.origin = '';
589
- this.protocol = '';
590
- this.username = '';
591
- this.password = '';
592
- this.host = '';
593
- this.hostname = '';
594
- this.port = '';
595
- this.pathname = '';
596
- this.search = '';
597
- this.hash = '';
598
- }
599
- };
600
11
  const program = new Command();
601
12
  program
602
13
  .name('defuddle')
@@ -618,107 +29,28 @@ program
618
29
  if (options.md) {
619
30
  options.markdown = true;
620
31
  }
621
- let html;
32
+ let dom;
622
33
  try {
623
34
  // Determine if source is a URL or file path
624
35
  if (source.startsWith('http://') || source.startsWith('https://')) {
625
- const response = await fetch(source);
626
- html = await response.text();
36
+ dom = await JSDOM.fromURL(source);
627
37
  }
628
38
  else {
629
39
  const filePath = resolve(process.cwd(), source);
630
- html = await readFile(filePath, 'utf-8');
631
- }
632
- // Create a new JSDOM instance with the HTML content
633
- const contentDom = new JSDOM(html, {
634
- virtualConsole,
635
- runScripts: 'dangerously',
636
- resources: 'usable',
637
- pretendToBeVisual: true,
638
- url: source.startsWith('http') ? source : undefined,
639
- beforeParse(window) {
640
- try {
641
- setupDOMInterfaces(window);
642
- }
643
- catch (error) {
644
- console.error('Error setting up DOM interfaces:', error);
645
- }
646
- }
647
- });
648
- // Initialize document properties
649
- const doc = contentDom.window.document;
650
- // Ensure document has required properties
651
- if (!doc.documentElement) {
652
- throw new Error('Document has no root element');
653
- }
654
- // Set up document properties
655
- try {
656
- doc.documentElement.style.cssText = '';
657
- doc.documentElement.className = '';
658
- }
659
- catch (error) {
660
- console.warn('Warning: Could not set document element properties:', error);
661
- }
662
- // Ensure body exists and is properly set up
663
- if (!doc.body) {
664
- const body = doc.createElement('body');
665
- doc.documentElement.appendChild(body);
666
- }
667
- try {
668
- doc.body.style.cssText = '';
669
- doc.body.className = '';
670
- }
671
- catch (error) {
672
- console.warn('Warning: Could not set body properties:', error);
673
- }
674
- // Set up viewport and ensure head exists
675
- if (!doc.head) {
676
- const head = doc.createElement('head');
677
- doc.documentElement.insertBefore(head, doc.body);
678
- }
679
- // Add viewport meta tag
680
- try {
681
- const viewport = doc.createElement('meta');
682
- viewport.setAttribute('name', 'viewport');
683
- viewport.setAttribute('content', 'width=device-width, initial-scale=1');
684
- doc.head.appendChild(viewport);
685
- }
686
- catch (error) {
687
- console.warn('Warning: Could not add viewport meta tag:', error);
688
- }
689
- // Add a base style element for mobile styles
690
- try {
691
- const style = doc.createElement('style');
692
- style.textContent = `
693
- @media (max-width: 768px) {
694
- body { width: 100%; }
695
- }
696
- `;
697
- doc.head.appendChild(style);
698
- }
699
- catch (error) {
700
- console.warn('Warning: Could not add style element:', error);
40
+ dom = await JSDOM.fromFile(filePath);
701
41
  }
702
42
  // Parse content with debug mode if enabled
703
43
  try {
704
- // @ts-ignore - Module interop issue between ES modules and CommonJS
705
- const defuddle = new Defuddle(doc, {
44
+ const result = await Defuddle(dom, source.startsWith('http') ? source : undefined, {
706
45
  debug: options.debug,
707
- ...(source.startsWith('http') ? { url: source } : {})
46
+ markdown: options.markdown
708
47
  });
709
- const result = await defuddle.parse();
710
48
  // If in debug mode, don't show content output
711
49
  if (options.debug) {
712
50
  process.exit(0);
713
51
  }
714
52
  // Format output
715
53
  let output;
716
- let content;
717
- let contentMarkdown;
718
- // Convert content to markdown if requested
719
- if (options.markdown || options.json) {
720
- contentMarkdown = createMarkdownContent(result.content, source);
721
- }
722
54
  // Format the response based on options
723
55
  if (options.property) {
724
56
  // Extract specific property
@@ -746,10 +78,6 @@ program
746
78
  schemaOrgData: result.schemaOrgData,
747
79
  wordCount: result.wordCount
748
80
  };
749
- // Only include markdown content if markdown flag is set
750
- if (options.markdown) {
751
- jsonObj.contentMarkdown = contentMarkdown;
752
- }
753
81
  output = JSON.stringify(jsonObj, null, 2)
754
82
  .replace(/"([^"]+)":/g, chalk.cyan('"$1":'))
755
83
  .replace(/: "([^"]+)"/g, chalk.yellow(': "$1"'))
@@ -757,7 +85,7 @@ program
757
85
  .replace(/: (true|false|null)/g, chalk.magenta(': $1'));
758
86
  }
759
87
  else {
760
- output = options.markdown ? contentMarkdown : result.content;
88
+ output = result.content;
761
89
  }
762
90
  // Handle output
763
91
  if (options.output) {
@@ -768,9 +96,6 @@ program
768
96
  else {
769
97
  console.log(output);
770
98
  }
771
- // Clean up JSDOM resources
772
- contentDom.window.close();
773
- dom.window.close();
774
99
  process.exit(0);
775
100
  }
776
101
  catch (error) {