Created
May 30, 2022 05:53
-
-
Save GitMurf/56bcd1da7db082513878e73011c1da3f to your computer and use it in GitHub Desktop.
When using headings with a [[page name]] in it, create a "search embed query" with all those headings expanded
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 noteName = tp.file.title; | |
let queryKeyword = await tp.system.prompt("Keyword for Section search query (do NOT add [ ] brackets around it)", noteName); | |
if(queryKeyword) { | |
// Un-comment the next line if you want the keyword to require [] brackets around it for backlinks matching purposes | |
queryKeyword = `\\[\\[${queryKeyword}[\\|\\]]`; // the | pipe check accounts for alias links | |
tR = ` | |
# Keyword Section Query | |
\`\`\`query | |
section:(/^#+ .*${queryKeyword}.*\\n+\\S[\\s\\S]*[^\\n]/) OR section:(/^#+ .*${queryKeyword}.*/ section:(/[\\s\\S]*[^\\n]/)) | |
\`\`\` | |
` | |
} else { | |
return; | |
} | |
%> |
Also keep in mind this is specifically for Headings / Section searches so will NOT show you ALL [[backlinks]] but only the ones where the [[backlink]] is in a Heading (and then all of the content below that Heading).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oddly enough for all of the sub text and sub headings to show up with the complex RegEx used in this query, you have to DISABLE the "Show more context" button, which is available if you are looking at this in Search results or if you have the Obsidian Query Control plugin installed (via BRAT).