ExAnydoc (ExAnydoc v0.1.0)

Copy Markdown View Source

Converts office documents into GitHub-Flavored Markdown using Firecrawl's anydoc Rust library.

All conversion happens locally. Formats with a content signature are detected automatically; CSV bytes must be passed with the explicit :csv format.

Examples

{:ok, markdown} = ExAnydoc.to_markdown("report.docx")

bytes = File.read!("report.docx")
{:ok, markdown} = ExAnydoc.to_markdown_bytes(bytes)

Functions return {:ok, result} or an error map suitable for pattern matching. Invalid argument types are rejected at the function or NIF boundary.

Summary

Functions

Detects a format from document content, returning nil when unknown.

Returns the format represented by an extension, with or without a leading dot.

Returns the format represented by a path's extension.

Parses bytes into anydoc's information-preserving document model.

Converts the document at path to GitHub-Flavored Markdown.

Converts document bytes to Markdown.

Types

error()

@type error() :: %{code: error_code(), message: String.t()}

error_code()

@type error_code() ::
  :unsupported
  | :malformed
  | :encrypted
  | :resource_limit
  | :missing_part
  | :io_error

format()

@type format() ::
  :doc
  | :docx
  | :odt
  | :pdf
  | :ppt
  | :pptx
  | :rtf
  | :epub
  | :excel
  | :ods
  | :odp
  | :csv

result(value)

@type result(value) :: {:ok, value} | {:error, error()}

Functions

format_from_bytes(bytes)

@spec format_from_bytes(binary()) :: format() | nil

Detects a format from document content, returning nil when unknown.

format_from_extension(extension)

@spec format_from_extension(String.t()) :: format() | nil

Returns the format represented by an extension, with or without a leading dot.

format_from_path(path)

@spec format_from_path(Path.t()) :: format() | nil

Returns the format represented by a path's extension.

to_document(bytes, format \\ nil)

@spec to_document(binary(), format() | nil) :: result(ExAnydoc.Document.t())

Parses bytes into anydoc's information-preserving document model.

PDF does not have a document-model representation; use to_markdown_bytes/2.

Embedded assets are returned in ExAnydoc.Document.assets and may contain large binaries.

to_markdown(path)

@spec to_markdown(Path.t()) :: result(String.t())

Converts the document at path to GitHub-Flavored Markdown.

The format is inferred from the path and document contents.

to_markdown_bytes(bytes, format \\ nil)

@spec to_markdown_bytes(binary(), format() | nil) :: result(String.t())

Converts document bytes to Markdown.

The optional format overrides content detection. It is required for CSV.

Pass an explicit format when the bytes have no reliable signature or when detection is not desired:

ExAnydoc.to_markdown_bytes("name,score

Ada,10 ", :csv)