From a2c3166cf9fcd6c62d693f6669752693b0ffe9be Mon Sep 17 00:00:00 2001 From: Moritz Jung Date: Tue, 5 Nov 2024 21:34:59 +0100 Subject: [PATCH] fix markdown link parser not handling section links --- exampleVault/Buttons/In Note Navigation.md | 67 +++++++++++++++++++ .../core/src/parsers/MarkdownLinkParser.ts | 8 ++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 exampleVault/Buttons/In Note Navigation.md diff --git a/exampleVault/Buttons/In Note Navigation.md b/exampleVault/Buttons/In Note Navigation.md new file mode 100644 index 00000000..5d590952 --- /dev/null +++ b/exampleVault/Buttons/In Note Navigation.md @@ -0,0 +1,67 @@ +## This is a Heading at the Top + +```meta-bind-button +label: Scroll to Middle +style: default +actions: + - type: open + link: "[[#This is a Heading in the Middle]]" + newTab: false + +``` + +some + +very + +long + +text + +some + +very + +long + +text + +## This is a Heading in the Middle + +some + +very + +long + +text + +some + +very + +long + +text + +some + +very + +long + +text + +some + +very + +long + +text + +## This is a Heading at the Bottom + + +Some Secion +^section-1 \ No newline at end of file diff --git a/packages/core/src/parsers/MarkdownLinkParser.ts b/packages/core/src/parsers/MarkdownLinkParser.ts index fdf06911..10d84fbf 100644 --- a/packages/core/src/parsers/MarkdownLinkParser.ts +++ b/packages/core/src/parsers/MarkdownLinkParser.ts @@ -8,7 +8,13 @@ import { isUrl, openURL } from 'packages/core/src/utils/Utils'; const P_MDLinkInner: Parser<[string, string | undefined, string | undefined]> = P.sequence( P_FilePath, // the file path - P.string('#').then(P.manyNotOf('[]#|^:')).optional(), // the optional heading + P.or( + P.string('#^') + .then(P.manyNotOf('[]#|^:')) + .map(x => '^' + x), // the optional block + P.string('#').then(P.manyNotOf('[]#|^:')), // the optional heading + P.succeed(undefined), + ), P.string('|').then(P.manyNotOf('[]')).optional(), // the optional alias );