Code Monkey home page Code Monkey logo

pandoc's Introduction

Pandoc PHP Package

Integrate Sponsor

If you need to convert text files from one format to another, pandoc is your swiss-army knife. This package is a PHP wrapper for pandoc.

Installation

You can install the package via composer:

composer require ueberdosis/pandoc

This package is a wrapper for the command-line tool pandoc. Don’t forget to install pandoc. Here is an example for Ubuntu:

sudo apt-get update
sudo apt-get install -y wget
sudo mkdir -p /usr/src/pandoc
cd /usr/src/pandoc
sudo wget https://github.com/jgm/pandoc/releases/download/2.15/pandoc-2.15-1-amd64.deb
sudo dpkg -i pandoc-2.15-1-amd64.deb

More examples are available in the pandoc documentation

Usage

Return the converted text as string

$output = (new \Pandoc\Pandoc)
    ->from('markdown')
    ->input('# Test')
    ->to('html')
    ->run();

Use a file as input and write a file as output

(new \Pandoc\Pandoc)
    ->from('markdown')
    ->inputFile('tests/data/example.md')
    ->to('plain')
    ->output('tests/temp/example.txt')
    ->run();

Change path to Pandoc

new \Pandoc\Pandoc([
    'command' => '/usr/local/bin/pandoc',
]);

Change working directory

(new \Pandoc\Pandoc)->cwd('/tmp/pandoc/');

List available input formats

(new \Pandoc\Pandoc)->listInputFormats();

List available output formats

(new \Pandoc\Pandoc)->listOutputFormats();

Write a log file

echo (new \Pandoc\Pandoc)
    ->from('markdown')
    ->input('# Markdown')
    ->to('html')
    ->log('log.txt')
    ->run();

Retrieve Pandoc version

echo (new \Pandoc\Pandoc)->version();

Use magic methods to make calls shorter

$output = (new \Pandoc\Pandoc)
    ->fromMarkdown('# Test')
    ->toHtml('tests/temp/example.txt')
    ->run();

Pass options to Pandoc

echo (new \Pandoc\Pandoc)
    ->fromMarkdown('# Test')
    ->toHtml('tests/temp/example.txt')
    ->option('fail-if-warnings')
    ->option('data-dir', './tmp')
    ->run();

See https://pandoc.org/MANUAL.html for a full list of available options

Laravel Facade

This package includes a Laravel facade for people that like that little bit of syntactic sugar.

echo \Pandoc\Facades\Pandoc::version();

Exceptions

If something went wrong, the package throws a generic \Symfony\Component\Process\Exception\ProcessFailedException. There are even a few specific exceptions.

  • \Pandoc\Exceptions\PandocNotFound
  • \Pandoc\Exceptions\InputFileNotFound
  • \Pandoc\Exceptions\UnknownInputFormat
  • \Pandoc\Exceptions\UnknownOutputFormat
  • \Pandoc\Exceptions\LogFileNotWriteable
  • \Pandoc\Exceptions\BadMethodCall

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

pandoc's People

Contributors

cheryllium avatar dependabot[bot] avatar hanspagel avatar m1guelpf avatar mejo- avatar patrickbaber avatar peter279k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pandoc's Issues

"standalone" should not be forced

On line 200 of pandoc/src/Pandoc.php the standalone parameter has been forced, while I think this should not be the case.

This is problematic when converting strings to HTML because it returns a complete HTML file with headers and footers. The "standalone" parameter can already be used by $this->option('standalone').

Allow options to be passed

Great wrapper, supper helpful, thanks.

Some food for thought, it would be helpful to be able to pass the many Pandoc options along on execution (https://pandoc.org/MANUAL.html).

For example, --standalone, --columns, --toc-depth, the list goes on:

->options('standalone, columns=2, toc-depth=3')

Error generating PDF: lstat(./pdflatex) failed

I got this error when running from the application, but if I run the exact command in the bash, I get the PDF:

lstat(./pdflatex) failed: ./pdflatex: No such file or directory kpathsea: Can't get directory of program name: ./pdflatex

Any ideas why is this happening?

  • Ubuntu 20.04
  • PHP 8.0
  • Using Laravel with Laravel Forge in Linode
  • pandoc --version outputs pandoc 2.17.0.1 (and more)
  • pdflatex--version outputs pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) (and more)

Priblem with passing multuple options of the same type

Hello,
i like the wrapper a lot, but I've stumbled on an issue, which is crucial for my implementation, and it looks like a bug.
When I pass multiple options of the same type, which are supported by pandoc ( you can pass multiple --metadata or --variable options), the wrapper passes on only the first one ... for example in

echo (new \Pandoc\Pandoc) ->from('markdown_mmd') ->inputFile(mmd_file($id)) ->option('standalone') ->option('self-contained') ->option('template',$okvir) ->option('css',$css) ->option('metadata-file', $yaml_file) ->option('metadata','x=y') ->option('metadata', 'n_izv_text='.$nizi['original']) ->to('html5') ->log($log_file) ->run();
I can access variable x in the template, but the n_izv_text or any other metadata does not get passed to template?
Any ideas on why is that?
Thank you in advance,
Regards, Om

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.