Created
May 25, 2021 06:27
-
-
Save GitMurf/f027ac2ada61d03007b973569e507627 to your computer and use it in GitHub Desktop.
Creates block ref on current line and copies to clipboard as asterisk alias link to be pasted somewhere else
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%* | |
const curSelection = tp.file.selection(); | |
const cmEditorAct = app.workspace.activeLeaf.view.editor; | |
const curLineNum = cmEditorAct.getCursor().line; | |
const curLine = cmEditorAct.getLine(curLineNum); | |
cmEditorAct.setSelection({ line: curLineNum, ch: 0 }, { line: curLineNum, ch: 9999 }); | |
const blockRef = curLine.match(/ \^(.*)/); | |
let id; | |
if (!blockRef) { | |
function createBlockHash() { | |
let result = ''; | |
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; | |
var charactersLength = characters.length; | |
for ( var i = 0; i < 7; i++ ) { | |
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
} | |
return result; | |
} | |
id = createBlockHash(); | |
tR = tp.file.selection() + ` ^${id}`.split("\n").join(""); | |
} else { | |
id = blockRef[1]; | |
tR = tp.file.selection(); | |
} | |
const textAlias = (curSelection ? curSelection : `*`); | |
const block = `[[${tp.file.title}#^${id}|${textAlias}]]`.split("\n").join(""); | |
navigator.clipboard.writeText(block).then(text => text); | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment