]> _ Git - cubist_cms-back.git/commitdiff
wip #3753
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 3 Dec 2020 13:14:43 +0000 (14:14 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 3 Dec 2020 13:14:43 +0000 (14:14 +0100)
src/app/Markdown/InternaLink/Extension.php [deleted file]
src/app/Markdown/InternaLink/Renderer.php [deleted file]
src/app/Markdown/InternalLink/Extension.php [new file with mode: 0644]
src/app/Markdown/InternalLink/Renderer.php [new file with mode: 0644]

diff --git a/src/app/Markdown/InternaLink/Extension.php b/src/app/Markdown/InternaLink/Extension.php
deleted file mode 100644 (file)
index 0e826be..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\Markdown\InternalLink;
-
-
-use League\CommonMark\Block\Element\Heading;
-use League\CommonMark\ConfigurableEnvironmentInterface;
-use League\CommonMark\Extension\ExtensionInterface;
-use League\CommonMark\Inline\Element\Link;
-
-class Extension implements ExtensionInterface
-{
-    public function register(ConfigurableEnvironmentInterface $environment)
-    {
-        $environment->addInlineRenderer(Link::class, new Renderer(), 10);
-    }
-}
diff --git a/src/app/Markdown/InternaLink/Renderer.php b/src/app/Markdown/InternaLink/Renderer.php
deleted file mode 100644 (file)
index ce724da..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-
-
-namespace Cubist\Backpack\Markdown\InternalLink;
-
-
-use Cubist\Backpack\Magic\Menu\Menu;
-use League\CommonMark\ElementRendererInterface;
-use League\CommonMark\HtmlElement;
-use League\CommonMark\Inline\Element\AbstractInline;
-use League\CommonMark\Inline\Element\Link;
-use League\CommonMark\Inline\Renderer\InlineRendererInterface;
-
-class Renderer implements InlineRendererInterface
-{
-
-    /**
-     * @param Link $inline
-     * @param ElementRendererInterface $htmlRenderer
-     *
-     * @return HtmlElement
-     */
-    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
-    {
-        if (!($inline instanceof Link)) {
-            throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
-        }
-
-        $attrs = $inline->getData('attributes', []);
-
-
-        $href = $inline->getUrl();
-        if (stristr($href, 'internal:')) {
-            $href = Menu::internalToHref($href);
-        }
-        $attrs['href'] = $href;
-
-        if (isset($inline->data['title'])) {
-            $attrs['title'] = $inline->data['title'];
-        }
-
-        if (isset($attrs['target']) && $attrs['target'] === '_blank' && !isset($attrs['rel'])) {
-            $attrs['rel'] = 'noopener noreferrer';
-        }
-
-        return new HtmlElement('a', $attrs, $htmlRenderer->renderInlines($inline->children()));
-    }
-
-}
diff --git a/src/app/Markdown/InternalLink/Extension.php b/src/app/Markdown/InternalLink/Extension.php
new file mode 100644 (file)
index 0000000..0e826be
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace Cubist\Backpack\Markdown\InternalLink;
+
+
+use League\CommonMark\Block\Element\Heading;
+use League\CommonMark\ConfigurableEnvironmentInterface;
+use League\CommonMark\Extension\ExtensionInterface;
+use League\CommonMark\Inline\Element\Link;
+
+class Extension implements ExtensionInterface
+{
+    public function register(ConfigurableEnvironmentInterface $environment)
+    {
+        $environment->addInlineRenderer(Link::class, new Renderer(), 10);
+    }
+}
diff --git a/src/app/Markdown/InternalLink/Renderer.php b/src/app/Markdown/InternalLink/Renderer.php
new file mode 100644 (file)
index 0000000..ce724da
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+
+
+namespace Cubist\Backpack\Markdown\InternalLink;
+
+
+use Cubist\Backpack\Magic\Menu\Menu;
+use League\CommonMark\ElementRendererInterface;
+use League\CommonMark\HtmlElement;
+use League\CommonMark\Inline\Element\AbstractInline;
+use League\CommonMark\Inline\Element\Link;
+use League\CommonMark\Inline\Renderer\InlineRendererInterface;
+
+class Renderer implements InlineRendererInterface
+{
+
+    /**
+     * @param Link $inline
+     * @param ElementRendererInterface $htmlRenderer
+     *
+     * @return HtmlElement
+     */
+    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
+    {
+        if (!($inline instanceof Link)) {
+            throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
+        }
+
+        $attrs = $inline->getData('attributes', []);
+
+
+        $href = $inline->getUrl();
+        if (stristr($href, 'internal:')) {
+            $href = Menu::internalToHref($href);
+        }
+        $attrs['href'] = $href;
+
+        if (isset($inline->data['title'])) {
+            $attrs['title'] = $inline->data['title'];
+        }
+
+        if (isset($attrs['target']) && $attrs['target'] === '_blank' && !isset($attrs['rel'])) {
+            $attrs['rel'] = 'noopener noreferrer';
+        }
+
+        return new HtmlElement('a', $attrs, $htmlRenderer->renderInlines($inline->children()));
+    }
+
+}