From 622e9e4228197c710128bba362f204476dd829ec Mon Sep 17 00:00:00 2001
From: Dominik Pfennig <dominik@suma-ev.de>
Date: Mon, 20 Mar 2017 14:04:42 +0100
Subject: [PATCH] =?UTF-8?q?Anchorelemente=20werden=20nun=20korrekt=20unter?=
 =?UTF-8?q?st=C3=BCtzt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/HtmlDocument.php | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/app/HtmlDocument.php b/app/HtmlDocument.php
index fe81d10..fc8aef5 100644
--- a/app/HtmlDocument.php
+++ b/app/HtmlDocument.php
@@ -46,13 +46,22 @@ class HtmlDocument extends Document
 
         # First things first. Let's change all a Tags that can define a target Attribute
         foreach ($dom->getElementsByTagName('a') as $link) {
-            # All Links within a "a" Tag need to target the top level because they change the site on click
-            $this->convertTargetAttribute($link, "_top");
-            # Convert all relative Links to absolute Ones
-            $link->setAttribute("href", $this->convertRelativeToAbsoluteLink($link->getAttribute("href")));
-            # Convert all Links to the proxified Version
-            # All of this Links should target to the top Level
-            $link->setAttribute("href", $this->proxifyUrl($link->getAttribute("href"), true));
+            if ($link->hasAttribute("href")) {
+                if (stripos($link->getAttribute("href"), "#") === 0) {
+                    continue;
+                } elseif (stripos($link->getAttribute("href"), "javascript:") === 0) {
+                    $link->setAttribute("href", "");
+                } else {
+                    # All Links within a "a" Tag need to target the top level because they change the site on click
+                    $this->convertTargetAttribute($link, "_top");
+                    # Convert all relative Links to absolute Ones
+                    $link->setAttribute("href", $this->convertRelativeToAbsoluteLink($link->getAttribute("href")));
+                    # Convert all Links to the proxified Version
+                    # All of this Links should target to the top Level
+                    $link->setAttribute("href", $this->proxifyUrl($link->getAttribute("href"), true));
+                }
+            }
+
         }
 
         # All Buttons
-- 
GitLab