Skip to content

Commit f1604c9

Browse files
authored
Backlinks update (#229)
* Update backlinks.qml - Add support for Setext headings (Resolves #227) * Update backlinks.qml - Add titles to links Adds link titles to generated links in the list. These links otherwise do not have any indication of where they link to. * Update version number
1 parent d68d7f6 commit f1604c9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

backlinks/backlinks.qml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ QtObject {
66
property string backlinksHtml
77
property bool triggerOnPreview
88
property string dirSep
9+
property bool useAtxHeadings;
910

1011
property variant settingsVariables: [
1112
{
@@ -15,6 +16,13 @@ QtObject {
1516
"type": "boolean",
1617
"default": false,
1718
},
19+
{
20+
"identifier": "useAtxHeadings",
21+
"name": "Use ATX headings",
22+
"description": "Use ATX-style Markdown headings (uncheck if using Setext-style)",
23+
"type": "boolean",
24+
"default": true,
25+
}
1826
];
1927

2028
function getSubFolder(note, path) {
@@ -45,7 +53,7 @@ QtObject {
4553
for (var i = 0; i < backlinks.length; i++) {
4654
var backlinkPath = backlinks[i]["p"];
4755
var backlinkTitle = backlinks[i]["t"];
48-
out += " <li><a href=\"file://" + backlinkPath + "\">" + backlinkTitle + "</a></li>\n";
56+
out += " <li><a href=\"file://" + backlinkPath + "\" title=\"" + backlinkPath + "\">" + backlinkTitle + "</a></li>\n";
4957
}
5058
out += "</ul>\n";
5159
}
@@ -83,10 +91,9 @@ QtObject {
8391
}
8492
if (isBacklink == true) {
8593
var fullPath = pageObj.fullNoteFilePath;
86-
var title = "";
87-
var titleMatch = text.match(/^# (.*)/);
88-
if (titleMatch) {
89-
title = titleMatch[1];
94+
var title = text.split("\n")[0];
95+
if (useAtxHeadings) {
96+
title = title.replace(/^# /, "");
9097
}
9198
var backlinkObj = {"p":fullPath, "t":title};
9299
backlinks.push(backlinkObj);

backlinks/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"script": "backlinks.qml",
55
"authors": ["@dohliam"],
66
"platforms": ["linux", "macos", "windows"],
7-
"version": "0.0.1",
7+
"version": "0.0.2",
88
"minAppVersion": "20.4.18",
99
"description" : "This script generates a list of backlinks to the current note from all other notes in the collection. Backlinks requires the use of wiki-style link syntax and should be installed alongside the wiki-links script. More information can be found at <a href='https://github.com/qownnotes/scripts/wiki/backlinks'>backlinks</a>."
1010
}

0 commit comments

Comments
 (0)