Download the PHP package antonioprimera/md-parser without Composer

On this page you can find all versions of the php package antonioprimera/md-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package md-parser

Custom Markdown Parser

This is a highly customizable Markdown parser, that comes with a predefined Markdown flavor, but allows you to easily create any other Markdown flavor, whether it's a standard one or something you've just invented.

For example, you could create a Markdown flavor that allows you to embed images with an ID (of an object stored in the DB) or a slug, or maybe a custom tag that allows you to embed a hero-icon by its name. You can even decide that paragraphs should be separated by a | character instead of a newline.

Here are some examples of what you could easily do with this parser:

Basic Usage (framework-agnostic)

The main parser is a class that is instantiated with a set of inline parsers, a set of block parsers, optionally a block splitter and also an optional config. Once instantiated, you can call the parse method with a markdown string, and it will return the parsed result.

First, import the package via composer:

Then, you can use the default flavor, or create your own.

If you want to use the default flavor, you can do it like this:

If you want to create your own parser, or just change the behavior of the default parser, check the Advanced Usage section below.

Usage in a Laravel Project

If you are using this package in a Laravel project, everything is set up for you, so you can use the Md facade like this:

By default, the Service Provider for this package will use the configuration from the config/md-config.php file, to create the parser instance. If you want to change the configuration, you can publish the config file by running:

You have 2 main options to build your parser using the config:

  1. Provide a flavor.factory entry in the config file, containing the class of your factory, that will return a parser instance, and optionally a flavor.config entry, containing the configuration that will be passed to the factory.
  2. Provide the necessary building blocks for the parser: flavor.inlineParsers, flavor.blockParsers, flavor.splitter (this is optional) and flavor.config (this is also optional).

Advanced Usage

If you want to create your own flavor, you can do it by creating a factory class that returns an AntonioPrimera\Md\Parser instance, loaded with your custom block and inline parsers, or mix and match the existing ones.

Here is how the default flavor is created:

Block Parsers

A Block Parser is a class that inherits the AntonioPrimera\Md\BlockParser class. It has 2 methods: matches for checking whether the block is a match for this parser and should be processed by it, and parse for parsing the block. Once the block is matched and parsed by a Block Parser, the result will be added to the parsed result and its parsing will stop.

A simple Block Parser that would parse empty lines (blocks that contain only whitespace) would look like this:

Inline Parsers

An Inline Parser is a class that inherits the AntonioPrimera\Md\InlineParser class. It has a single parse method, that is used to find and replace inline elements in the given text. The parser first runs all the Inline Parsers on the text, and then splits the text into blocks and runs the Block Parsers on each block.

A simple Inline Parser that parses a hero-icon syntax like [heroicon:icon-name] would look like this:

Splitter

A Markdown Splitter is a class that extends the AntonioPrimera\Md\Splitters\MarkdownSplitter class. It has a single split method, that receives a markdown string and returns an array of blocks. The blocks are then parsed by the Block Parsers.

When instantiating the parser, you can pass a Splitter instance, if you rolled your own, or you can pass just a string that will be used as a delimiter for splitting the markdown string into blocks. By default, the Newline character \n is used.

Configuration

When instantiating a parser, you can pass a configuration to each inline parser and block parser instance, or you can just pass a single configuration array that will be partially forwarded to all the parsers, based on their aliases.

This can be done in order to keep the configuration in one place or to allow for dynamic configuration (e.g. based on some user input stored in the DB).

Each inline parser and block parser has an alias, which, by default is the kebab-case class base name without the parser suffix (e.g. HeroIconParser has an alias of hero-icon). You can override the alias method in the parser class if you want to use a different alias. Then you can pass the configuration for that parser by using the alias as a key in the configuration array.

Which is the same as passing the configuration directly to the parser instances:

Contributing

What still needs to be done:

If you want to contribute, feel free to fork the repository and submit a pull request. If you have any questions, feel free to ask.

Most of the specifications for the Markdown parser are based on the following resource:


All versions of md-parser with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
illuminate/support Version >=10
antonioprimera/php-helpers Version ^0.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package antonioprimera/md-parser contains the following files

Loading the files please wait ....