@aiquants/html-to-markdown 0.2.4 → 0.2.5

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.
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";require("./mcp-server-streamable-B3R3qi85.cjs").runStreamableMcpServer().catch(e=>{process.exit(1)});
2
+ "use strict";require("./mcp-server-streamable-Cc4QsZQe.cjs").runStreamableMcpServer().catch(e=>{process.exit(1)});
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { r as runStreamableMcpServer } from "./mcp-server-streamable-CuBJeQTj.js";
2
+ import { r as runStreamableMcpServer } from "./mcp-server-streamable-BC-Qlr-9.js";
3
3
  runStreamableMcpServer().catch((error) => {
4
4
  console.error("Failed to start streamable MCP server:", error);
5
5
  process.exit(1);
package/dist/mcp.cjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});require("./mcp-server-B5lrAMe3.cjs").runMcpServer().catch(e=>{process.exit(1)});
2
+ const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});require("./mcp-server-Bo_mCvzz.cjs").runMcpServer().catch(e=>{process.exit(1)});
package/dist/mcp.js CHANGED
@@ -6,7 +6,7 @@ Object.assign(global, {
6
6
  window,
7
7
  self: window
8
8
  });
9
- import { r as runMcpServer } from "./mcp-server-BEggrdWH.js";
9
+ import { r as runMcpServer } from "./mcp-server-CueTvF4M.js";
10
10
  runMcpServer().catch((error) => {
11
11
  console.error("Failed to start MCP server:", error);
12
12
  process.exit(1);
package/mcp.json CHANGED
@@ -3,12 +3,12 @@
3
3
  "html-to-markdown": {
4
4
  "command": "npx",
5
5
  "args": ["@aiquants/html-to-markdown-mcp"],
6
- "description": "Convert HTML content from URLs to Markdown format"
6
+ "description": "Convert web pages and HTML to Markdown with JavaScript dynamic content support, table structure preservation, and file saving."
7
7
  },
8
8
  "html-to-markdown-streamable": {
9
9
  "command": "npx",
10
10
  "args": ["@aiquants/html-to-markdown-mcp-streamable"],
11
- "description": "Convert HTML content from URLs to Markdown format with streamable support"
11
+ "description": "HTML to Markdown converter with real-time progress updates. Ideal for large pages and time-consuming conversions."
12
12
  }
13
13
  }
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiquants/html-to-markdown",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "HTML to Markdown converter",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -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-DTaUKNBS.cjs"),r=require("node:process"),n=require("fs"),o=require("path"),a=require("./core-D2dlEt1l.cjs");class s{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 i{constructor(t=r.stdin,e=r.stdout){this._stdin=t,this._stdout=e,this._readBuffer=new s,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)})}}function c(t,e){if(t&&"direct-html-input"!==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"}return"page"}async function h(t,e,r,a,s){if(!e&&!r)return null;let i;if(e)i=o.resolve(e);else{if(!r)return null;{const t=c(a),e="html"===s?".html":".md";i=o.resolve(r,`${t}${e}`)}}return await n.promises.mkdir(o.dirname(i),{recursive:!0}),await n.promises.writeFile(i,t,"utf-8"),i}class l{constructor(){this.version=e.getPackageVersion(),this.server=new e.Server({name:"@aiquants/html-to-markdown",version:this.version,description:"A tool to dynamically fetch a web page from a given URL and convert it to Markdown."},{capabilities:{tools:{}}}),this.setupToolHandlers()}setupToolHandlers(){this.server.setRequestHandler(e.ListToolsRequestSchema,async()=>({tools:[{name:"html_to_markdown",description:"Convert HTML content from a URL or HTML string to Markdown format. Supports dynamic content loading and preserves table structures.",inputSchema:{type:"object",properties:{url:{type:"string",description:"The URL of the web page to convert to Markdown"},html_content:{type:"string",description:"HTML content as a string to convert to Markdown (alternative to URL)"},locale:{type:"string",description:"The locale to use for browser context (en-US or ja-JP)",enum:["en-US","ja-JP"],default:"en-US"},output_format:{type:"string",description:"Output format: 'markdown' (default), 'html', or 'both'",enum:["markdown","html","both"],default:"markdown"},save_path:{type:"string",description:"Full path (including filename) where to save the converted content. Cannot be used with save_directory."},save_directory:{type:"string",description:"Directory path where to save the converted content with auto-generated filename. Cannot be used with save_path."}},anyOf:[{required:["url"]},{required:["html_content"]}]}}]})),this.server.setRequestHandler(e.CallToolRequestSchema,async t=>{if("html_to_markdown"===t.params.name)return await this.handleHtmlToMarkdown(t.params.arguments);throw new Error(`Unknown tool: ${t.params.name}`)})}async handleHtmlToMarkdown(t){try{const e=function(t){if(!t||"object"!=typeof t)throw new Error("Arguments are required");const{url:e,html_content:r,locale:n="en-US",output_format:o="markdown",save_path:a,save_directory:s}=t;if(!e&&!r)throw new Error("Either 'url' or 'html_content' is required");if(e&&"string"!=typeof e)throw new Error("'url' must be a string");if(r&&"string"!=typeof r)throw new Error("'html_content' must be a string");if(n&&!["en-US","ja-JP"].includes(n))throw new Error("'locale' must be 'en-US' or 'ja-JP'");if(o&&!["markdown","html","both"].includes(o))throw new Error("'output_format' must be 'markdown', 'html', or 'both'");if(a&&"string"!=typeof a)throw new Error("'save_path' must be a string");if(s&&"string"!=typeof s)throw new Error("'save_directory' must be a string");if(a&&s)throw new Error("Cannot specify both 'save_path' and 'save_directory'");return{url:e,html_content:r,locale:n,output_format:o,save_path:a,save_directory:s}}(t),{url:r,html_content:n,locale:s="en-US",output_format:i="markdown",save_path:l,save_directory:d}=e;if(r)try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const u=await a.htmlToMarkdown(r||"direct-html-input",{locale:s,htmlContent:n}),m=[];if(l||d)switch(i){case"markdown":{const t=await h(u.markdown,l,d,r,"markdown");t&&m.push(t);break}case"html":{const t=await h(u.html,l,d,r,"html");t&&m.push(t);break}case"both":{const t=l?l.endsWith(".md")?l:`${l}.md`:d?o.join(d,`${c(r)}.md`):void 0;if(t){const e=await h(u.markdown,t,void 0,r,"markdown");e&&m.push(e)}const e=l?l.endsWith(".html")?l:`${l}.html`:d?o.join(d,`${c(r)}.html`):void 0;if(e){const t=await h(u.html,e,void 0,r,"html");t&&m.push(t)}break}}let f="";switch(i){case"markdown":f=u.markdown;break;case"html":f=u.html;break;case"both":f=`=== Markdown ===\n${u.markdown}\n\n=== HTML ===\n${u.html}`;break;default:throw new Error(`Invalid output format: ${i}`)}m.length>0&&(f+=`\n\n=== Files Saved ===\n${m.map(t=>`- ${t}`).join("\n")}`);return{content:[{type:"text",text:f}],isError:!1}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:String(e)}`}],isError:!0}}}async start(){const t=new i;await this.server.connect(t)}}const d=()=>new l;exports.createMcpServer=d,exports.runMcpServer=async()=>{const t=d();await t.start()};