@aiquants/html-to-markdown 0.3.0 → 0.5.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/README.md +123 -4
- package/dist/{core-CouDTni-.js → core-DJV8t_Qj.js} +8 -4
- package/dist/core-Dq4LfiYy.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/main.cjs +1 -1
- package/dist/main.js +30 -13
- package/dist/mcp-server-CMBUHOmc.cjs +1 -0
- package/dist/{mcp-server-BAmy7d8r.js → mcp-server-DD8CqdNw.js} +59 -2
- package/dist/{mcp-server-streamable-CVDJHcWu.js → mcp-server-streamable-DODolSbj.js} +127 -3
- package/dist/{mcp-server-streamable-mF26pg3E.cjs → mcp-server-streamable-IQlimU2H.cjs} +1 -1
- 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/index.d.ts +1 -1
- package/dist/src/mcp-common.d.ts +57 -0
- package/dist/src/mcp-server-streamable.d.ts +15 -2
- package/dist/src/mcp-server.d.ts +79 -2
- package/dist/src/types.d.ts +6 -6
- package/dist/{version-Cg6D6H9g.cjs → version-BkgGdAYt.cjs} +1 -1
- package/dist/{version-BF9-U8Ef.js → version-CTdrYd1G.js} +81 -7
- package/mcp.json +2 -2
- package/package.json +1 -1
- package/dist/core-D2dlEt1l.cjs +0 -1
- package/dist/mcp-server-CCu0Pcm3.cjs +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const t=new(require("happy-dom").Window);Object.assign(global,{document:t.document,window:t,self:t});const e=require("./version-Cg6D6H9g.cjs"),r=require("node:process"),s=require("./core-D2dlEt1l.cjs");class a{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 r=this._buffer.toString("utf8",0,t).replace(/\r$/,"");return this._buffer=this._buffer.subarray(t+1),function(t){return e.JSONRPCMessageSchema.parse(JSON.parse(t))}(r)}clear(){this._buffer=void 0}}class n{constructor(t=r.stdin,e=r.stdout){this._stdin=t,this._stdout=e,this._readBuffer=new a,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 o{constructor(){this.version=e.getPackageVersion(),this.server=new e.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(e.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:e.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:e.MCP_TOOL_SCHEMAS.saveContentToFile}]})),this.server.setRequestHandler(e.CallToolRequestSchema,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);default:throw new Error(`Unknown tool: ${t.params.name}`)}})}async handleHtmlToMarkdown(t){try{const r=e.parseHtmlToMarkdownArgs(t),{url:a,html_content:n,locale:o="en-US"}=r;if(a)try{new URL(a)}catch{throw new Error(`Invalid URL: ${a}`)}const i=(await s.htmlToMarkdown(a||"direct-html-input",{locale:o,htmlContent:n})).markdown;return e.createSuccessResult(i)}catch(r){return e.createErrorResult(r)}}async handleSaveContentToFile(t){try{const r=e.parseSaveContentArgs(t),{content:s,save_path:a,save_directory:n,filename:o}=r,i=`File saved successfully to: ${await e.saveContentToFile(s,a,n,o)}`;return e.createSuccessResult(i)}catch(r){return e.createErrorResult(r)}}async start(){const t=new n;await this.server.connect(t)}}const i=()=>new o;exports.createMcpServer=i,exports.runMcpServer=async()=>{const t=i();await t.start()};
|