1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Libraries\Markdown\CustomContainerInline;
7
8use League\CommonMark\Node\Node;
9use League\CommonMark\Renderer\ChildNodeRendererInterface;
10use League\CommonMark\Renderer\NodeRendererInterface;
11use League\CommonMark\Util\HtmlElement;
12
13class Renderer implements NodeRendererInterface
14{
15 public function render(Node $node, ChildNodeRendererInterface $childRenderer)
16 {
17 Element::assertInstanceOf($node);
18
19 $attrs = $node->data->getData('attributes');
20
21 $code = presence($attrs->get('flag', null));
22 if ($code !== null) {
23 $attrs->remove('flag');
24 $attrs->set('class', 'flag-country flag-country--flat flag-country--wiki');
25 $attrs->set('style', "background-image: url('".flag_url($code)."')");
26
27 $country = app('countries')->byCode($code);
28 if ($country !== null) {
29 $attrs->set('title', $country->name);
30 }
31 }
32
33 return new HtmlElement(
34 'span',
35 $attrs->export(),
36 $childRenderer->renderNodes($node->children()),
37 );
38 }
39}