picas / markdown-extended
Yet another PHP parser for the markdown (*extended*) syntax
Requires
- php: >=5.6
Requires (Dev)
- friendsofphp/php-cs-fixer: @stable
- phploc/phploc: @stable
- phpmd/phpmd: @stable
- phpmetrics/phpmetrics: @stable
- phpunit/phpunit: <10
- sebastian/phpcpd: @stable
- symfony/finder: <6
Replaces
- atelierspierrot/extended-markdown: dev-master
- atelierspierrot/markdown-extended: dev-master
- piwi/markdown-extended: v1.0.0-rc.12
- dev-master / 1.0.x-dev
- v1.0.0-rc.12
- v1.0.0-rc.11
- v1.0.0-rc.10
- v1.0.0-rc.9
- v1.0.0-rc.8
- v1.0.0-rc.7
- v1.0.0-rc.6
- v1.0.0-rc.5
- v1.0.0-rc.4
- v1.0.0-rc.3
- v1.0.0-rc.2
- v1.0.0-rc.1
- v0.1.0-beta
- v0.1.0-alpha
- dev-develop
- dev-fix-content-collection
- dev-tests-review
- dev-feat-html-tag-classes
- dev-fix-title-extraction
- dev-old-develop-php7
- dev-master-php5
- dev-feature-menu
- dev-0.1-gamma5
This package is auto-updated.
Last update: 2024-10-31 00:28:26 UTC
README
Yet another PHP parser for the markdown (extended) syntax.
PHP Markdown Extended is a PHP parser to transform Markdown text files or strings in HTML or other formats. This new version of a Markdown parser tries to follow the extended syntax specifications and is PHP-5.3 compliant and highly customizable.
You can use this package in PHP scripts just as usual (for PHP apps) and also like a standalone command line utility. The CLI interface is interactive with a large set of options and fully documented.
README contents:
Installation
You can use this package in your work in many ways. Please note that it requires a running PHP version of 5.3.3 minimum.
Raw PHP package
First, you can clone the GitHub repository and include it "as is" in your project:
$ git clone https://github.com/e-picas/markdown-extended.git
You can also download an archive from GitHub:
$ wget --no-check-certificate https://github.com/e-picas/markdown-extended/archive/master.tar.gz $ tar -xvf master.tar.gz
Then, to use the package classes, you just need to include its bootstrapper which will register its namespaces in current runtime environment:
require_once 'path/to/package/src/bootstrap.php';
Using Composer
Another way to use the package, if you are a Composer user,
is to add it to your requirements in your composer.json
file:
"picas/markdown-extended": "dev-master"
The namespace will be automatically added to the project's Composer's autoloader.
Using a standalone version
Finally, if you plan to use the parser as a single binary, you can use a
PHAR archive directly, which embeds
the whole source as a standalone binary (~220Kb). Its usage is the same as the
bin/markdown-extended
script described below.
The archive is stored in a specific phar-latest
branch on the repository:
$ wget --no-check-certificate https://github.com/e-picas/markdown-extended/archive/phar-latest.tar.gz
$ tar -xvf phar-latest.tar.gz
$ cd phar-latest
Locally
If you only need the archive for a local project, you can copy it where you want:
$ cp bin/markdown-extended.phar your/project/path/ $ php your/project/path/markdown-extended.phar ...
Personally
To install the binary in your user's binaries:
$ ./install.sh ~/bin false
Globally
For a complete global install, run:
$ sudo ./install.sh /usr/local
Usage
An HTML demonstration and the code documentation are available on the "dev" branch.
Usage for writers
To be compliant with the extended Markdown syntax, writers may construct their contents following the rules described at http://cheatsheet.aboutmde.org/ (all basic markdown rules are still available and valid).
For a full example and a test file, you can refer to the demo/MD_syntax.md
file of the package ;
the latest version can be found at http://github.com/e-picas/markdown-extended/blob/dev/demo/MD_syntax.md.
Usage for developers
The source code documentation of the last stable release can also be found online at http://docs.ateliers-pierrot.fr/markdown-extended/.
The MarkdownExtended
package can be simply call writing:
use \MarkdownExtended\MarkdownExtended; // load the namespace $options = array( /* ... */ ); // parser options, see documentation // parse a string or a file content $content = MarkdownExtended::parse( "my markdown string" OR 'my-markdown-file.md' , $options ); // parse a string $content = MarkdownExtended::parseString( "my markdown string" , $options ); // parse a file content $content = MarkdownExtended::parseSource( 'my-markdown-file.md' , $options );
This will load in $content
the parsed version of your original Markdown
source (file content or string).
The returned $content
variable is actually a \MarkdownExtended\API\ContentInterface
object but you can write it directly using:
echo $content; // shortcut for $content->getContent()
To get the part you need from the content, write:
$content ->getContent() // the full content ->getCharset() // a guessed character set ->getTitle() // the guessed title ->getBody() // the body ->getMetadata() // the metadata as array ->getNotes() // the notes as array ;
You can also use the \MarkdownExtended\Parser
object as a procedural non-static
object (this is in fact what the static methods above really do):
// create an instance with custom options $parser = new \MarkdownExtended\Parser( $options ); // parse a string $content = $parser->transform( "my markdown string" ); // parse a file content $content = $parser->transformSource( 'my-markdown-file.md' );
A more complete usage documentation is available in the package's documents
(doc/DOCUMENTATION.md
). You can read it online at
https://github.com/e-picas/markdown-extended/blob/master/doc/DOCUMENTATION.md.
Its manpage version is embedded in the package running:
$ man ./man/markdown-extended.7.man
Command line usage
A command line interface is proposed with the package running:
$ ./bin/markdown-extended --help
The interface allows to parse one or more files, extract some information from sources, write the results in files and some other stuff. A large set of options are available to customize the transformation.
A complete manpage is available in the package's man/
directory and its markdown source is
available in its documents (doc/MANPAGE.md
). To read it, run:
$ man ./man/markdown-extended.3.man
The developer documentation is also available as a manpage running:
$ man ./man/markdown-extended.7.man
Examples of cli usage:
# transform a simple string $ ./bin/markdown-extended "my **markdown** _extended_ string" my <strong>markdown</strong> <em>extended</em> string # transform a file content with output to STDOUT $ ./bin/markdown-extended my-markdown-file.md ... # transform a file content with output in file $ ./bin/markdown-extended --output=my-transformed-markdown.html my-markdown-file.md ... # generate the manpage itslef $ ./bin/markdown-extended -f man -o man/markdown-extended.man doc/MANPAGE.md ...
Old parsers compatibility
To keep the package compatible with old versions of Markdown, an interface is embedded
with the common Markdown($content)
function ; to use it, just include the file
src/markdown.php
of the package:
require_once 'path/to/src/markdown.php'; // to get result of a string parsing: echo Markdown($string [, $options]); // to get result of a file content parsing: echo MarkdownFromSource($file_name [, $options]);
This way, you may be able to change your Markdown parser without so much work and, I hope so, a better result ;)
Open-Source & Community
This parser is a free software, available under BSD license ; you can freely use it, for yourself or a commercial use, modify its source code according to your needs, freely distribute your work and propose it to the community, as long as you let an information about its first authors.
As the sources are hosted on a GIT repository on
GitHub, you can modify it, to
ameliorate a feature or correct an error. Please read the CONTRIBUTING.md
file of the package
for more info.
License
This software, as the original Markdown, is licensed under the terms of the
BSD-3-Clause license.
Please see the LICENSE
file for a full text.
You can use, transform and distribute this software and its dependencies as you wish, as long as you mention the copyrights below:
Markdown
Copyright (c) 2003-2006 John Gruber
<http://daringfireball.net/>
All rights reserved.
PHP Markdown & Extra
Copyright (c) 2004-2009 Michel Fortin
<http://michelf.com/>
All rights reserved.
Multi Markdown
Copyright (c) 2005-2009 Fletcher T. Penney
<http://fletcherpenney.net/>
All rights reserved.
PHP Markdown Extended
Copyright (c) 2008-2024 Pierre Cassat & contributors
<http://picas.fr/>
All rights reserved.