Skip to content

Commit 409891c

Browse files
committed
github-headline: add heading level setting
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent 3caa3ce commit 409891c

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎github-headline/github-headline.qml‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import QtQml 2.0
2+
import QOwnNotesTypes 1.0
23

34
/**
45
* This script detects if a GitHub issue url is in the clipboard and downloads the page
56
* so it can parse the headline from it to paste a markdown headline and a link
67
*/
78
QtObject {
9+
property int headingLevel
10+
property variant settingsVariables: [
11+
{
12+
"identifier": "headingLevel",
13+
"name": "Heading level for inserted headline",
14+
"description": "Markdown heading level used for the inserted GitHub issue or pull request headline (1-6).",
15+
"type": "integer",
16+
"default": 3
17+
}
18+
]
819

920
/**
1021
* Replaces html entities to characters
@@ -559,6 +570,19 @@ QtObject {
559570
return string;
560571
}
561572
}
573+
574+
function markdownHeadingPrefix() {
575+
var level = parseInt(headingLevel);
576+
577+
if (isNaN(level) || level < 1) {
578+
level = 3;
579+
} else if (level > 6) {
580+
level = 6;
581+
}
582+
583+
return new Array(level + 1).join("#");
584+
}
585+
562586
/**
563587
* This function is called when html or a media file is pasted to a note with `Ctrl + Shift + V`
564588
*
@@ -606,7 +630,7 @@ QtObject {
606630
script.log("Found headline: " + headline);
607631

608632
// generate Markdown to paste
609-
var result = "## " + headline + "\n\n- <" + text + ">\n";
633+
var result = markdownHeadingPrefix() + " " + headline + "\n\n- <" + text + ">\n";
610634
return result;
611635
}
612636

‎github-headline/info.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "GitHub Headline",
33
"identifier": "github-headline",
44
"script": "github-headline.qml",
5-
"version": "0.2.5",
5+
"version": "0.3.0",
66
"minAppVersion": "17.05.6",
77
"authors": ["@pbek"],
88
"description": "Inserts a headline and a link to the <a href='https://github.com/'>GitHub</a> issue or pull request from an url in the clipboard into the current note when you paste the link with <i>Ctrl + Shift + V</i>."

0 commit comments

Comments
 (0)