innobrain/markitdown

Laravel bindings for markitdown.

v3.0.0 2024-12-22 14:58 UTC

This package is auto-updated.

Last update: 2024-12-22 14:59:14 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel bindings for markitdown.

Installation

  1. Install the package via composer:
composer require innobrain/markitdown
  1. Publish the configuration file:
php artisan vendor:publish --tag="markitdown-config"
  1. Run the installation command if you want the package to manage your markitdown installation:
php artisan markitdown:install

This will:

  • Set up a Python virtual environment with the required dependencies
  • Add the setup script to your project's composer.json
  • Ensure the environment is kept up to date with future composer updates

Alternative Installation Methods

If you prefer not to use the built-in virtual environment, you can disable it in your .env file or in the config:

MARKITDOWN_USE_VENV_PACKAGE=false

Then install markitdown manually using one of these methods:

Using pip directly:

pip install markitdown

Using pipx (Recommended for manual installation):

On macOS:

brew install pipx
pipx ensurepath
sudo pipx ensurepath --global # optional to allow pipx actions with --global argument

Or see how to install on other platforms. After installing pipx, you can install markitdown with:

pipx install markitdown

When not using the built-in virtual environment, you'll need to set the path to the markitdown executable in your .env file. You can retrieve the path with:

which markitdown
MARKITDOWN_EXECUTABLE=/path/to/markitdown

Also, when running the script anywhere but the console, you need to set the PATH, as php-fpm does not have access to the PATH variable. You can do this by adding the following to your .env file:

MARKITDOWN_SYSTEM_PATH=<your path>

Configuration

The package's configuration will be published to config/markitdown.php. Here are the available options:

return [
    /*
     * Use this to set the timeout for the process. Default is 30 seconds.
     */
    'process_timeout' => env('MARKITDOWN_PROCESS_TIMEOUT', 30),

    /*
     * Use this to set the path to the markitdown executable. If not set,
     * the binary will be searched in the PATH. Will be ignored
     * if use_venv_package is set to true.
     */
    'executable' => env('MARKITDOWN_EXECUTABLE', 'markitdown'),

    /*
     * This will override the above setting and use the new locally installed package.
     */
    'use_venv_package' => env('MARKITDOWN_USE_VENV_PACKAGE', true),

    /*
     * This is needed when you want to run markitdown in php-fpm. One dependency
     * of markitdown requires PATH to be set. If you are running in a console,
     * this is not needed.
     */
    'system' => [
        'path' => env('MARKITDOWN_SYSTEM_PATH', ''),
    ],

    /*
     * The path where temporary files will be stored. This directory must be writable
     * by the web server. Defaults to storage/app/private/markitdown_tmp
     */
    'temporary_directory' => env('MARKITDOWN_TEMPORARY_DIRECTORY', storage_path('app/private/markitdown_tmp')),
];

Usage

// convert a file:
$markdown = \Innobrain\Markitdown\Facades\Markitdown::convert('/path/to/file.docx');

// or convert a file you already have in memory:
$file = file_get_contents('/path/to/file.docx');
$markdown = \Innobrain\Markitdown\Facades\Markitdown::convertFile($file, '.docx');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.