@aiquants/html-to-markdown 0.5.0 → 0.5.2
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/dist/{core-Dq4LfiYy.cjs → core--XIBQvpW.cjs} +1 -1
- package/dist/{core-DJV8t_Qj.js → core-DhxxOcPm.js} +334 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/main.cjs +1 -1
- package/dist/main.js +1 -1
- package/dist/{mcp-server-DD8CqdNw.js → mcp-server-DOe8W9IZ.js} +2 -2
- package/dist/{mcp-server-CMBUHOmc.cjs → mcp-server-Dn3EHzcf.cjs} +1 -1
- package/dist/{mcp-server-streamable-IQlimU2H.cjs → mcp-server-streamable-DUB_ixZe.cjs} +1 -1
- package/dist/{mcp-server-streamable-DODolSbj.js → mcp-server-streamable-pcpU_lDl.js} +2 -2
- package/dist/mcp-streamable.cjs +1 -1
- package/dist/mcp-streamable.js +1 -1
- package/dist/mcp.cjs +1 -1
- package/dist/mcp.js +1 -1
- package/dist/src/plugins/index.d.ts +1 -0
- package/dist/src/plugins/rehype-decode-entities.d.ts +14 -0
- package/dist/tests/entity-decoding.test.d.ts +5 -0
- package/dist/{version-CTdrYd1G.js → version-BNwQMbri.js} +1 -1
- package/dist/{version-BkgGdAYt.cjs → version-BsWiDlbg.cjs} +1 -1
- package/package.json +3 -2
|
@@ -20418,6 +20418,335 @@ const rehypeAbsoluteLinks = (options) => {
|
|
|
20418
20418
|
});
|
|
20419
20419
|
};
|
|
20420
20420
|
};
|
|
20421
|
+
const rehypeDecodeEntities = () => {
|
|
20422
|
+
return (tree) => {
|
|
20423
|
+
visit(tree, "text", (node2) => {
|
|
20424
|
+
node2.value = decodeHtmlEntities(node2.value);
|
|
20425
|
+
});
|
|
20426
|
+
visit(tree, "element", (node2) => {
|
|
20427
|
+
if (node2.properties) {
|
|
20428
|
+
for (const [key2, value] of Object.entries(node2.properties)) {
|
|
20429
|
+
if (typeof value === "string") {
|
|
20430
|
+
node2.properties[key2] = decodeHtmlEntities(value);
|
|
20431
|
+
}
|
|
20432
|
+
}
|
|
20433
|
+
}
|
|
20434
|
+
});
|
|
20435
|
+
};
|
|
20436
|
+
};
|
|
20437
|
+
const preprocessHtmlEntities = (html2) => {
|
|
20438
|
+
return decodeHtmlEntities(html2);
|
|
20439
|
+
};
|
|
20440
|
+
function decodeHtmlEntities(text2) {
|
|
20441
|
+
if (!text2 || typeof text2 !== "string") {
|
|
20442
|
+
return text2;
|
|
20443
|
+
}
|
|
20444
|
+
text2 = text2.replace(/&#(\d+);/g, (match, dec) => {
|
|
20445
|
+
try {
|
|
20446
|
+
const codePoint = parseInt(dec, 10);
|
|
20447
|
+
if (codePoint >= 0 && codePoint <= 1114111) {
|
|
20448
|
+
return String.fromCodePoint(codePoint);
|
|
20449
|
+
}
|
|
20450
|
+
return match;
|
|
20451
|
+
} catch {
|
|
20452
|
+
return match;
|
|
20453
|
+
}
|
|
20454
|
+
});
|
|
20455
|
+
text2 = text2.replace(/&#[xX]([0-9a-fA-F]+);/g, (match, hex) => {
|
|
20456
|
+
try {
|
|
20457
|
+
const codePoint = parseInt(hex, 16);
|
|
20458
|
+
if (codePoint >= 0 && codePoint <= 1114111) {
|
|
20459
|
+
return String.fromCodePoint(codePoint);
|
|
20460
|
+
}
|
|
20461
|
+
return match;
|
|
20462
|
+
} catch {
|
|
20463
|
+
return match;
|
|
20464
|
+
}
|
|
20465
|
+
});
|
|
20466
|
+
const namedEntities = getComprehensiveNamedEntities();
|
|
20467
|
+
for (const [entity, character] of Object.entries(namedEntities)) {
|
|
20468
|
+
const regex2 = new RegExp(entity.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g");
|
|
20469
|
+
text2 = text2.replace(regex2, character);
|
|
20470
|
+
}
|
|
20471
|
+
return text2;
|
|
20472
|
+
}
|
|
20473
|
+
function getComprehensiveNamedEntities() {
|
|
20474
|
+
return {
|
|
20475
|
+
// 基本的なHTMLエンティティ(大文字小文字両対応)
|
|
20476
|
+
"&": "&",
|
|
20477
|
+
"&": "&",
|
|
20478
|
+
"<": "<",
|
|
20479
|
+
"<": "<",
|
|
20480
|
+
">": ">",
|
|
20481
|
+
">": ">",
|
|
20482
|
+
""": '"',
|
|
20483
|
+
""": '"',
|
|
20484
|
+
"'": "'",
|
|
20485
|
+
"&APOS;": "'",
|
|
20486
|
+
" ": " ",
|
|
20487
|
+
"&NBSP;": " ",
|
|
20488
|
+
// 数学記号
|
|
20489
|
+
"×": "×",
|
|
20490
|
+
"÷": "÷",
|
|
20491
|
+
"−": "−",
|
|
20492
|
+
"±": "±",
|
|
20493
|
+
"¹": "¹",
|
|
20494
|
+
"²": "²",
|
|
20495
|
+
"³": "³",
|
|
20496
|
+
"¼": "¼",
|
|
20497
|
+
"½": "½",
|
|
20498
|
+
"¾": "¾",
|
|
20499
|
+
"∞": "∞",
|
|
20500
|
+
"∑": "∑",
|
|
20501
|
+
"∏": "∏",
|
|
20502
|
+
"√": "√",
|
|
20503
|
+
"∝": "∝",
|
|
20504
|
+
"∂": "∂",
|
|
20505
|
+
"∫": "∫",
|
|
20506
|
+
"∠": "∠",
|
|
20507
|
+
"⊥": "⊥",
|
|
20508
|
+
"∥": "∥",
|
|
20509
|
+
// ギリシャ文字
|
|
20510
|
+
"Α": "Α",
|
|
20511
|
+
"α": "α",
|
|
20512
|
+
"Β": "Β",
|
|
20513
|
+
"β": "β",
|
|
20514
|
+
"Γ": "Γ",
|
|
20515
|
+
"γ": "γ",
|
|
20516
|
+
"Δ": "Δ",
|
|
20517
|
+
"δ": "δ",
|
|
20518
|
+
"Ε": "Ε",
|
|
20519
|
+
"ε": "ε",
|
|
20520
|
+
"Ζ": "Ζ",
|
|
20521
|
+
"ζ": "ζ",
|
|
20522
|
+
"Η": "Η",
|
|
20523
|
+
"η": "η",
|
|
20524
|
+
"Θ": "Θ",
|
|
20525
|
+
"θ": "θ",
|
|
20526
|
+
"Ι": "Ι",
|
|
20527
|
+
"ι": "ι",
|
|
20528
|
+
"Κ": "Κ",
|
|
20529
|
+
"κ": "κ",
|
|
20530
|
+
"Λ": "Λ",
|
|
20531
|
+
"λ": "λ",
|
|
20532
|
+
"Μ": "Μ",
|
|
20533
|
+
"μ": "μ",
|
|
20534
|
+
"Ν": "Ν",
|
|
20535
|
+
"ν": "ν",
|
|
20536
|
+
"Ξ": "Ξ",
|
|
20537
|
+
"ξ": "ξ",
|
|
20538
|
+
"Ο": "Ο",
|
|
20539
|
+
"ο": "ο",
|
|
20540
|
+
"Π": "Π",
|
|
20541
|
+
"π": "π",
|
|
20542
|
+
"Ρ": "Ρ",
|
|
20543
|
+
"ρ": "ρ",
|
|
20544
|
+
"Σ": "Σ",
|
|
20545
|
+
"σ": "σ",
|
|
20546
|
+
"Τ": "Τ",
|
|
20547
|
+
"τ": "τ",
|
|
20548
|
+
"Υ": "Υ",
|
|
20549
|
+
"υ": "υ",
|
|
20550
|
+
"Φ": "Φ",
|
|
20551
|
+
"φ": "φ",
|
|
20552
|
+
"Χ": "Χ",
|
|
20553
|
+
"χ": "χ",
|
|
20554
|
+
"Ψ": "Ψ",
|
|
20555
|
+
"ψ": "ψ",
|
|
20556
|
+
"Ω": "Ω",
|
|
20557
|
+
"ω": "ω",
|
|
20558
|
+
// 通貨記号
|
|
20559
|
+
"€": "€",
|
|
20560
|
+
"¥": "¥",
|
|
20561
|
+
"£": "£",
|
|
20562
|
+
"¢": "¢",
|
|
20563
|
+
"¤": "¤",
|
|
20564
|
+
// 著作権・商標(大文字小文字両対応)
|
|
20565
|
+
"©": "©",
|
|
20566
|
+
"©": "©",
|
|
20567
|
+
"®": "®",
|
|
20568
|
+
"®": "®",
|
|
20569
|
+
"™": "™",
|
|
20570
|
+
"™": "™",
|
|
20571
|
+
// 句読点・記号
|
|
20572
|
+
"…": "…",
|
|
20573
|
+
"—": "—",
|
|
20574
|
+
"–": "–",
|
|
20575
|
+
"‘": "‘",
|
|
20576
|
+
"’": "’",
|
|
20577
|
+
"“": "“",
|
|
20578
|
+
"”": "”",
|
|
20579
|
+
"•": "•",
|
|
20580
|
+
"·": "·",
|
|
20581
|
+
"§": "§",
|
|
20582
|
+
"¶": "¶",
|
|
20583
|
+
"†": "†",
|
|
20584
|
+
"‡": "‡",
|
|
20585
|
+
"‰": "‰",
|
|
20586
|
+
"‹": "‹",
|
|
20587
|
+
"›": "›",
|
|
20588
|
+
"«": "«",
|
|
20589
|
+
"»": "»",
|
|
20590
|
+
// アクセント文字(ラテン文字)
|
|
20591
|
+
"À": "À",
|
|
20592
|
+
"à": "à",
|
|
20593
|
+
"Á": "Á",
|
|
20594
|
+
"á": "á",
|
|
20595
|
+
"Â": "Â",
|
|
20596
|
+
"â": "â",
|
|
20597
|
+
"Ã": "Ã",
|
|
20598
|
+
"ã": "ã",
|
|
20599
|
+
"Ä": "Ä",
|
|
20600
|
+
"ä": "ä",
|
|
20601
|
+
"Å": "Å",
|
|
20602
|
+
"å": "å",
|
|
20603
|
+
"Æ": "Æ",
|
|
20604
|
+
"æ": "æ",
|
|
20605
|
+
"Ç": "Ç",
|
|
20606
|
+
"ç": "ç",
|
|
20607
|
+
"È": "È",
|
|
20608
|
+
"è": "è",
|
|
20609
|
+
"É": "É",
|
|
20610
|
+
"é": "é",
|
|
20611
|
+
"Ê": "Ê",
|
|
20612
|
+
"ê": "ê",
|
|
20613
|
+
"Ë": "Ë",
|
|
20614
|
+
"ë": "ë",
|
|
20615
|
+
"Ì": "Ì",
|
|
20616
|
+
"ì": "ì",
|
|
20617
|
+
"Í": "Í",
|
|
20618
|
+
"í": "í",
|
|
20619
|
+
"Î": "Î",
|
|
20620
|
+
"î": "î",
|
|
20621
|
+
"Ï": "Ï",
|
|
20622
|
+
"ï": "ï",
|
|
20623
|
+
"Ð": "Ð",
|
|
20624
|
+
"ð": "ð",
|
|
20625
|
+
"Ñ": "Ñ",
|
|
20626
|
+
"ñ": "ñ",
|
|
20627
|
+
"Ò": "Ò",
|
|
20628
|
+
"ò": "ò",
|
|
20629
|
+
"Ó": "Ó",
|
|
20630
|
+
"ó": "ó",
|
|
20631
|
+
"Ô": "Ô",
|
|
20632
|
+
"ô": "ô",
|
|
20633
|
+
"Õ": "Õ",
|
|
20634
|
+
"õ": "õ",
|
|
20635
|
+
"Ö": "Ö",
|
|
20636
|
+
"ö": "ö",
|
|
20637
|
+
"Ø": "Ø",
|
|
20638
|
+
"ø": "ø",
|
|
20639
|
+
"Ù": "Ù",
|
|
20640
|
+
"ù": "ù",
|
|
20641
|
+
"Ú": "Ú",
|
|
20642
|
+
"ú": "ú",
|
|
20643
|
+
"Û": "Û",
|
|
20644
|
+
"û": "û",
|
|
20645
|
+
"Ü": "Ü",
|
|
20646
|
+
"ü": "ü",
|
|
20647
|
+
"Ý": "Ý",
|
|
20648
|
+
"ý": "ý",
|
|
20649
|
+
"Þ": "Þ",
|
|
20650
|
+
"þ": "þ",
|
|
20651
|
+
"ß": "ß",
|
|
20652
|
+
"ÿ": "ÿ",
|
|
20653
|
+
// 矢印
|
|
20654
|
+
"←": "←",
|
|
20655
|
+
"↑": "↑",
|
|
20656
|
+
"→": "→",
|
|
20657
|
+
"↓": "↓",
|
|
20658
|
+
"↔": "↔",
|
|
20659
|
+
"↵": "↵",
|
|
20660
|
+
"⇐": "⇐",
|
|
20661
|
+
"⇑": "⇑",
|
|
20662
|
+
"⇒": "⇒",
|
|
20663
|
+
"⇓": "⇓",
|
|
20664
|
+
"⇔": "⇔",
|
|
20665
|
+
// 数学記号(追加)
|
|
20666
|
+
"∀": "∀",
|
|
20667
|
+
"∃": "∃",
|
|
20668
|
+
"∅": "∅",
|
|
20669
|
+
"∇": "∇",
|
|
20670
|
+
"∈": "∈",
|
|
20671
|
+
"∉": "∉",
|
|
20672
|
+
"∋": "∋",
|
|
20673
|
+
"∩": "∩",
|
|
20674
|
+
"∪": "∪",
|
|
20675
|
+
"⊂": "⊂",
|
|
20676
|
+
"⊃": "⊃",
|
|
20677
|
+
"⊄": "⊄",
|
|
20678
|
+
"⊆": "⊆",
|
|
20679
|
+
"⊇": "⊇",
|
|
20680
|
+
"⊕": "⊕",
|
|
20681
|
+
"⊗": "⊗",
|
|
20682
|
+
"≡": "≡",
|
|
20683
|
+
"≠": "≠",
|
|
20684
|
+
"≤": "≤",
|
|
20685
|
+
"≥": "≥",
|
|
20686
|
+
"∼": "∼",
|
|
20687
|
+
"≅": "≅",
|
|
20688
|
+
"≈": "≈",
|
|
20689
|
+
// スペード・ハート・ダイヤ・クラブ
|
|
20690
|
+
"♠": "♠",
|
|
20691
|
+
"♥": "♥",
|
|
20692
|
+
"♦": "♦",
|
|
20693
|
+
"♣": "♣",
|
|
20694
|
+
// 追加の特殊文字
|
|
20695
|
+
"◊": "◊",
|
|
20696
|
+
"ℑ": "ℑ",
|
|
20697
|
+
"ℜ": "ℜ",
|
|
20698
|
+
"℘": "℘",
|
|
20699
|
+
"ℵ": "ℵ",
|
|
20700
|
+
// 日本語・中国語・韓国語特有のエンティティ
|
|
20701
|
+
"(": "(",
|
|
20702
|
+
// 全角左括弧
|
|
20703
|
+
")": ")",
|
|
20704
|
+
// 全角右括弧
|
|
20705
|
+
"シ": "シ",
|
|
20706
|
+
// カタカナのシ
|
|
20707
|
+
"シ": "シ",
|
|
20708
|
+
// カタカナのシ(大文字)
|
|
20709
|
+
"あ": "あ",
|
|
20710
|
+
// ひらがなのあ
|
|
20711
|
+
"い": "い",
|
|
20712
|
+
// ひらがなのい
|
|
20713
|
+
"う": "う",
|
|
20714
|
+
// ひらがなのう
|
|
20715
|
+
"え": "え",
|
|
20716
|
+
// ひらがなのえ
|
|
20717
|
+
"お": "お",
|
|
20718
|
+
// ひらがなのお
|
|
20719
|
+
// 中国語の文字
|
|
20720
|
+
"中": "中",
|
|
20721
|
+
// 中
|
|
20722
|
+
"文": "文",
|
|
20723
|
+
// 文
|
|
20724
|
+
"国": "国",
|
|
20725
|
+
// 国
|
|
20726
|
+
// 韓国語の文字
|
|
20727
|
+
"한": "한",
|
|
20728
|
+
// 한
|
|
20729
|
+
"국": "국",
|
|
20730
|
+
// 국
|
|
20731
|
+
"어": "어",
|
|
20732
|
+
// 어
|
|
20733
|
+
// その他のUnicode文字
|
|
20734
|
+
" ": " ",
|
|
20735
|
+
// En space
|
|
20736
|
+
" ": " ",
|
|
20737
|
+
// Em space
|
|
20738
|
+
" ": " ",
|
|
20739
|
+
// Thin space
|
|
20740
|
+
"‌": "",
|
|
20741
|
+
// Zero width non-joiner
|
|
20742
|
+
"‍": "",
|
|
20743
|
+
// Zero width joiner
|
|
20744
|
+
"‎": "",
|
|
20745
|
+
// Left-to-right mark
|
|
20746
|
+
"‏": ""
|
|
20747
|
+
// Right-to-left mark
|
|
20748
|
+
};
|
|
20749
|
+
}
|
|
20421
20750
|
const blockLevelTags = /* @__PURE__ */ new Set([
|
|
20422
20751
|
"address",
|
|
20423
20752
|
"article",
|
|
@@ -20687,7 +21016,8 @@ const handleTableCell = (_state, node2, _parent) => {
|
|
|
20687
21016
|
const convertHtmlToMarkdown = async (html2, baseUrl, locale) => {
|
|
20688
21017
|
console.info(getMessage(locale, "convert_start"));
|
|
20689
21018
|
const slugger2 = new BananaSlug();
|
|
20690
|
-
const
|
|
21019
|
+
const preprocessedHtml = preprocessHtmlEntities(html2);
|
|
21020
|
+
const file = await unified().use(rehypeParse, { fragment: true }).use(rehypeRaw).use(rehypeDecodeEntities).use(rehypeSanitizeHtml).use(rehypeWikipediaFootnotes).use(rehypeNamedAnchors).use(rehypeSlug).use(rehypeParagraphWrapper).use(rehypeAbsoluteLinks, { baseUrl }).use(rehypeRemark, {
|
|
20691
21021
|
handlers: {
|
|
20692
21022
|
span(state, node2) {
|
|
20693
21023
|
const id = node2.properties?.id;
|
|
@@ -20784,11 +21114,12 @@ const convertHtmlToMarkdown = async (html2, baseUrl, locale) => {
|
|
|
20784
21114
|
return value.replace(/\n/g, "").replace(/\|/g, "\\|");
|
|
20785
21115
|
}
|
|
20786
21116
|
}
|
|
20787
|
-
}).process(
|
|
21117
|
+
}).process(preprocessedHtml);
|
|
20788
21118
|
const unescapedMarkdown = String(file).replace(/\\\[\^(.+?)\\?\](?!\s*:)/g, "[^$1]").replace(/\]\(\\#/g, "](#");
|
|
20789
21119
|
const correctedMarkdown = unescapedMarkdown.replace(/(\s*)- - /g, "$1- ").replace(/(\s*)\* \* /g, "$1* ");
|
|
21120
|
+
const finalMarkdown = preprocessHtmlEntities(correctedMarkdown);
|
|
20790
21121
|
console.info(getMessage(locale, "convert_success"));
|
|
20791
|
-
return
|
|
21122
|
+
return finalMarkdown;
|
|
20792
21123
|
};
|
|
20793
21124
|
const htmlToMarkdown = async (urlOrHtml, options = {}) => {
|
|
20794
21125
|
const { locale = "en-US", htmlContent } = options;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e}),Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./core
|
|
1
|
+
const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e}),Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./core--XIBQvpW.cjs"),t=require("./mcp-server-Dn3EHzcf.cjs"),c=require("./mcp-server-streamable-DUB_ixZe.cjs");exports.getMessage=r.getMessage,exports.htmlToMarkdown=r.htmlToMarkdown,exports.createMcpServer=t.createMcpServer,exports.runMcpServer=t.runMcpServer,exports.createStreamableMcpServer=c.createStreamableMcpServer,exports.runStreamableMcpServer=c.runStreamableMcpServer;
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,9 @@ Object.assign(global, {
|
|
|
5
5
|
window,
|
|
6
6
|
self: window
|
|
7
7
|
});
|
|
8
|
-
import { g, h } from "./core-
|
|
9
|
-
import { c, r } from "./mcp-server-
|
|
10
|
-
import { c as c2, r as r2 } from "./mcp-server-streamable-
|
|
8
|
+
import { g, h } from "./core-DhxxOcPm.js";
|
|
9
|
+
import { c, r } from "./mcp-server-DOe8W9IZ.js";
|
|
10
|
+
import { c as c2, r as r2 } from "./mcp-server-streamable-pcpU_lDl.js";
|
|
11
11
|
export {
|
|
12
12
|
c as createMcpServer,
|
|
13
13
|
c2 as createStreamableMcpServer,
|
package/dist/main.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});const t=require("./core
|
|
2
|
+
Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});const t=require("./core--XIBQvpW.cjs");var r="undefined"!=typeof document?document.currentScript:null;(async()=>{(("undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&"SCRIPT"===r.tagName.toUpperCase()&&r.src||new URL("main.cjs",document.baseURI).href).endsWith(process.argv[1])||process.argv[1]&&process.argv[1].includes("vite-node"))&&(async()=>{const e=(await import("yargs-parser")).default,r=await import("node:fs"),o=await import("node:path"),c=e(process.argv.slice(2),{string:["locale","output","html-content"],alias:{output:["o"],"html-content":["h"]},default:{locale:"en-US"}}),n=c._[0],s=c.locale,a=c.output,i=c["html-content"];if(n||i||process.exit(1),n&&!i)try{new URL(n)}catch(p){process.exit(1)}try{const{markdown:e,html:c}=await t.htmlToMarkdown(n||"direct-html-input",{locale:s,htmlContent:i});let p;if(a){p=o.resolve(process.cwd(),a);const e=o.dirname(p);r.existsSync(e)||r.mkdirSync(e,{recursive:!0})}else{let e;e=i?"html_content":n.replace(/https?:\/\//,"").replace(/[^a-zA-Z0-9]/g,"_");const t=`${e}_${Date.now()}.md`,c=o.join(process.cwd(),".outputs","raw");r.existsSync(c)||r.mkdirSync(c,{recursive:!0}),p=o.join(c,t)}r.writeFileSync(p,e);const l=o.parse(p),d=o.join(l.dir,`${l.name}.html`);r.writeFileSync(d,c)}catch(p){process.exit(1)}})()})();
|
package/dist/main.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.assign(global, {
|
|
|
6
6
|
window,
|
|
7
7
|
self: window
|
|
8
8
|
});
|
|
9
|
-
import { g as getMessage, h as htmlToMarkdown } from "./core-
|
|
9
|
+
import { g as getMessage, h as htmlToMarkdown } from "./core-DhxxOcPm.js";
|
|
10
10
|
const runCli = async () => {
|
|
11
11
|
const yargsParser = (await import("yargs-parser")).default;
|
|
12
12
|
const fs = await import("node:fs");
|
|
@@ -5,9 +5,9 @@ Object.assign(global, {
|
|
|
5
5
|
window,
|
|
6
6
|
self: window
|
|
7
7
|
});
|
|
8
|
-
import { J as JSONRPCMessageSchema, g as getPackageVersion, S as Server, L as ListToolsRequestSchema, M as MCP_TOOL_SCHEMAS, C as CallToolRequestSchema, p as parseHtmlToMarkdownArgs, c as createSuccessResult, a as createErrorResult, b as parseSaveContentArgs, s as saveContentToFile, d as parseUrlToMarkdownFileArgs } from "./version-
|
|
8
|
+
import { J as JSONRPCMessageSchema, g as getPackageVersion, S as Server, L as ListToolsRequestSchema, M as MCP_TOOL_SCHEMAS, C as CallToolRequestSchema, p as parseHtmlToMarkdownArgs, c as createSuccessResult, a as createErrorResult, b as parseSaveContentArgs, s as saveContentToFile, d as parseUrlToMarkdownFileArgs } from "./version-BNwQMbri.js";
|
|
9
9
|
import process from "node:process";
|
|
10
|
-
import { h as htmlToMarkdown } from "./core-
|
|
10
|
+
import { h as htmlToMarkdown } from "./core-DhxxOcPm.js";
|
|
11
11
|
class ReadBuffer {
|
|
12
12
|
append(chunk) {
|
|
13
13
|
this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});const t=require("./version-
|
|
1
|
+
const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});const t=require("./version-BsWiDlbg.cjs"),r=require("node:process"),a=require("./core--XIBQvpW.cjs");class n{append(e){this._buffer=this._buffer?Buffer.concat([this._buffer,e]):e}readMessage(){if(!this._buffer)return null;const e=this._buffer.indexOf("\n");if(-1===e)return null;const r=this._buffer.toString("utf8",0,e).replace(/\r$/,"");return this._buffer=this._buffer.subarray(e+1),function(e){return t.JSONRPCMessageSchema.parse(JSON.parse(e))}(r)}clear(){this._buffer=void 0}}class s{constructor(e=r.stdin,t=r.stdout){this._stdin=e,this._stdout=t,this._readBuffer=new n,this._started=!1,this._ondata=e=>{this._readBuffer.append(e),this.processReadBuffer()},this._onerror=e=>{var t;null===(t=this.onerror)||void 0===t||t.call(this,e)}}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){for(var e,t;;)try{const t=this._readBuffer.readMessage();if(null===t)break;null===(e=this.onmessage)||void 0===e||e.call(this,t)}catch(r){null===(t=this.onerror)||void 0===t||t.call(this,r)}}async close(){var e;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror);0===this._stdin.listenerCount("data")&&this._stdin.pause(),this._readBuffer.clear(),null===(e=this.onclose)||void 0===e||e.call(this)}send(e){return new Promise(t=>{const r=function(e){return JSON.stringify(e)+"\n"}(e);this._stdout.write(r)?t():this._stdout.once("drain",t)})}}class o{constructor(){this.version=t.getPackageVersion(),this.server=new t.Server({name:"@aiquants/html-to-markdown",version:this.version,description:"Convert web pages and HTML to Markdown with JavaScript dynamic content support and table structure preservation. Includes separate file saving tool."},{capabilities:{tools:{}}}),this.setupToolHandlers()}setupToolHandlers(){this.server.setRequestHandler(t.ListToolsRequestSchema,async()=>({tools:[{name:"html_to_markdown",description:"Convert web pages or HTML strings to Markdown format. Handles JavaScript-rendered dynamic content and preserves table structures.",inputSchema:t.MCP_TOOL_SCHEMAS.htmlToMarkdown},{name:"save_content_to_file",description:"Save text content to a file with specified path or directory. Supports automatic filename generation and format detection.",inputSchema:t.MCP_TOOL_SCHEMAS.saveContentToFile},{name:"url_to_markdown_file",description:"Convert web pages or HTML strings directly to Markdown files. Combines HTML-to-Markdown conversion and file saving in one step. Handles JavaScript-rendered dynamic content.",inputSchema:t.MCP_TOOL_SCHEMAS.urlToMarkdownFile}]})),this.server.setRequestHandler(t.CallToolRequestSchema,async e=>{switch(e.params.name){case"html_to_markdown":return await this.handleHtmlToMarkdown(e.params.arguments);case"save_content_to_file":return await this.handleSaveContentToFile(e.params.arguments);case"url_to_markdown_file":return await this.handleUrlToMarkdownFile(e.params.arguments);default:throw new Error(`Unknown tool: ${e.params.name}`)}})}async handleHtmlToMarkdown(e){try{const r=t.parseHtmlToMarkdownArgs(e),{url:n,html_content:s,locale:o="en-US"}=r;if(n)try{new URL(n)}catch{throw new Error(`Invalid URL: ${n}`)}const i=(await a.htmlToMarkdown(n||"direct-html-input",{locale:o,htmlContent:s})).markdown;return t.createSuccessResult(i)}catch(r){return t.createErrorResult(r)}}async handleSaveContentToFile(e){try{const r=t.parseSaveContentArgs(e),{content:a,save_path:n,save_directory:s,filename:o}=r,i=`File saved successfully to: ${await t.saveContentToFile(a,n,s,o)}`;return t.createSuccessResult(i)}catch(r){return t.createErrorResult(r)}}async handleUrlToMarkdownFile(e){try{const r=t.parseUrlToMarkdownFileArgs(e),{url:n,html_content:s,locale:o="en-US",save_path:i,save_directory:c,filename:l}=r;if(n)try{new URL(n)}catch{throw new Error(`Invalid URL: ${n}`)}const d=(await a.htmlToMarkdown(n||"direct-html-input",{locale:o,htmlContent:s})).markdown;let u=l;!u&&n&&(u=this.generateFilenameFromUrl(n));const h=`URL successfully converted to Markdown and saved to: ${await t.saveContentToFile(d,i,c,u)}`;return t.createSuccessResult(h)}catch(r){return t.createErrorResult(r)}}generateFilenameFromUrl(e){try{let t=new URL(e).pathname.split("/").pop()||"page";return t=t.replace(/\.[^.]*$/,""),t=t.replace(/[<>:"/\\|?*]/g,"_"),t&&!t.match(/^\.+$/)||(t="page"),t}catch{return"page"}}async start(){const e=new s;await this.server.connect(e)}}const i=()=>new o;exports.createMcpServer=i,exports.runMcpServer=async()=>{const e=i();await e.start()};
|