markitdown-ts 0.0.4 → 0.0.6

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 CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  [![CI](https://github.com/dead8309/markitdown-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/dead8309/markitdown/actions/workflows/ci.yml)
4
4
 
5
- `markitdown-ts` is a TypeScript library designed for converting various file formats to Markdown. This makes it suitable for indexing, text analysis, and other applications that benefit from structured text. It is a TypeScript implementation of the original `markitdown` [Python library.](https://github.com/microsoft/markitdown)
5
+ `markitdown-ts` is a TypeScript library designed for converting various file formats to Markdown. It can process fiiles from local paths, URLs, or directly from in-memory buffers, making it ideal for serverless and edge environments like Supabase Functions or Cloudflare Workers.
6
+
7
+ It is a TypeScript implementation of the original `markitdown` [Python library.](https://github.com/microsoft/markitdown) and is suitable for indexing, text analysis, and other applications that benefit from structured text.
6
8
 
7
9
  It supports:
8
10
 
@@ -32,12 +34,21 @@ pnpm add markitdown-ts
32
34
 
33
35
  ## Usage
34
36
 
37
+ ### Basic Usage (from a File Path)
38
+
39
+ The simplest way to use the library is by providing a local file path or a URL.
40
+
35
41
  ```typescript
36
42
  import { MarkItDown } from "markitdown-ts";
37
43
 
38
44
  const markitdown = new MarkItDown();
39
45
  try {
46
+ // Convert a local file
40
47
  const result = await markitdown.convert("path/to/your/file.pdf");
48
+
49
+ // Or convert from a URL
50
+ const result = await markitdown.convert("https://arxiv.org/pdf/2308.08155v2.pdf");
51
+
41
52
  if (result) {
42
53
  console.log(result.text_content);
43
54
  }
@@ -46,7 +57,57 @@ try {
46
57
  }
47
58
  ```
48
59
 
49
- Pass additional options as needed for specific functionality.
60
+ ### Advanced Usage (from Buffers, Blobs, or Responses)
61
+
62
+ For use in serverless environments where you can't rely on a persistent filesystem, you can convert data directly from memory.
63
+
64
+ > [!IMPORTANT]
65
+ >
66
+ > This is the recommended approach for environments like **Supabase Edge Functions**, **Cloudflare Workers**, or **AWS Lambda**.
67
+
68
+ #### From a Buffer
69
+
70
+ If you have your file content in a `Buffer`, use the `convertBuffer` method. You **must** provide the `file_extension` in the options so the library knows which converter to use.
71
+
72
+ ```typescript
73
+ import { MarkItDown } from "markitdown-ts";
74
+ import * as fs from "fs";
75
+
76
+ const markitdown = new MarkItDown();
77
+ try {
78
+ const buffer = fs.readFileSync("path/to/your/file.docx");
79
+ const result = await markitdown.convertBuffer(buffer, {
80
+ file_extension: ".docx"
81
+ });
82
+ console.log(result?.text_content);
83
+ } catch (error) {
84
+ console.error("Conversion failed:", error);
85
+ }
86
+ ```
87
+
88
+ #### From a Response or Blob
89
+
90
+ You can pass a standard `Response` object directly to the `convert` method. This is perfect for handling file uploads from a request body.
91
+
92
+ ```typescript
93
+ import { MarkItDown } from "markitdown-ts";
94
+
95
+ const markitdown = new MarkItDown();
96
+
97
+ // Example: Simulating a file upload by creating a Blob and a Response
98
+ const buffer = fs.readFileSync("path/to/archive.zip");
99
+ const blob = new Blob([buffer]);
100
+ const response = new Response(blob, {
101
+ headers: { "Content-Type": "application/zip" }
102
+ });
103
+
104
+ try {
105
+ const result = await markitdown.convert(response);
106
+ console.log(result?.text_content);
107
+ } catch (error) {
108
+ console.error("Conversion failed:", error);
109
+ }
110
+ ```
50
111
 
51
112
  ## YouTube Transcript Support
52
113
 
@@ -76,11 +137,22 @@ const result = await markitdown.convert("test.jpg", {
76
137
 
77
138
  ## API
78
139
 
79
- The library uses a single function `convert` for all conversions, with the options and the response type defined as such:
140
+ The library exposes a `MarkItDown` class with two primary conversion methods.
80
141
 
81
142
  ```typescript
82
- export interface DocumentConverter {
83
- convert(local_path: string, options: ConverterOptions): Promise<ConverterResult>;
143
+ class MarkItDown {
144
+ /**
145
+ * Converts a source from a file path, URL, or Response object.
146
+ */
147
+ async convert(source: string | Response, options?: ConverterOptions): Promise<ConverterResult>;
148
+
149
+ /**
150
+ * Converts a source from an in-memory Buffer.
151
+ */
152
+ async convertBuffer(
153
+ source: Buffer,
154
+ options: ConverterOptions & { file_extension: string }
155
+ ): Promise<ConverterResult>;
84
156
  }
85
157
 
86
158
  export type ConverterResult =
@@ -92,16 +164,28 @@ export type ConverterResult =
92
164
  | undefined;
93
165
 
94
166
  export type ConverterOption = {
167
+ // Required when using convertBuffer
95
168
  file_extension?: string;
169
+
170
+ // For URL-based converters (e.g., Wikipedia, Bing SERP)
96
171
  url?: string;
172
+
173
+ // Provide a custom fetch implementation
97
174
  fetch?: typeof fetch;
98
- enableYoutubeTranscript?: boolean; // false by default
99
- youtubeTranscriptLanguage?: string; // "en" by default
100
- llmModel: string;
175
+
176
+ // YouTube-specific options
177
+ enableYoutubeTranscript?: boolean; // Default: false
178
+ youtubeTranscriptLanguage?: string; // Default: "en"
179
+
180
+ // Image-specific LLM options
181
+ llmModel?: LanguageModel;
101
182
  llmPrompt?: string;
183
+
184
+ // Options for .docx conversion (passed to mammoth.js)
102
185
  styleMap?: string | Array<string>;
103
- _parent_converters?: DocumentConverter[];
104
- cleanup_extracted?: boolean;
186
+
187
+ // Options for .zip conversion
188
+ cleanupExtracted?: boolean; // Default: true
105
189
  };
106
190
  ```
107
191