forked from srid/emanote
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
193 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,4 +105,4 @@ | |
<h6 class="mt-6 mb-2 text-xl font-bold text-gray-700" /> | ||
</Header> | ||
|
||
</ema:note:pandoc> | ||
</ema:note:pandoc> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
page: | ||
headHtml: | | ||
<snippet var="js.mathjax" /> | ||
--- | ||
|
||
# External link icons | ||
|
||
A link whose address begins with an [URI scheme](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax) component is considered an **external link**. | ||
|
||
## Heuristic | ||
|
||
Emanote displays an icon next to an external hyperlink if its description contains some text, including inline code and math formulas.[^noneg] The heuristic is intended to make the site look good in most cases. | ||
|
||
### Overriding the heuristic | ||
|
||
This behaviour can be overriden by setting the value of the `data-linkicon` [data attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*) of a link: | ||
|
||
| Attribute to use | Description | | ||
| ---------------------------------------------- | ---------------------------------------------- | | ||
| `{data-linkicon=external}` | *Force* displaying the icon next to the link | | ||
| `{data-linkicon=none}` or `{data-linkicon=""}` | *Prevent* displaying the icon next to the link | | ||
|
||
[^noneg]: A common non-example is a hyperlink containing only an image in the description. | ||
|
||
Note that the attribute can also be used to display the icons in the [[html-template|HTML templates]] (like the footer or the sidebar) or in raw HTML of [[markdown]]. | ||
|
||
## URL properties | ||
|
||
The displayed icon may depend on the link properties (e.g. the actual URI scheme). This is [[custom-style|customized using CSS]]. By default, Emanote displays a different icon if the URI scheme component is `mailto:`. Check the <https://github.com/EmaApps/emanote/blob/master/default/templates/base.tpl> of [[html-template|HTML template]] for details. | ||
|
||
## Demo | ||
|
||
* Default styling: | ||
* [the emanote repo](https://github.com/EmaApps/emanote) | ||
* [why the external link symbol ![[external-link-icon.svg]] is not in Unicode](https://www.unicode.org/alloc/nonapprovals.html) | ||
* [$e^{i \pi} + 1 = 0$](https://en.wikipedia.org/wiki/Euler%27s_identity) | ||
* [`(>>=) :: forall a b. m a -> (a -> m b) -> m b`](https://hackage.haskell.org/package/base/docs/Prelude.html#v:-62--62--61-) | ||
* [![[hello-badge.svg]]](https://emanote.srid.ca) | ||
* [email protected] | ||
* `{data-linkicon=none}` used to suppress the icon: | ||
* Water's formula is [H](https://en.wikipedia.org/wiki/Hydrogen){data-linkicon=none}₂[O](https://en.wikipedia.org/wiki/Oxygen){data-linkicon=none}. | ||
* A 90's style hyperlink: | ||
[➡➡➡ **CLICK HERE!!!** ⬅⬅⬅](https://emanote.srid.ca){class="shadow-lg border-8 rounded-md bg-yellow-400 border-red-200" data-linkicon=none} | ||
* `{data-linkicon=external}` used to forcefully show the icon | ||
* [![[pIqaD.svg]]](https://en.wikipedia.org/wiki/Klingon_scripts){data-linkicon=external} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
cabal-version: 2.4 | ||
name: emanote | ||
version: 0.8.1.3 | ||
version: 0.8.1.4 | ||
license: AGPL-3.0-only | ||
copyright: 2022 Sridhar Ratnakumar | ||
maintainer: [email protected] | ||
|
@@ -175,6 +175,7 @@ library | |
Emanote.Model.Title | ||
Emanote.Model.Type | ||
Emanote.Pandoc.BuiltinFilters | ||
Emanote.Pandoc.BuiltinFiltersSpec | ||
Emanote.Pandoc.Link | ||
Emanote.Pandoc.Markdown.Parser | ||
Emanote.Pandoc.Markdown.Syntax.HashTag | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module Emanote.Pandoc.BuiltinFiltersSpec where | ||
|
||
import Emanote.Pandoc.BuiltinFilters (preparePandoc) | ||
import Emanote.Pandoc.Markdown.Parser (parseMarkdown) | ||
import Hedgehog | ||
import Relude | ||
import Test.Hspec | ||
import Test.Hspec.Hedgehog (hedgehog) | ||
import Text.Pandoc.Definition (Inline (..)) | ||
import Text.Pandoc.Walk qualified as W | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "setExternalLinkIcon" $ do | ||
it "respects user-specified data-linkicon attribute" . hedgehog $ do | ||
getDataLinkIconAttrs "[test](https://www.test.com){data-linkicon=abc}" === Right ["abc"] | ||
getDataLinkIconAttrs "[test](https://www.test.com){data-linkicon=\"\"}" === Right [""] | ||
getDataLinkIconAttrs "[[foo]]{data-linkicon=external}" === Right ["external"] | ||
getDataLinkIconAttrs "[abc](x/y/z){data-linkicon=none}" === Right ["none"] | ||
it "does not add attribute if link is internal" . hedgehog $ do | ||
getDataLinkIconAttrs "[[foo]]" === Right [] | ||
getDataLinkIconAttrs "[abc](x/y/z)" === Right [] | ||
getDataLinkIconAttrs "![[image.jpg]]" === Right [] | ||
getDataLinkIconAttrs "[![](path/to/image.png)](foo/bar/baz)" === Right [] | ||
getDataLinkIconAttrs "[[bar|baz]]" === Right [] | ||
getDataLinkIconAttrs "[`abc`](./test.txt)" === Right [] | ||
getDataLinkIconAttrs "[$$abc$$](/just/test#ing)" === Right [] | ||
getDataLinkIconAttrs "#tag" === Right [] | ||
getDataLinkIconAttrs "[[abc|def]]" === Right [] | ||
it "adds attribute if link is external and its description contains text, code or math" . hedgehog $ do | ||
getDataLinkIconAttrs "[Emanote](https://github.com/EmaApps/emanote)" === Right ["external"] | ||
getDataLinkIconAttrs "[`text`](http://somehost:1234/test)" === Right ["external"] | ||
getDataLinkIconAttrs "[$$E=mc^2$$](ssh://[email protected]/~/path/)" === Right ["external"] | ||
getDataLinkIconAttrs "[![[picture.png]] ~~**`code`**~~](scheme://host:port/path?query)" === Right ["external"] | ||
getDataLinkIconAttrs "[==$$e^{i \\pi} + 1 = 0$$== ![[image.svg]]](git://host.xz/path/to/repo.git/)" === Right ["external"] | ||
getDataLinkIconAttrs "[email protected]" === Right ["external"] | ||
getDataLinkIconAttrs "https://www.test.gov" === Right ["external"] | ||
getDataLinkIconAttrs "[**![[image.jpg]] *qwerty* ![[image.jpg]]**](doi:10.1000/182)" === Right ["external"] | ||
getDataLinkIconAttrs "[:video_game:](bolo://hostname/)" === Right ["external"] | ||
it "does not add attribute if link description contains no text, code or math" . hedgehog $ do | ||
getDataLinkIconAttrs "[](http://nothing.interesting.here)" === Right [] | ||
getDataLinkIconAttrs "[![[image.png]]](https://www.example.com)" === Right [] | ||
getDataLinkIconAttrs "[==*_**~~![[img.png]]~~**_*==](http://something.info)" === Right [] | ||
|
||
-- | Extract "data-linkicon" attributes present in the given Markdown content. | ||
getDataLinkIconAttrs :: Text -> Either Text [Text] | ||
getDataLinkIconAttrs = | ||
fmap (W.query $ getLinkAttr "data-linkicon") . parseEmanoteMarkdown | ||
where | ||
parseEmanoteMarkdown = fmap (preparePandoc . snd) . parseMarkdown "<test>" | ||
|
||
getLinkAttr :: Text -> Inline -> [Text] | ||
getLinkAttr name (Link (_, _, attrs) _ (_, _)) = | ||
snd <$> filter ((== name) . fst) attrs | ||
getLinkAttr _ _ = | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters