Skip to content

Commit bd9bf31

Browse files
authored
Merge pull request #172 from spasche/fix-headings-with-special-chars
Fix detection of links to headings with special characters
2 parents 68cc752 + 0fc0fd2 commit bd9bf31

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1+
# 2.3.3
2+
3+
- Fix: detection of links to headings with special characters. [#163](https://github.com/TfTHacker/obsidian42-strange-new-worlds/issues/163).
4+
15
# 2.3.2
6+
27
- Fix: When using editing toolbar configured for showing toolbar at top, the SNW reference counter overlapped. The CSS was mofiied to prevent this. [#155](https://github.com/TfTHacker/obsidian42-strange-new-worlds/issues/155).
38

49
# 2.3.1
10+
511
- Change: if a link is the only link in the vault to a destination (thus the reference count is 1), the reference counter will not be shown next to the link, regardless of the minimum threshold count set in settings. This makes sense. If the link is used once, its obvious without the counter, and the counter simply stating the link has one reference was redudant and annoying to many users.
612

7-
# 2.3.0
13+
# 2.3.0
14+
815
- New: Added support for references to show up in the kanban plugin. This can be toggled on and off in settings.
916
- Changed: SNW's internal index did not include file extensions, which in some cases led to issues. the index now uses the full path with the extension, which means every file whether it is a MD file or not is included in the index.
1017

1118
# 2.2.1
1219

1320
- Reference count now appears in the files property subpan
1421

15-
# 2.2.0
22+
# 2.2.0
1623

1724
- This is another major update to the indexing engine to avoid detecting certain reported issues.
1825
- Additional optimization efforts to improve performance. (removing loops, keeping index optimized)

DEV_NOTES.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ DEV_NOTES.MD
22

33
# Updating the version
44

5-
1. update pacakage.json version number
5+
1. update package.json version number
66
2. npm run version (updates the manifest and version file)
77
3. commit repo
88
4. npm run githubaction (commits the version number tag to the repo and pushes it, which kicks of the github action to prepare the release)

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian42-strange-new-worlds",
33
"name": "Strange New Worlds",
4-
"version": "2.3.2",
4+
"version": "2.3.3",
55
"minAppVersion": "1.7.2",
66
"description": "Help see how your vault is interconnected with visual indicators.",
77
"author": "TfTHacker",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian42-strange-new-worlds",
3-
"version": "2.3.2",
3+
"version": "2.3.3",
44
"description": "Revealing networked thought and the strange new worlds created by your vault",
55
"scripts": {
66
"dev": "node --no-warnings esbuild.config.mjs",

src/indexer.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ export function getIndexedReferences() {
1616
return indexedReferences;
1717
}
1818

19-
// Primary Indexing function. Adss to the indexedReferences map all outgoing links from a given file
19+
function parseLinkTextAndStripHeading(link: string): { path: string; subpath: string } {
20+
let { path, subpath } = parseLinktext(link);
21+
if (subpath.startsWith("#") && !subpath.startsWith("#^")) {
22+
// subpath may link to a subheading (e.g. #parent#child). Keep the last subheading in this case.
23+
subpath = subpath.substring(subpath.lastIndexOf('#'));
24+
subpath = "#" + stripHeading(subpath);
25+
}
26+
return { path: path, subpath };
27+
}
28+
29+
// Primary Indexing function. Adds to the indexedReferences map all outgoing links from a given file
2030
// The Database is primarily a key which is the link, and the value is an array of references that use that link
2131
export const getLinkReferencesForFile = (file: TFile, cache: CachedMetadata) => {
2232
if (plugin.settings.enableIgnoreObsExcludeFoldersLinksFrom && file?.path && plugin.app.metadataCache.isUserIgnored(file?.path)) {
@@ -26,8 +36,8 @@ export const getLinkReferencesForFile = (file: TFile, cache: CachedMetadata) =>
2636
if (!item) continue;
2737
for (const ref of item) {
2838
const { path, subpath } = ref.link.startsWith("#") // if link is pointing to itself, create a full path
29-
? parseLinktext(file.path.replace(`.${file.extension}`, "") + ref.link)
30-
: parseLinktext(ref.link);
39+
? parseLinkTextAndStripHeading(file.path.replace(`.${file.extension}`, "") + ref.link)
40+
: parseLinkTextAndStripHeading(ref.link);
3141
const tfileDestination = plugin.app.metadataCache.getFirstLinkpathDest(path, "/");
3242
if (tfileDestination) {
3343
if (
@@ -123,7 +133,7 @@ export function getSNWCacheByFile(file: TFile): TransformedCache {
123133
if (!indexedReferences) buildLinksAndReferences();
124134

125135
if (cachedMetaData?.headings) {
126-
// filter - fFirst confirm there are references
136+
// filter - first confirm there are references
127137
// map - map to the transformed cache
128138
const baseFilePath = `${filePathInUppercase}#`;
129139
const tempCacheHeadings = cachedMetaData.headings
@@ -229,7 +239,7 @@ export function getSNWCacheByFile(file: TFile): TransformedCache {
229239
}
230240

231241
if (cachedMetaData?.frontmatterLinks) {
232-
// filter - fFirst confirm there are references
242+
// filter - first confirm there are references
233243
// map - map to the transformed cache
234244
const tempCacheFrontmatter = cachedMetaData.frontmatterLinks
235245
.filter((link) => indexedReferences.has(parseLinkTextToFullPath(link.link).toLocaleUpperCase() || link.link.toLocaleUpperCase()))
@@ -256,7 +266,7 @@ export function getSNWCacheByFile(file: TFile): TransformedCache {
256266
}
257267

258268
export function parseLinkTextToFullPath(link: string): string {
259-
const resolvedFilePath = parseLinktext(link);
269+
const resolvedFilePath = parseLinkTextAndStripHeading(link);
260270
const resolvedTFile = plugin.app.metadataCache.getFirstLinkpathDest(resolvedFilePath.path, "/");
261271
if (resolvedTFile === null) return "";
262272
return resolvedTFile.path + resolvedFilePath.subpath;

versions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
"2.2.1": "1.7.2",
1616
"2.3.0": "1.7.2",
1717
"2.3.1": "1.7.2",
18-
"2.3.2": "1.7.2"
18+
"2.3.2": "1.7.2",
19+
"2.3.3": "1.7.2"
1920
}

0 commit comments

Comments
 (0)