Skip to content

How to add a global output filter on text nodes? #641

Answered by bplace
bplace asked this question in Q&A
Discussion options

You must be logged in to vote

Here's what I did:

In the Extension:

$environment->addBlockRenderer(Document::class, new TypographyRenderer(), 10);

TypographyRenderer

    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
    {
        if ( ! ($block instanceof Document)) {
            throw new \InvalidArgumentException('Incompatible block type: ' . \get_class($block));
        }

        $wholeDoc = $htmlRenderer->renderBlocks($block->children());

        $wholeDoc = preg_replace("#(\w) :#", "$1<span class=\"u-fine\">&nbsp;</span>:", $wholeDoc);

        return $wholeDoc === '' ? '' : $wholeDoc . "\n";
    }

Any other little tweak I'll need will go there,…

Replies: 3 comments

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
Answer selected by colinodell
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 #585 on June 12, 2021 13:58.