Skip to content

Commit

Permalink
Fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
scottwillmoore committed Jun 23, 2023
1 parent e583a23 commit b096c11
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.3] - 2023-06-23

### Changed

- Add test cases for the Dataview plugin.
- Add test cases for tables which contain aliased links.

### Fixed

- Fix aliased link detection for the Dataview plugin. #9.

## [1.1.2] - 2023-05-07

### Changed
Expand Down
3 changes: 0 additions & 3 deletions TODO.md

This file was deleted.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Short links",
"description": "An Obsidian plugin to display short internal links.",
"author": "Scott Moore",
"version": "1.1.2",
"version": "1.1.3",
"minAppVersion": "1.1.1",
"isDesktopOnly": false
}
21 changes: 21 additions & 0 deletions notes/Dataview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#dataview

# Data

[[Australia]]
[[Australia#Victoria]]
[[Australia#^states-and-territories]]

[[Australia|AUS]]
[[Australia#Victoria|VIC]]
[[Australia#^states-and-territories|States and Territories]]

[[Australia|<]]
[[Australia#Victoria|<<]]
[[Australia#^states-and-territories|<<<]]

# View

```dataview
TABLE file.outlinks FROM #dataview
```
19 changes: 19 additions & 0 deletions notes/Tables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
NOTE: Aliased links appear to break tables...

| Link | Link |
| --- | --- |
| [[Australia]] | [[Australia]] |
| [[Australia#Victoria]] | [[Australia#Victoria]] |
| [[Australia#^states-and-territories]] | [[Australia#^states-and-territories]] |

| Link | Aliased Link |
| --- | --- |
| [[Australia]] | [[Australia|AUS]] |
| [[Australia#Victoria]] | [[Australia#Victoria|VIC]] |
| [[Australia#^states-and-territories]] | [[Australia#^states-and-territories|States and Territories]] |

| Aliased Link | Link |
| --- | --- |
| [[Australia|AUS]] | [[Australia]] |
| [[Australia#Victoria|VIC]] | [[Australia#Victoria]] |
| [[Australia#^states-and-territories|States and Territories]] | [[Australia#^states-and-territories]] |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "An Obsidian plugin to display short internal links.",
"author": "Scott Moore",
"license": "MIT",
"version": "1.1.2",
"version": "1.1.3",
"scripts": {
"build": "node --require esbuild-register scripts/build.ts",
"format": "prettier --write .",
Expand Down
17 changes: 14 additions & 3 deletions sources/markdownPostProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@ export const createMarkdownPostProcessor: CreateMarkdownPostProcessor = (plugin)
const link = linkElement.getAttribute("href");
if (link === null) continue;

const isAlias = linkElement.hasAttribute("aria-label");
// NOTE: There is no easy way to detect whether a link is an alias or
// not. At the moment, the only way to detect whether a link is an
// alias is to check whether the `aria-label` attribute exists.
// However, this does not work in rare cases, for example in the
// Dataview plugin. Therefore, we also must check whether the
// attribute is different from the link text and also strip any file
// names! At the moment we just remove all instances of `.md`, however
// this is not a perfect solution.

const ariaLabel = linkElement.getAttribute("aria-label");
const expectedText = ariaLabel?.replace(".md", "");
const isAlias = expectedText !== linkElement.getText();

const internalLink = parseInternalLink(link);

if (configuration.shortLinksToFiles && !isAlias) {
const fileNameText = sliceText(link, internalLink.fileName);
linkElement.setText(fileNameText);
const fileBaseText = sliceText(link, internalLink.fileBase);
linkElement.setText(fileBaseText);
}

switch (internalLink.type) {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"1.0.2": "0.16.3",
"1.1.0": "1.1.1",
"1.1.1": "1.1.1",
"1.1.2": "1.1.1"
"1.1.2": "1.1.1",
"1.1.3": "1.1.1"
}

0 comments on commit b096c11

Please sign in to comment.