diff --git a/client/codemirror/frontmatter.ts b/client/codemirror/frontmatter.ts index 3e73042d..8eaba51f 100644 --- a/client/codemirror/frontmatter.ts +++ b/client/codemirror/frontmatter.ts @@ -20,6 +20,7 @@ export function frontmatterPlugin(client: Client) { (state: EditorState) => { const widgets: any[] = []; const foldRanges = foldedRanges(state); + const shortWikiLinks = client.config.get("shortWikiLinks", true); syntaxTree(state).iterate({ enter(node) { @@ -136,6 +137,7 @@ export function frontmatterPlugin(client: Client) { matchFrom: mFrom, matchTo: mTo, client, + shortWikiLinks, state, callback: (e, ref) => { if (e.altKey) { diff --git a/client/codemirror/lua_widget.ts b/client/codemirror/lua_widget.ts index fb9801a6..cecfc742 100644 --- a/client/codemirror/lua_widget.ts +++ b/client/codemirror/lua_widget.ts @@ -190,6 +190,7 @@ export class LuaWidget extends WidgetType { ); html = parseHtmlString(renderMarkdownToHtml(mdTree, { + shortWikiLinks: this.client.config.get("shortWikiLinks", false), translateUrls: (url) => { if (isLocalURL(url)) { url = resolveMarkdownLink( diff --git a/client/codemirror/table.ts b/client/codemirror/table.ts index c676256a..963d4cf5 100644 --- a/client/codemirror/table.ts +++ b/client/codemirror/table.ts @@ -63,6 +63,7 @@ class TableViewWidget extends WidgetType { // Annotate every element with its position so we can use it to put // the cursor there when the user clicks on the table. annotationPositions: true, + shortWikiLinks: this.client.config.get("shortWikiLinks", false), translateUrls: (url) => { if (isLocalURL(url)) { url = resolveMarkdownLink( diff --git a/client/codemirror/wiki_link_processor.ts b/client/codemirror/wiki_link_processor.ts index 9d5eec20..8c9f5b44 100644 --- a/client/codemirror/wiki_link_processor.ts +++ b/client/codemirror/wiki_link_processor.ts @@ -28,6 +28,7 @@ export interface WikiLinkProcessorOptions { matchTo: number; client: Client; state: EditorState; + shortWikiLinks: boolean; callback: (e: MouseEvent, ref: any) => void; } @@ -95,7 +96,9 @@ export function processWikiLink(options: WikiLinkProcessorOptions): any[] { // We don't want to render the meta renderedRef.meta = false; // We also don't want to rendered the prefix of the path - renderedRef.path = fileName(renderedRef.path); + renderedRef.path = options.shortWikiLinks + ? fileName(renderedRef.path) + : renderedRef.path; const prefix = (ref.details?.type === "position" || ref.details?.type === "linecolumn") diff --git a/client/markdown_renderer/markdown_render.ts b/client/markdown_renderer/markdown_render.ts index 0fc33221..7b87b983 100644 --- a/client/markdown_renderer/markdown_render.ts +++ b/client/markdown_renderer/markdown_render.ts @@ -25,6 +25,7 @@ export type MarkdownRenderOptions = { smartHardBreak?: true; annotationPositions?: true; preserveAttributes?: true; + shortWikiLinks?: boolean; // When defined, use to inline images as data: urls translateUrls?: (url: string, type: "link" | "image") => string; expand?: true; @@ -296,7 +297,9 @@ function render( // Custom stuff case "WikiLink": { const link = findNodeOfType(t, "WikiLinkPage")!.children![0].text!; - let linkText = link.split("/").pop()!; + let linkText = options.shortWikiLinks === true + ? link.split("/").pop()! + : link; const aliasNode = findNodeOfType(t, "WikiLinkAlias"); if (aliasNode) { linkText = aliasNode.children![0].text!; diff --git a/libraries/Library/Std/Config.md b/libraries/Library/Std/Config.md index c4f4c9b2..48e28f22 100644 --- a/libraries/Library/Std/Config.md +++ b/libraries/Library/Std/Config.md @@ -81,6 +81,11 @@ config.define("autoCloseBrackets", { type = "string", }) +config.define("shortWikiLinks", { + description = "Render wiki links to just the last segment, e.g. Person/John becomes John", + type = "boolean" +}) + config.define("emoji", { description = "Additional emoji aliases", type = "object", @@ -372,6 +377,7 @@ config.set { task = { all = true }, }, taskStates = {}, + shortWikiLinks = true, actionButtons = { { icon = "home", diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index b11ff7f7..f6c44327 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -3,6 +3,7 @@ An attempt at documenting the changes/new features introduced in each release. ## Edge Whenever a commit is pushed to the `main` branch, within ~10 minutes, it will be released as a docker image with the `:v2` tag, and a binary in the [edge release](https://github.com/silverbulletmd/silverbullet/releases/tag/edge). If you want to live on the bleeding edge of SilverBullet goodness (or regression) this is where to do it. +* New `shortWikiLinks` config (defaulting to `true`) that decides whether a wiki link should be rendered in its short form (rendering just the last segment, e.g. `Person/John` would show as `John`). To always render the full name, put `config.set("shortWikiLinks", false)` in your [[CONFIG]]. * Upgraded dependencies, specifically CodeMirror. CodeMirror now no longer allows `Alt-` and `Alt-` [[Keyboard Shortcuts]], meaning I had to remap a few existing ones. It’s basically a mission impossible to pick great ones, but I tried: * `Quick note` is now bound to both `Ctrl-q q` (type `Ctrl-q` first, then hit `q` again) and `Ctrl-q Ctrl-q` (hit `Ctrl-q` twice) * `Navigate: Home` is now bound to `Ctrl-g h` @@ -19,7 +20,7 @@ Whenever a commit is pushed to the `main` branch, within ~10 minutes, it will be * `Page: Rename Linked Page` keyboard shortcut removed * `Sync: Space` keyboard shortcut removed * As documented in [[Keyboard Shortcuts]], it is now possible to specify _multiple_ keyboard shortcuts to a commands. -* Linked Mentions now list full page path rather than abbreviated version +* Linked Mentions now list full page path rather than abbreviated version. ## 2.4.0 * Indexer rework (note: upgrading will start a full space reindex automatically):