Changed named anchor syntax
parent
246d3ae45b
commit
a2e5d0cc93
|
@ -11,7 +11,7 @@ export async function indexAnchors({ name: pageName, tree }: IndexTreeEvent) {
|
|||
const anchors: { key: string; value: string }[] = [];
|
||||
|
||||
collectNodesOfType(tree, "NamedAnchor").forEach((n) => {
|
||||
const aName = n.children![0].text!;
|
||||
const aName = n.children![0].text!.substring(1);
|
||||
anchors.push({
|
||||
key: `a:${pageName}:${aName}`,
|
||||
value: "" + n.from,
|
||||
|
@ -31,11 +31,13 @@ export async function anchorComplete() {
|
|||
if (!pageRef) {
|
||||
pageRef = await editor.getCurrentPage();
|
||||
}
|
||||
const allAnchors = await index.queryPrefix(`a:${pageRef}:@${anchorRef}`);
|
||||
const allAnchors = await index.queryPrefix(
|
||||
`a:${pageRef}:${anchorRef}`,
|
||||
);
|
||||
return {
|
||||
from: prefix.from + pageRefPrefix.length + 1,
|
||||
options: allAnchors.map((a) => ({
|
||||
label: a.key.split("@")[1],
|
||||
label: a.key.split(":")[2],
|
||||
type: "anchor",
|
||||
})),
|
||||
};
|
||||
|
|
|
@ -19,8 +19,8 @@ syntax:
|
|||
className: sb-command-link
|
||||
NamedAnchor:
|
||||
firstCharacters:
|
||||
- "@"
|
||||
regex: "@[a-zA-Z\\.\\-\\/]+[\\w\\.\\-\\/]*"
|
||||
- "$"
|
||||
regex: "\\$[a-zA-Z\\.\\-\\/]+[\\w\\.\\-\\/]*"
|
||||
className: sb-named-anchor
|
||||
functions:
|
||||
clearPageIndex:
|
||||
|
|
|
@ -201,7 +201,7 @@ export class Editor {
|
|||
const stateRestored = await this.loadPage(pageName);
|
||||
if (pos) {
|
||||
if (typeof pos === "string") {
|
||||
// console.log("Navigating to anchor", pos);
|
||||
console.log("Navigating to anchor", pos);
|
||||
|
||||
// We're going to look up the anchor through a direct page store query...
|
||||
const posLookup = await this.system.localSyscall(
|
||||
|
@ -209,7 +209,7 @@ export class Editor {
|
|||
"index.get",
|
||||
[
|
||||
pageName,
|
||||
`a:${pageName}:@${pos}`,
|
||||
`a:${pageName}:${pos}`,
|
||||
],
|
||||
);
|
||||
|
||||
|
|
|
@ -3,6 +3,16 @@ release.
|
|||
|
||||
---
|
||||
|
||||
## 0.1.4
|
||||
|
||||
- Breaking change (for those who used it): the named anchor syntax has changed
|
||||
from `@anchorname` to `$anchorname`. This is to avoid conflicts with
|
||||
potentialy future use of `@` for other purposes (like mentioning people).
|
||||
Linking to an anchor still uses the `[[page@anchorname]]` syntax. So, you
|
||||
create an anchor $likethis you can then reference it [[@likethis]].
|
||||
|
||||
---
|
||||
|
||||
## 0.1.3
|
||||
|
||||
- Silver Bullet now runs on Windows!
|
||||
|
|
Loading…
Reference in New Issue