Jelajahi Sumber

Add unsafeGetAttribute function

jherve 1 tahun lalu
induk
melakukan
111bee353a
1 mengubah file dengan 9 tambahan dan 4 penghapusan
  1. 9 4
      src/LinkedIn/DetachedNode.purs

+ 9 - 4
src/LinkedIn/DetachedNode.purs

@@ -59,11 +59,11 @@ toDetached node = unsafePartial $ toDetached' (nodeType node) node where
 elementToDetached :: Element -> String -> Effect DetachedNode
 elementToDetached :: Element -> String -> Effect DetachedNode
 elementToDetached el text = case E.tagName el of
 elementToDetached el text = case E.tagName el of
   "A" -> do
   "A" -> do
-    href <- getAttribute "href" el
+    href <- unsafeGetAttribute "href" el
 
 
     pure $ DetachedA {
     pure $ DetachedA {
       content: normalize text,
       content: normalize text,
-      href: unsafePartial $ fromJust href
+      href
     }
     }
 
 
   "BUTTON" -> do
   "BUTTON" -> do
@@ -77,8 +77,8 @@ elementToDetached el text = case E.tagName el of
     }
     }
 
 
   "LI-ICON" -> do
   "LI-ICON" -> do
-    type_ <- getAttribute "type" el
-    pure $ DetachedLiIcon $ unsafePartial $ fromJust type_
+    type_ <- unsafeGetAttribute "type" el
+    pure $ DetachedLiIcon type_
 
 
   -- On SVG elements "className" returns a weird "SVGString" type that cannot be trimmed
   -- On SVG elements "className" returns a weird "SVGString" type that cannot be trimmed
   tag | tag == "svg" || tag == "use" || tag == "path" -> do
   tag | tag == "svg" || tag == "use" || tag == "path" -> do
@@ -107,6 +107,11 @@ elementToDetached el text = case E.tagName el of
       classStr <- E.className el'
       classStr <- E.className el'
       pure $ A.toUnfoldable $ S.split (Pattern " ") (normalize classStr)
       pure $ A.toUnfoldable $ S.split (Pattern " ") (normalize classStr)
 
 
+unsafeGetAttribute ∷ String → Element → Effect String
+unsafeGetAttribute name e = do
+  attr <- getAttribute name e
+  pure $ unsafePartial $ fromJust attr
+
 normalize :: String -> String
 normalize :: String -> String
 normalize = normaliseSpace >>> S.trim
 normalize = normaliseSpace >>> S.trim