Skip to content

Easy Solution to wrap html-elements around custom parsed md/cm-elements? #635

Answered by colinodell
cyberpunkbln asked this question in Q&A
Discussion options

You must be logged in to vote

You could create a custom block renderer that replaces the built-in heading renderer.

For example, you could do something like this:

<?php

use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\Heading;
use League\CommonMark\Block\Renderer\BlockRendererInterface;
use League\CommonMark\Block\Renderer\HeadingRenderer;
use League\CommonMark\ElementRendererInterface;
use League\CommonMark\HtmlElement;

final class MyCustomHeadingRenderer implements BlockRendererInterface
{
    private BlockRendererInterface $coreHeadingRenderer;

    public function __construct()
    {
        $this->coreHeadingRenderer = new HeadingRenderer();
    }

    /**
     * @param Hea…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by colinodell
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question General questions about the project or usage
2 participants
Converted from issue

This discussion was converted from issue #600 on June 12, 2021 13:53.