@aiquants/html-to-markdown 0.5.1 → 0.6.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.
@@ -13373,7 +13373,7 @@ const convert = (
13373
13373
  * @param {Test} [test]
13374
13374
  * @returns {Check}
13375
13375
  */
13376
- function(test) {
13376
+ (function(test) {
13377
13377
  if (test === null || test === void 0) {
13378
13378
  return ok;
13379
13379
  }
@@ -13381,13 +13381,20 @@ const convert = (
13381
13381
  return castFactory$1(test);
13382
13382
  }
13383
13383
  if (typeof test === "object") {
13384
- return Array.isArray(test) ? anyFactory$1(test) : propsFactory(test);
13384
+ return Array.isArray(test) ? anyFactory$1(test) : (
13385
+ // Cast because `ReadonlyArray` goes into the above but `isArray`
13386
+ // narrows to `Array`.
13387
+ propertiesFactory(
13388
+ /** @type {Props} */
13389
+ test
13390
+ )
13391
+ );
13385
13392
  }
13386
13393
  if (typeof test === "string") {
13387
13394
  return typeFactory(test);
13388
13395
  }
13389
13396
  throw new Error("Expected function, string, or object as test");
13390
- }
13397
+ })
13391
13398
  );
13392
13399
  function anyFactory$1(tests) {
13393
13400
  const checks2 = [];
@@ -13404,7 +13411,7 @@ function anyFactory$1(tests) {
13404
13411
  return false;
13405
13412
  }
13406
13413
  }
13407
- function propsFactory(check) {
13414
+ function propertiesFactory(check) {
13408
13415
  const checkAsRecord = (
13409
13416
  /** @type {Record<string, unknown>} */
13410
13417
  check
@@ -13851,10 +13858,10 @@ const isElement = (
13851
13858
  * @returns {boolean}
13852
13859
  */
13853
13860
  // eslint-disable-next-line max-params
13854
- function(element2, test, index2, parent, context) {
13861
+ (function(element2, test, index2, parent, context) {
13855
13862
  const check = convertElement(test);
13856
13863
  return looksLikeAnElement(element2) ? check.call(context, element2, index2, parent) : false;
13857
- }
13864
+ })
13858
13865
  );
13859
13866
  const convertElement = (
13860
13867
  // Note: overloads in JSDoc can’t yet use different `@template`s.
@@ -13870,7 +13877,7 @@ const convertElement = (
13870
13877
  * @param {Test | null | undefined} [test]
13871
13878
  * @returns {Check}
13872
13879
  */
13873
- function(test) {
13880
+ (function(test) {
13874
13881
  if (test === null || test === void 0) {
13875
13882
  return element$1;
13876
13883
  }
@@ -13884,7 +13891,7 @@ const convertElement = (
13884
13891
  return castFactory(test);
13885
13892
  }
13886
13893
  throw new Error("Expected function, string, or array as `test`");
13887
- }
13894
+ })
13888
13895
  );
13889
13896
  function anyFactory(tests) {
13890
13897
  const checks2 = [];
@@ -14293,7 +14300,7 @@ const findAfter = (
14293
14300
  * @param {Test} [test]
14294
14301
  * @returns {UnistNode | undefined}
14295
14302
  */
14296
- function(parent, index2, test) {
14303
+ (function(parent, index2, test) {
14297
14304
  const is = convert(test);
14298
14305
  if (!parent || !parent.type || !parent.children) {
14299
14306
  throw new Error("Expected parent node");
@@ -14314,7 +14321,7 @@ const findAfter = (
14314
14321
  }
14315
14322
  }
14316
14323
  return void 0;
14317
- }
14324
+ })
14318
14325
  );
14319
14326
  const searchLineFeeds = /\n/g;
14320
14327
  const searchTabOrSpaces = /[\t ]+/g;
@@ -19723,7 +19730,7 @@ const CallableInstance = (
19723
19730
  * @param {string | symbol} property
19724
19731
  * @returns {(...parameters: Array<unknown>) => unknown}
19725
19732
  */
19726
- function(property) {
19733
+ (function(property) {
19727
19734
  const self2 = this;
19728
19735
  const constr = self2.constructor;
19729
19736
  const proto2 = (
@@ -19738,7 +19745,7 @@ const CallableInstance = (
19738
19745
  };
19739
19746
  Object.setPrototypeOf(apply, proto2);
19740
19747
  return apply;
19741
- }
19748
+ })
19742
19749
  );
19743
19750
  const own = {}.hasOwnProperty;
19744
19751
  class Processor extends CallableInstance {
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--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;
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-jjdOcY1v.cjs"),c=require("./mcp-server-streamable-DU6yq8ZG.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-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";
8
+ import { g, h } from "./core-txi0EJ9v.js";
9
+ import { c, r } from "./mcp-server-B8T7ljWL.js";
10
+ import { c as c2, r as r2 } from "./mcp-server-streamable-Bv5fFO_D.js";
11
11
  export {
12
12
  c as createMcpServer,
13
13
  c2 as createStreamableMcpServer,
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-DhxxOcPm.js";
9
+ import { g as getMessage, h as htmlToMarkdown } from "./core-txi0EJ9v.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-BNwQMbri.js";
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-DrEUqsN7.js";
9
9
  import process from "node:process";
10
- import { h as htmlToMarkdown } from "./core-DhxxOcPm.js";
10
+ import { h as htmlToMarkdown } from "./core-txi0EJ9v.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-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()};
1
+ const e=new(require("happy-dom").Window);Object.assign(global,{document:e.document,window:e,self:e});const t=require("./version-Jbxn3hLf.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()};