diff --git a/default/templates/base.tpl b/default/templates/base.tpl index 34853cb56..d8267c06f 100644 --- a/default/templates/base.tpl +++ b/default/templates/base.tpl @@ -32,8 +32,7 @@ } /* External link icon (see https://stackoverflow.com/a/66093928/5603549)*/ - a.emanote-external:not(.emanote-contains-image)::after - { + a.emanote-external:not(.emanote-external-no-icon)::after { background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='rgb(156, 163, 175)' %3E%3Cpath d='M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z' /%3E%3Cpath d='M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z' /%3E%3C/svg%3E") 0 0 no-repeat; background-size: 100% 100%; display: inline-block; @@ -41,8 +40,8 @@ width: 1em; content: ''; } - a.emanote-external:not(.emanote-contains-image):hover::after - { + + a.emanote-external:not(.emanote-external-no-icon):hover::after { background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='rgba(75, 85, 99)' %3E%3Cpath d='M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z' /%3E%3Cpath d='M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z' /%3E%3C/svg%3E") 0 0 no-repeat; background-size: 100% 100%; display: inline-block; @@ -64,10 +63,6 @@ - - - + \ No newline at end of file diff --git a/default/templates/components/pandoc.tpl b/default/templates/components/pandoc.tpl index acda7b6bd..96563c92b 100644 --- a/default/templates/components/pandoc.tpl +++ b/default/templates/components/pandoc.tpl @@ -91,7 +91,9 @@ - + + + diff --git a/src/Heist/Extra/Splices/Pandoc/Ctx.hs b/src/Heist/Extra/Splices/Pandoc/Ctx.hs index 7861e8502..383a9d598 100644 --- a/src/Heist/Extra/Splices/Pandoc/Ctx.hs +++ b/src/Heist/Extra/Splices/Pandoc/Ctx.hs @@ -17,6 +17,7 @@ import Heist.Extra.Splices.Pandoc.Attr (concatAttr) import Heist.Interpreted qualified as HI import Relude import Text.Pandoc.Builder qualified as B +import Text.Pandoc.Walk qualified as W import Text.XmlHtml qualified as X -- | The configuration context under which we must render a `Pandoc` document @@ -115,16 +116,34 @@ inlineLookupAttr node = \case B.Code {} -> childTagAttr node "Code" B.Note _ -> childTagAttr node "Note" - B.Link _ _ (url, _) -> - fromMaybe B.nullAttr $ do - link <- X.childElementTag "PandocLink" node - let innerTag = if "://" `T.isInfixOf` url then "External" else "Internal" - pure $ attrFromNode link `concatAttr` childTagAttr link innerTag + link@(B.Link _ _ (url, _)) -> + let isExternal = "://" `T.isInfixOf` url + containsImage = getAny $ W.query (\case B.Image {} -> Any True; _ -> Any False) link + in fromMaybe B.nullAttr $ do + linkNode <- X.childElementTag "PandocLink" node + let linkTypeNode = + X.childElementTag + ( if isExternal + then "External" + else "Internal" + ) + linkNode + let noIconNode = + if isExternal && containsImage + then linkTypeNode >>= X.childElementTag "NoIcon" + else Nothing + pure $ + attrFromNode linkNode + `concatAttr` attrFromMaybeNode linkTypeNode + `concatAttr` attrFromMaybeNode noIconNode _ -> B.nullAttr +attrFromMaybeNode :: Maybe X.Node -> B.Attr +attrFromMaybeNode = maybe B.nullAttr attrFromNode + childTagAttr :: X.Node -> Text -> B.Attr childTagAttr x name = - maybe B.nullAttr attrFromNode $ X.childElementTag name x + attrFromMaybeNode $ X.childElementTag name x attrFromNode :: X.Node -> B.Attr attrFromNode node =