@aiquants/html-to-markdown 1.0.0 → 1.2.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.
- package/dist/core-CTBCnkuY.js +3 -0
- package/dist/core-diGadcw4.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/main.cjs +1 -1
- package/dist/main.js +1 -1
- package/dist/mcp-server-DSLDlYZX.cjs +1 -0
- package/dist/mcp-server-DmJXoVRZ.js +1 -0
- package/dist/mcp-server-streamable-CgJP5t9P.js +1 -0
- package/dist/mcp-server-streamable-DZ7VyWAg.cjs +1 -0
- 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/mcp-server-streamable.d.ts +7 -4
- package/dist/src/mcp-server.d.ts +114 -51
- package/dist/version-DAQkOvqo.cjs +7 -0
- package/dist/version-yDYKn_vW.js +7 -0
- package/package.json +15 -14
- package/dist/core--XIBQvpW.cjs +0 -1
- package/dist/core-ChRwTJHy.js +0 -3
- package/dist/mcp-server-CvLGX0Fe.js +0 -1
- package/dist/mcp-server-eznfa4gh.cjs +0 -1
- package/dist/mcp-server-streamable-CjY9xfH0.js +0 -1
- package/dist/mcp-server-streamable-DJ-R_Z_E.cjs +0 -1
- package/dist/version-D8gIcbbb.cjs +0 -7
- package/dist/version-DEqf1gI6.js +0 -7
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-diGadcw4.cjs"),t=require("./mcp-server-DSLDlYZX.cjs"),c=require("./mcp-server-streamable-DZ7VyWAg.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
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Window as e}from"happy-dom";const r=new e;Object.assign(global,{document:r.document,window:r,self:r});import{g as a,h as s}from"./core-
|
|
1
|
+
import{Window as e}from"happy-dom";const r=new e;Object.assign(global,{document:r.document,window:r,self:r});import{g as a,h as s}from"./core-CTBCnkuY.js";import{c as o,r as m}from"./mcp-server-DmJXoVRZ.js";import{c as t,r as c}from"./mcp-server-streamable-CgJP5t9P.js";export{o as createMcpServer,t as createStreamableMcpServer,a as getMessage,s as htmlToMarkdown,m as runMcpServer,c as runStreamableMcpServer};
|
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-diGadcw4.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
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Window as t}from"happy-dom";const e=new t;Object.assign(global,{document:e.document,window:e,self:e});import{g as o,h as s}from"./core-
|
|
2
|
+
import{Window as t}from"happy-dom";const e=new t;Object.assign(global,{document:e.document,window:e,self:e});import{g as o,h as s}from"./core-CTBCnkuY.js";(async()=>{(import.meta.url.endsWith(process.argv[1])||process.argv[1]&&process.argv[1].includes("vite-node"))&&(async()=>{const t=(await import("yargs-parser")).default,e=await import("node:fs"),o=await import("node:path"),c=t(process.argv.slice(2),{string:["locale","output","html-content"],alias:{output:["o"],"html-content":["h"]},default:{locale:"en-US"}}),r=c._[0],n=c.locale,a=c.output,i=c["html-content"];if(r||i||process.exit(1),r&&!i)try{new URL(r)}catch(l){process.exit(1)}try{const{markdown:t,html:c}=await s(r||"direct-html-input",{locale:n,htmlContent:i});let l;if(a){l=o.resolve(process.cwd(),a);const t=o.dirname(l);e.existsSync(t)||e.mkdirSync(t,{recursive:!0})}else{let t;t=i?"html_content":r.replace(/https?:\/\//,"").replace(/[^a-zA-Z0-9]/g,"_");const s=`${t}_${Date.now()}.md`,c=o.join(process.cwd(),".outputs","raw");e.existsSync(c)||e.mkdirSync(c,{recursive:!0}),l=o.join(c,s)}e.writeFileSync(l,t);const p=o.parse(l),m=o.join(p.dir,`${p.name}.html`);e.writeFileSync(m,c)}catch(l){process.exit(1)}})()})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});const t=require("./version-DAQkOvqo.cjs"),r=require("node:process"),a=require("./core-diGadcw4.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},{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()};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Window as t}from"happy-dom";const e=new t;Object.assign(global,{document:e.document,window:e,self:e});import{J as r,g as a,S as n,L as s,M as o,C as i,p as c,c as l,a as d,b as h,s as u,d as f}from"./version-yDYKn_vW.js";import m from"node:process";import{h as p}from"./core-CTBCnkuY.js";class _{append(t){this._buffer=this._buffer?Buffer.concat([this._buffer,t]):t}readMessage(){if(!this._buffer)return null;const t=this._buffer.indexOf("\n");if(-1===t)return null;const e=this._buffer.toString("utf8",0,t).replace(/\r$/,"");return this._buffer=this._buffer.subarray(t+1),function(t){return r.parse(JSON.parse(t))}(e)}clear(){this._buffer=void 0}}class w{constructor(t=m.stdin,e=m.stdout){this._stdin=t,this._stdout=e,this._readBuffer=new _,this._started=!1,this._ondata=t=>{this._readBuffer.append(t),this.processReadBuffer()},this._onerror=t=>{var e;null===(e=this.onerror)||void 0===e||e.call(this,t)}}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 t,e;;)try{const e=this._readBuffer.readMessage();if(null===e)break;null===(t=this.onmessage)||void 0===t||t.call(this,e)}catch(r){null===(e=this.onerror)||void 0===e||e.call(this,r)}}async close(){var t;this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror);0===this._stdin.listenerCount("data")&&this._stdin.pause(),this._readBuffer.clear(),null===(t=this.onclose)||void 0===t||t.call(this)}send(t){return new Promise(e=>{const r=function(t){return JSON.stringify(t)+"\n"}(t);this._stdout.write(r)?e():this._stdout.once("drain",e)})}}class v{constructor(){this.version=a(),this.server=new n({name:"@aiquants/html-to-markdown",version:this.version},{capabilities:{tools:{}}}),this.setupToolHandlers()}setupToolHandlers(){this.server.setRequestHandler(s,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:o.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:o.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:o.urlToMarkdownFile}]})),this.server.setRequestHandler(i,async t=>{switch(t.params.name){case"html_to_markdown":return await this.handleHtmlToMarkdown(t.params.arguments);case"save_content_to_file":return await this.handleSaveContentToFile(t.params.arguments);case"url_to_markdown_file":return await this.handleUrlToMarkdownFile(t.params.arguments);default:throw new Error(`Unknown tool: ${t.params.name}`)}})}async handleHtmlToMarkdown(t){try{const e=c(t),{url:r,html_content:a,locale:n="en-US"}=e;if(r)try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const s=(await p(r||"direct-html-input",{locale:n,htmlContent:a})).markdown;return l(s)}catch(e){return d(e)}}async handleSaveContentToFile(t){try{const e=h(t),{content:r,save_path:a,save_directory:n,filename:s}=e,o=await u(r,a,n,s);return l(`File saved successfully to: ${o}`)}catch(e){return d(e)}}async handleUrlToMarkdownFile(t){try{const e=f(t),{url:r,html_content:a,locale:n="en-US",save_path:s,save_directory:o,filename:i}=e;if(r)try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const c=(await p(r||"direct-html-input",{locale:n,htmlContent:a})).markdown;let d=i;!d&&r&&(d=this.generateFilenameFromUrl(r));const h=await u(c,s,o,d);return l(`URL successfully converted to Markdown and saved to: ${h}`)}catch(e){return d(e)}}generateFilenameFromUrl(t){try{let e=new URL(t).pathname.split("/").pop()||"page";return e=e.replace(/\.[^.]*$/,""),e=e.replace(/[<>:"/\\|?*]/g,"_"),e&&!e.match(/^\.+$/)||(e="page"),e}catch{return"page"}}async start(){const t=new w;await this.server.connect(t)}}const y=()=>new v,g=async()=>{const t=y();await t.start()};export{y as c,g as r};
|