Skip to content

Commit 18a7357

Browse files
authored
Merge pull request #84 from gravesp/main
Fix (possibly hack) such that internal .md file links anchors are created correctly...
2 parents 001d2de + 8b99421 commit 18a7357

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

AzureDevOps.WikiPDFExport/WikiPDFExporter.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Markdig.Parsers;
2323
using Markdig.Extensions.Yaml;
2424
using Markdig.Helpers;
25+
using Microsoft.TeamFoundation.Common;
2526
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
2627
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
2728
using Microsoft.VisualStudio.Services.Client;
@@ -36,7 +37,8 @@ public class WikiPDFExporter : IWikiPDFExporter
3637
{
3738
private Options _options;
3839
private TelemetryClient _telemetryClient;
39-
private string _path;
40+
private string _path; //Starting path of the export tree of files - note this may be below the root of the wiki (the path ending ....wiki/)
41+
private string _rootWikiPath; //The path to the root of the wiki
4042
private Dictionary<string, string> _iconClass;
4143

4244
public WikiPDFExporter(Options options)
@@ -120,6 +122,11 @@ public async Task Export()
120122
_path = Path.GetFullPath(_path);
121123
}
122124

125+
// Set _rootWikiPath...
126+
var split = _path.Split(".wiki");
127+
_rootWikiPath = split[0].IsNullOrEmpty() ? _path : split[0] + ".wiki";
128+
129+
123130
List<MarkdownFile> files = null;
124131
if (!string.IsNullOrEmpty(_options.Single))
125132
{
@@ -668,7 +675,7 @@ public void CorrectLinksAndImages(MarkdownObject document, FileInfo file, Markdo
668675
//urls could be encoded and contain spaces - they are then not found on disk
669676
var linkUrl = HttpUtility.UrlDecode(link.Url);
670677
linkUrl = linkUrl.Replace("#", "-");
671-
absPath = Path.GetFullPath(_path + linkUrl);
678+
absPath = Path.GetFullPath(_rootWikiPath + linkUrl);
672679
}
673680
else
674681
{
@@ -708,7 +715,12 @@ public void CorrectLinksAndImages(MarkdownObject document, FileInfo file, Markdo
708715
//remove anchor
709716
relPath = relPath.Split("#")[0];
710717

718+
711719
relPath = relPath.Replace("/", "\\");
720+
// remove relative part if we are not exporting from the root of the wiki
721+
var pathBelowRootWiki = _path.Replace(_rootWikiPath, "");
722+
if( !pathBelowRootWiki.IsNullOrEmpty())
723+
relPath = relPath.Replace(pathBelowRootWiki, "");
712724
relPath = relPath.Replace("\\", "");
713725
relPath = relPath.Replace(".md", "");
714726
relPath = relPath.ToLower();

0 commit comments

Comments
 (0)