Giter Club home page Giter Club logo

Comments (5)

GrahamCampbell avatar GrahamCampbell commented on August 17, 2024 1

Thanks so much @colinodell. Massively appreciate your continual jumping into these issues and helping out. :)

from laravel-markdown.

ArneAnka avatar ArneAnka commented on August 17, 2024 1

Thanks @colinodell

If anyone is looking to do the same, this is what I did:

  1. Create an Extensions folder under App
  2. Create file called AddListStyleClassesExtension.php under the newly created folder App/Extensions
  3. Populate AddListStyleClassesExtension.php with:
<?php

namespace App\Extensions;

use League\CommonMark\ConfigurableEnvironmentInterface;
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Extension\ExtensionInterface;

class AddListStyleClassesExtension implements ExtensionInterface
{
    public function register(ConfigurableEnvironmentInterface $environment): void
    {
            $environment
                ->addEventListener(DocumentParsedEvent::class, new AddListStyleClassesRenderer());
        ;
    }
}
  1. Create file called AddListStyleClassesRenderer.php under the newly created folder App/Extensions
  2. Populate AddListStyleClassesRenderer.php with:
<?php
namespace App\Extensions;

use League\CommonMark\EnvironmentInterface;
use League\CommonMark\Event\DocumentParsedEvent;
use League\CommonMark\Block\Element\ListBlock;

class AddListStyleClassesRenderer {

    /**
     * @param DocumentParsedEvent $e
     *
     * @return void
     */
    public function __invoke(DocumentParsedEvent $e)
    {
        $walker = $e->getDocument()->walker();

        while ($event = $walker->next()) {
            $node = $event->getNode();
            if ($node instanceof ListBlock) {
                $node->data['attributes'] = array('class' => 'list-disc list-inside');
            }
        }
    }

}
  1. Add the AddListStyleClassesExtension class to the markdown.php-config file
    'extensions' => [\App\Extensions\AddListStyleClassesExtension::class],

Done!

from laravel-markdown.

colinodell avatar colinodell commented on August 17, 2024

thephpleague/commonmark#605 might answer your question

from laravel-markdown.

colinodell avatar colinodell commented on August 17, 2024

Thanks for sharing your solution with others! o/

from laravel-markdown.

ptmkenny avatar ptmkenny commented on August 17, 2024

For anybody coming to this from a search engine like I just did, there is a much easier solution now using Default Attributes.

from laravel-markdown.

Related Issues (20)

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.