Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 148 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ csv = "1.4.0"
flate2 = "1"
encoding_rs = "0.8.35"
log = "0.4"
office-crypto = "0.3.0"
pdf-inspector = "1.14.2"
quick-xml = "0.41.0"
zip = { version = "8.6.0", default-features = false, features = ["deflate"] }
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ markdown = anydoc.to_markdown_bytes(data)
# Or name it, which signature-less formats (CSV) need:
markdown = anydoc.to_markdown_bytes(data, "csv")

# Password-protected OOXML
markdown = anydoc.to_markdown_bytes(data, password="secret")

# Or stop at the document model, which also carries embedded assets:
document = anydoc.to_document(data)
```
Expand Down Expand Up @@ -121,6 +124,9 @@ let markdown = anydoc::to_markdown_bytes(&bytes, None)?;
// Or name it, which signature-less formats (CSV) need:
let markdown = anydoc::to_markdown_bytes(&bytes, anydoc::Format::Csv)?;

// Password-protected OOXML
let markdown = anydoc::to_markdown_bytes_with_password(&bytes, None, "secret")?;

// Or stop at the document model, which also carries embedded assets:
let document = anydoc::to_document(&bytes, None)?;
```
Expand Down
4 changes: 4 additions & 0 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ The package ships an `anydoc` command, so `npx` converts a document with no inst
npx @firecrawl/anydoc report.docx # Markdown to stdout
npx @firecrawl/anydoc slides.pptx -o slides.md # or to a file
npx @firecrawl/anydoc - --format csv < data.csv # read stdin
npx @firecrawl/anydoc report.docx --password secret
```

Set `ANYDOC_PASSWORD` instead of using `--password` when the password should
not appear in shell history or the process list.

Markdown goes to stdout, errors to stderr, and `anydoc --help` covers the rest.

## Usage
Expand Down
16 changes: 11 additions & 5 deletions node/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ Usage:

Converts one document per invocation and writes the Markdown to stdout.
Pass - as the input to read the document from stdin. Never prompts; all
diagnostics go to stderr.
diagnostics go to stderr. ANYDOC_PASSWORD is used when --password is omitted.

Options:
-o, --output <path> Write the Markdown to <path> instead of stdout
-f, --format <format> Name the input format instead of detecting it:
${FORMATS}
(extension aliases like xls, docm, ppsx resolve
to these)
-p, --password <value> Decrypt a password-protected OOXML document
-h, --help Print this help and exit
-V, --version Print the version and exit

Expand Down Expand Up @@ -50,7 +51,7 @@ function fail(code, message) {
}

function parseArgs(argv) {
const args = { input: null, output: null, format: null }
const args = { input: null, output: null, format: null, password: null }
let positionalOnly = false
for (let i = 0; i < argv.length; i++) {
let arg = argv[i]
Expand Down Expand Up @@ -95,6 +96,10 @@ function parseArgs(argv) {
case '--format':
args.format = value()
break
case '-p':
case '--password':
args.password = value()
break
default:
fail(USAGE_ERROR, `unknown option '${arg}' (see anydoc --help)`)
}
Expand Down Expand Up @@ -133,12 +138,13 @@ async function main() {

let markdown
try {
const password = args.password ?? process.env.ANYDOC_PASSWORD
if (args.input === '-') {
markdown = await toMarkdownBytes(await readStdin(), format)
markdown = await toMarkdownBytes(await readStdin(), format, password)
} else if (format !== undefined) {
markdown = await toMarkdownBytes(await readFile(args.input), format)
markdown = await toMarkdownBytes(await readFile(args.input), format, password)
} else {
markdown = await toMarkdown(args.input)
markdown = await toMarkdown(args.input, password)
}
} catch (error) {
fail(CONVERSION_ERROR, error.message)
Expand Down
6 changes: 3 additions & 3 deletions node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export declare const enum TableKind {
*
* Rejects with an `Error` carrying a `ConvertErrorCode` on `code`.
*/
export declare function toDocument(bytes: Uint8Array, format?: Format | undefined | null): Promise<Document>
export declare function toDocument(bytes: Uint8Array, format?: Format | undefined | null, password?: string | undefined | null): Promise<Document>

/**
* Convert a document file to Markdown. The format is detected from the file
Expand All @@ -281,7 +281,7 @@ export declare function toDocument(bytes: Uint8Array, format?: Format | undefine
* Rejects with an `Error` carrying a `ConvertErrorCode` on `code`; a file
* that cannot be read is `'io'`.
*/
export declare function toMarkdown(path: string): Promise<string>
export declare function toMarkdown(path: string, password?: string | undefined | null): Promise<string>

/**
* Convert an in-memory document to Markdown. Without a format, it is
Expand All @@ -290,4 +290,4 @@ export declare function toMarkdown(path: string): Promise<string>
*
* Rejects with an `Error` carrying a `ConvertErrorCode` on `code`.
*/
export declare function toMarkdownBytes(bytes: Uint8Array, format?: Format | undefined | null): Promise<string>
export declare function toMarkdownBytes(bytes: Uint8Array, format?: Format | undefined | null, password?: string | undefined | null): Promise<string>
Loading