Coder Social home page Coder Social logo

yivi / commonmarkbundle Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 131 KB

A Symfony 5 bundle to integrate league/commonmark v2, allowing you to set multiple Commonmark converters with different configuration.

License: MIT License

PHP 100.00%
php symfony symfony-bundle symfony-5

commonmarkbundle's Introduction

CommonMarkBundle

A Symfony 5+ bundle to integrate league/commonmark v2, allowing you to set multiple Commonmark converters.

PHP Version Require Latest Stable Version Total Downloads Latest Unstable Version License Tests

Requirements

This bundle requires PHP 8+ and Symfony 5+.

Installation

composer require yivoff/commonmark-bundle

If for some reason you are running without Symfony Flex, enable the bundle as usual adding Yivoff\CommonmarkBundle\YivoffCommonmarkBundle to the bundle's array.

Configuration

You'll need to enable at least one converter to use the bundle. Create a YAML configuration file at path config/packages/aymdev_commonmark.yaml. Here is an example configuration declaring 2 converters:

yivoff_commonmark:
   converters:
      commonmark:
         options:
            commonmark:
               enable_em: false

      github:
         type: github
         
      my_custom:
         type: custom
            extensions:
               - League\CommonMark\Extension\Autolink\AutolinkExtension
               - League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension

Setting up at least one converter is mandatory, but all settings are optional. By default, a converter without setting a type will be created as a CommonMark converter.

Converter type

The type key can be used to choose between a CommonMark, a GitHub Flavoured or a Custom converter.

By default, if not type is chosen, CommonMark will be chosen.

Converter options

You can use the options key holds the configuration passed to the converter, as an array.

Check the CommonMark documentation to learn more about the available options.

Converter extensions

The CommonMark and Github Flavoured have a predefined set of extensions installed, which cannot be changed.

But custom starts with no extensions, and you pick and choose which extensions you want to enable using the extensions key.

This key has no effect on github or commonmark type converters.

Using the converters

As services

Each of the defined converters is available as a service within the container.

The id is generated with the following format: yivoff_commonmark.converters.converter_name.

For the converters in the configuration example three services would be generated:

  • yivoff_commonmark.converters.commonmark
  • yivoff_commonmark.converters.github
  • yivoff_commonmark.converters.my_custom

Additionally, the bundle registers an alias for each service, so one can use the service directly for autowiring.

Again, for the above example the registered aliases would be:

  • League\CommonMark\ConverterInterface $commonmark
  • League\CommonMark\ConverterInterface $github
  • League\CommonMark\ConverterInterface $myCustom

Usage in templates

The bundle defines a Twig filter: commonmark.

If you have defined multiple converters, you need to pass the name of the converter you want to use:

{{ some_markdown_content|commonmark('github') }}

But If you have only one converter defined, the parameter can be omitted.

{{ some_markdown_content|commonmark }}

commonmarkbundle's People

Contributors

yivi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.