diff --git a/docs/source/syntax/applies.md b/docs/source/syntax/applies.md index 679295ccc..b59ff0e52 100644 --- a/docs/source/syntax/applies.md +++ b/docs/source/syntax/applies.md @@ -48,7 +48,7 @@ applies: Are equivalent, note `all` just means we won't be rendering the version portion in the html. -## This section has its own applies annotations +## This section has its own applies annotations [#sections] :::{applies} :stack: unavailable diff --git a/docs/source/syntax/links.md b/docs/source/syntax/links.md index 4381acd62..7f66311ce 100644 --- a/docs/source/syntax/links.md +++ b/docs/source/syntax/links.md @@ -42,6 +42,32 @@ Cross links are links that point to a different docset. The syntax is `://`, where is the repository name and is the path to the file. +## Auto Text Links + +If you link to a local markdown file but omit any link text `docs-builder` will use the target's [title](titles.md). + +```markdown +[](applies.md) +``` +will output: [](applies.md) + +You can go one step further to auto generate link text for headings within files: + +```markdown +[](applies.md#sections) +``` + +will output: [](applies.md#sections) + +This also applies to local anchors + + +```markdown +[](#anchor-link) +``` + +will output: [](#anchor-link) + ## Heading anchors Headings will automatically create anchor links in the resulting html. diff --git a/docs/source/testing/index.md b/docs/source/testing/index.md index 8a1174dc7..0f334219e 100644 --- a/docs/source/testing/index.md +++ b/docs/source/testing/index.md @@ -2,4 +2,7 @@ title: Testing --- -The files in this directory are used for testing purposes. Do not edit these files unless you are working on tests. \ No newline at end of file +The files in this directory are used for testing purposes. Do not edit these files unless you are working on tests. + + +###### [#synthetics-config-file] diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index 69fed5b07..05ac7e43c 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -108,9 +108,20 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice) if (link.FirstChild == null || !string.IsNullOrEmpty(anchor)) { - var file = string.IsNullOrWhiteSpace(url) ? context.Path - : context.Build.ReadFileSystem.FileInfo.New(Path.Combine(context.Build.SourcePath.FullName, url.TrimStart('/'))); + var file = string.IsNullOrWhiteSpace(url) + ? context.Path + : url.StartsWith('/') + ? context.Build.ReadFileSystem.FileInfo.New(Path.Combine(context.Build.SourcePath.FullName, url.TrimStart('/'))) + : context.Build.ReadFileSystem.FileInfo.New(Path.Combine(context.Path.Directory!.FullName, url)); var markdown = context.GetDocumentationFile?.Invoke(file) as MarkdownFile; + if (markdown == null) + { + processor.EmitWarning(line, + column, + length, + $"'{url}' could not be resolved to a markdown file while creating an auto text link, '{file.FullName}' does not exist."); + } + var title = markdown?.Title; if (!string.IsNullOrEmpty(anchor))