Copy Logseq/Roam Research content to clipboard without `[[]]` brackets

Remove wiki links (from logseq or roam) when you want to copy paste notes our of your editor:

Install kit link

// Name: Copy text sans brackets
// Description: Remove wiki links from selected text
// Shortcut: cmd + [
// Author: Ian Jones
// Twitter: @_jonesian
import "@johnlindquist/kit"
const text = await getSelectedText()
const newText = text.split("\n").map(text => {
return text.split(' ').map((word, i, arr) => {
if(!word) {
return
}
const FULL_BRACES_MATCH = /\[\[(.*?)\]\]/
const LEFT_MATCH = /\[\[/
const RIGHT_MATCH = /\]\]/
const [_, fullMatch] = word.match(FULL_BRACES_MATCH) ?? []
const [leftMatch] = word.match(LEFT_MATCH) ?? []
const [rightMatch] = word.match(RIGHT_MATCH) ?? []
if(!!fullMatch){
return fullMatch
} else if (!!leftMatch) {
const restOfArr = arr.slice(i + 1)
const restOfLink = restOfArr.reduce((acc, curr) => {
if(acc.endFound){
return acc
}
const [rightMatch] = curr.match(RIGHT_MATCH) ?? []
return {endFound: !!rightMatch, str: acc.str + " " + curr}
}, {endFound: false, str: ''}).str
const [_, match] = (word + restOfLink).match(FULL_BRACES_MATCH) ?? []
return match
} else if (rightMatch){
return
}else {
return word
}
}).join(' ')
}).join("\n")
if(newText){
await copy(newText)
}