parent
64e398fd90
commit
7b955ef26a
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
collectNodesOfType,
|
||||||
findNodeOfType,
|
findNodeOfType,
|
||||||
renderToText,
|
renderToText,
|
||||||
traverseTree,
|
traverseTree,
|
||||||
|
@ -206,6 +207,42 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also index links used inside quoted frontmatter strings like "[[Page]]"
|
||||||
|
// must match the full string node, only allowing for quotes and whitespace around it
|
||||||
|
if (n.type === "FrontMatter") {
|
||||||
|
// The YAML in frontmatter is parsed by CodeMirror itself
|
||||||
|
for (const textNode of collectNodesOfType(n, "string")) {
|
||||||
|
const text = textNode.children![0].text!;
|
||||||
|
const trimmed = text.replace(/^["'\s]*/, "").replace(/["'\s]*$/, "");
|
||||||
|
// Make sure we search from the beginning, when reusing a Regex object with global flag
|
||||||
|
wikiLinkRegex.lastIndex = 0;
|
||||||
|
const match = wikiLinkRegex.exec(text);
|
||||||
|
// Search in entire node text to get correct position, but check for full match against trimmed
|
||||||
|
if (match && match[0] === trimmed) {
|
||||||
|
const [_fullMatch, firstMark, url, alias, _lastMark] = match;
|
||||||
|
const pos = textNode.from! + match.index! + firstMark.length;
|
||||||
|
const link: any = {
|
||||||
|
ref: `${name}@${pos}`,
|
||||||
|
tag: "link",
|
||||||
|
page: name,
|
||||||
|
snippet: extractSnippetAroundIndex(pageText, pos),
|
||||||
|
pos: pos,
|
||||||
|
asTemplate: false,
|
||||||
|
};
|
||||||
|
if (looksLikePathWithExtension(url)) {
|
||||||
|
link.toFile = resolvePath(name, url);
|
||||||
|
} else {
|
||||||
|
link.toPage = resolvePath(name, parsePageRef(url).page);
|
||||||
|
}
|
||||||
|
if (alias) {
|
||||||
|
link.alias = alias;
|
||||||
|
}
|
||||||
|
updateITags(link, frontmatter);
|
||||||
|
links.push(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,25 @@
|
||||||
YAML stands for “YAML Ain’t Markup Language.” More information can be found at [the YAML website](https://yaml.org/).
|
YAML stands for “YAML Ain’t Markup Language.” More information can be found at [the YAML website](https://yaml.org/).
|
||||||
|
|
||||||
SilverBullet uses YAML in various contexts, specifically [[Frontmatter]].
|
SilverBullet uses YAML in various contexts, specifically [[Frontmatter]] and [[Space Config]]
|
||||||
|
|
||||||
|
# Internal links
|
||||||
|
Many string values can be written directly in YAML without any quoting, like:
|
||||||
|
```yaml
|
||||||
|
property: value
|
||||||
|
```
|
||||||
|
|
||||||
|
However when you want to reference [[Links|a page]] or [[Command links|command]] you will need to quote the full link:
|
||||||
|
```yaml
|
||||||
|
some page: "[[Pages]]"
|
||||||
|
list of pages:
|
||||||
|
- "[[Pages]]"
|
||||||
|
- "[[Links]]"
|
||||||
|
```
|
||||||
|
|
||||||
|
This is because the square brackets used in the internal link format have a meaning in YAML as well. So an unquoted link is parsed as list inside a list:
|
||||||
|
```yaml
|
||||||
|
some page: [[Pages]]
|
||||||
|
equivalent yaml: [
|
||||||
|
[ "Pages" ]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in New Issue