├── .gitignore ├── manifest.json ├── .github ├── workflows │ ├── premerge.yml │ └── release.yml └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── tsconfig.json ├── src └── main.ts ├── rollup.config.js ├── package.json ├── LICENSE ├── README.md └── styles.css /.gitignore: -------------------------------------------------------------------------------- 1 | # Intellij 2 | *.iml 3 | .idea 4 | 5 | # npm 6 | node_modules/ 7 | package-lock.json 8 | 9 | # build 10 | main.js 11 | *.js.map 12 | 13 | # obsidian 14 | data.json 15 | 16 | 17 | dist/ -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "hover-external-link", 3 | "name": "Hover External Link Plugin", 4 | "version": "1.0.0", 5 | "minAppVersion": "0.10.2", 6 | "description": "Hover on external links to see the destination URL.", 7 | "author": "Jamie Brynes", 8 | "authorUrl": "https://obsidian.md/about", 9 | "isDesktopOnly": true 10 | } -------------------------------------------------------------------------------- /.github/workflows/premerge.yml: -------------------------------------------------------------------------------- 1 | name: "premerge" 2 | on: [push] 3 | 4 | jobs: 5 | build: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Checkout source 9 | uses: actions/checkout@v2 10 | 11 | - name: Install NPM dependencies 12 | run: npm install 13 | 14 | - name: Build 15 | run: npm run build 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "inlineSourceMap": true, 5 | "inlineSources": true, 6 | "module": "ESNext", 7 | "target": "es6", 8 | "allowJs": true, 9 | "noImplicitAny": true, 10 | "moduleResolution": "node", 11 | "importHelpers": true, 12 | "lib": [ 13 | "dom", 14 | "es5", 15 | "scripthost", 16 | "es2015" 17 | ] 18 | }, 19 | "include": [ 20 | "**/*.ts" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: "✨ feature" 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { Plugin } from "obsidian"; 2 | import tippy from "tippy.js"; 3 | 4 | export default class HoverLinkPlugin extends Plugin { 5 | async onload() { 6 | this.registerMarkdownPostProcessor((element) => { 7 | // We only want to add tooltips to: 8 | // 1. external links 9 | // 2. links which don't already show the href 10 | const targetLinks = Array.from(element.getElementsByTagName("a")).filter( 11 | (link) => 12 | link.classList.contains("external-link") && 13 | link.href !== link.innerHTML 14 | ); 15 | 16 | for (const link of targetLinks) { 17 | tippy(link, { 18 | content: link.href, 19 | }); 20 | } 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a bug report 4 | title: '' 5 | labels: "\U0001F41B bug" 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - Plugin Version [e.g. 1.2.0] 28 | - Obsidian Version [e.g. 0.8.12] 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import typescript from "@rollup/plugin-typescript"; 2 | import { nodeResolve } from "@rollup/plugin-node-resolve"; 3 | import commonjs from "@rollup/plugin-commonjs"; 4 | import copy from "rollup-plugin-copy"; 5 | 6 | const isProd = process.env.NODE_ENV === "production"; 7 | 8 | export default { 9 | input: "src/main.ts", 10 | output: { 11 | dir: "./dist", 12 | sourcemap: "inline", 13 | sourcemapExcludeSources: isProd, 14 | format: "cjs", 15 | exports: "default", 16 | }, 17 | external: ["obsidian"], 18 | plugins: [ 19 | typescript(), 20 | nodeResolve({ browser: true }), 21 | commonjs(), 22 | copy({ 23 | targets: [ 24 | { 25 | src: "manifest.json", 26 | dest: "dist/", 27 | }, 28 | { 29 | src: "styles.css", 30 | dest: "dist/", 31 | }, 32 | ], 33 | }), 34 | ], 35 | }; 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "obsidian-sample-plugin", 3 | "version": "0.12.0", 4 | "description": "This is a sample plugin for Obsidian (https://obsidian.md)", 5 | "main": "main.js", 6 | "scripts": { 7 | "dev": "rollup --config rollup.config.js -w", 8 | "build": "rollup --config rollup.config.js --environment BUILD:production" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "MIT", 13 | "devDependencies": { 14 | "@rollup/plugin-commonjs": "^18.0.0", 15 | "@rollup/plugin-node-resolve": "^11.2.1", 16 | "@rollup/plugin-typescript": "^8.2.1", 17 | "@types/node": "^14.14.37", 18 | "obsidian": "^0.12.0", 19 | "postcss": "^8.3.6", 20 | "rollup": "^2.32.1", 21 | "rollup-plugin-copy": "^3.4.0", 22 | "rollup-plugin-postcss": "^4.0.1", 23 | "tslib": "^2.2.0", 24 | "typescript": "^4.2.4" 25 | }, 26 | "dependencies": { 27 | "tippy.js": "^6.3.1" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jamie Brynes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hover External Link Obsidian Plugin 2 | 3 | An [Obsidian](https://obsidian.md/) plugin that adds hover URL previews to external links in your rendered Markdown. 4 | 5 | ## Demo 6 | 7 | https://user-images.githubusercontent.com/13353733/130523291-99b6c6c3-24f4-4729-b9ba-e4df464f0e65.mp4 8 | 9 | 10 | ## Installation 11 | 12 | ### From in Obsidian 13 | 14 | 🚧 Coming Soon! 🚧 15 | 16 | ### Manually 17 | 18 | 1. Download `main.js`, `manifest.json`, and `styles.css` from the [latest release](https://github.com/jamiebrynes7/obsidian-hover-external-link/releases/latest). 19 | 2. Place them in `/.obsidian/plugins/hover-external-link/` folder (you'll need to create this). 20 | 21 | ## Usage 22 | 23 | This plugin will add on-hover tooltips to all external links _if_ the text of the link is not the same as the URL. This only works in the preview mode. 24 | 25 | ```md 26 | This link will have a hover tooltip: [Google](www.google.com). 27 | 28 | This link won't: [www.google.com](www.google.com). 29 | ``` 30 | 31 | ## Customization 32 | 33 | This plugin exposes two CSS variables that you can use to set the tooltip background and text color. 34 | 35 | ```css 36 | .theme-light { 37 | --link-tooltip-background: #333; 38 | --link-tooltip-text: #fff; 39 | } 40 | 41 | .theme-dark { 42 | --link-tooltip-background: #ccc; 43 | --link-tooltip-text: #000; 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: "Create Release" 2 | on: 3 | push: 4 | tags: 5 | - "*" 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout source 12 | uses: actions/checkout@v2 13 | 14 | - name: Install NPM dependencies 15 | run: npm install 16 | 17 | - name: Build 18 | run: NODE_ENV=production npm run build 19 | 20 | - name: Create release 21 | id: create_release 22 | uses: actions/create-release@v1 23 | env: 24 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 25 | with: 26 | tag_name: ${{ github.ref }} 27 | release_name: Release ${{ github.ref }} 28 | 29 | - name: Upload release assets (1/3) 30 | uses: actions/upload-release-asset@v1 31 | env: 32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 33 | with: 34 | upload_url: ${{ steps.create_release.outputs.upload_url }} 35 | asset_path: ./dist/main.js 36 | asset_name: main.js 37 | asset_content_type: application/javascript 38 | 39 | - name: Upload release assets (2/3) 40 | uses: actions/upload-release-asset@v1 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | with: 44 | upload_url: ${{ steps.create_release.outputs.upload_url }} 45 | asset_path: ./dist/manifest.json 46 | asset_name: manifest.json 47 | asset_content_type: application/json 48 | 49 | - name: Upload release assets (3/3) 50 | uses: actions/upload-release-asset@v1 51 | env: 52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 53 | with: 54 | upload_url: ${{ steps.create_release.outputs.upload_url }} 55 | asset_path: ./dist/styles.css 56 | asset_name: styles.css 57 | asset_content_type: text/css 58 | -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Originally copied from dist/tippy.css in the tippy.js package. 3 | * 4 | * Modifications were made to implement compatibility with 5 | * Obsidian themes. 6 | */ 7 | 8 | .theme-light { 9 | --link-tooltip-background: #333; 10 | --link-tooltip-text: #fff; 11 | } 12 | 13 | .theme-dark { 14 | --link-tooltip-background: #ccc; 15 | --link-tooltip-text: #000; 16 | } 17 | 18 | .tippy-box[data-animation="fade"][data-state="hidden"] { 19 | opacity: 0; 20 | } 21 | 22 | [data-tippy-root] { 23 | max-width: calc(100vw - 10px); 24 | } 25 | 26 | .tippy-box { 27 | position: relative; 28 | background-color: var(--link-tooltip-background); 29 | color: var(--link-tooltip-text); 30 | border-radius: 4px; 31 | font-size: 14px; 32 | line-height: 1.4; 33 | outline: 0; 34 | transition-property: transform, visibility, opacity; 35 | } 36 | 37 | .tippy-box[data-placement^="top"] > .tippy-arrow { 38 | bottom: 0; 39 | } 40 | 41 | .tippy-box[data-placement^="top"] > .tippy-arrow:before { 42 | bottom: -7px; 43 | left: 0; 44 | border-width: 8px 8px 0; 45 | border-top-color: initial; 46 | transform-origin: center top; 47 | } 48 | 49 | .tippy-box[data-placement^="bottom"] > .tippy-arrow { 50 | top: 0; 51 | } 52 | 53 | .tippy-box[data-placement^="bottom"] > .tippy-arrow:before { 54 | top: -7px; 55 | left: 0; 56 | border-width: 0 8px 8px; 57 | border-bottom-color: initial; 58 | transform-origin: center bottom; 59 | } 60 | 61 | .tippy-box[data-placement^="left"] > .tippy-arrow { 62 | right: 0; 63 | } 64 | 65 | .tippy-box[data-placement^="left"] > .tippy-arrow:before { 66 | border-width: 8px 0 8px 8px; 67 | border-left-color: initial; 68 | right: -7px; 69 | transform-origin: center left; 70 | } 71 | 72 | .tippy-box[data-placement^="right"] > .tippy-arrow { 73 | left: 0; 74 | } 75 | 76 | .tippy-box[data-placement^="right"] > .tippy-arrow:before { 77 | left: -7px; 78 | border-width: 8px 8px 8px 0; 79 | border-right-color: initial; 80 | transform-origin: center right; 81 | } 82 | 83 | .tippy-box[data-inertia][data-state="visible"] { 84 | transition-timing-function: cubic-bezier(0.54, 1.5, 0.38, 1.11); 85 | } 86 | 87 | .tippy-arrow { 88 | width: 16px; 89 | height: 16px; 90 | color: var(--link-tooltip-background); 91 | } 92 | 93 | .tippy-arrow:before { 94 | content: ""; 95 | position: absolute; 96 | border-color: transparent; 97 | border-style: solid; 98 | } 99 | 100 | .tippy-content { 101 | position: relative; 102 | padding: 10px 15px; 103 | z-index: 1; 104 | overflow-wrap: anywhere; 105 | } 106 | --------------------------------------------------------------------------------