22
22
using Markdig . Parsers ;
23
23
using Markdig . Extensions . Yaml ;
24
24
using Markdig . Helpers ;
25
+ using Microsoft . TeamFoundation . Common ;
25
26
using Microsoft . TeamFoundation . WorkItemTracking . WebApi ;
26
27
using Microsoft . TeamFoundation . WorkItemTracking . WebApi . Models ;
27
28
using Microsoft . VisualStudio . Services . Client ;
@@ -36,7 +37,8 @@ public class WikiPDFExporter : IWikiPDFExporter
36
37
{
37
38
private Options _options ;
38
39
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
40
42
private Dictionary < string , string > _iconClass ;
41
43
42
44
public WikiPDFExporter ( Options options )
@@ -120,6 +122,11 @@ public async Task Export()
120
122
_path = Path . GetFullPath ( _path ) ;
121
123
}
122
124
125
+ // Set _rootWikiPath...
126
+ var split = _path . Split ( ".wiki" ) ;
127
+ _rootWikiPath = split [ 0 ] . IsNullOrEmpty ( ) ? _path : split [ 0 ] + ".wiki" ;
128
+
129
+
123
130
List < MarkdownFile > files = null ;
124
131
if ( ! string . IsNullOrEmpty ( _options . Single ) )
125
132
{
@@ -668,7 +675,7 @@ public void CorrectLinksAndImages(MarkdownObject document, FileInfo file, Markdo
668
675
//urls could be encoded and contain spaces - they are then not found on disk
669
676
var linkUrl = HttpUtility . UrlDecode ( link . Url ) ;
670
677
linkUrl = linkUrl . Replace ( "#" , "-" ) ;
671
- absPath = Path . GetFullPath ( _path + linkUrl ) ;
678
+ absPath = Path . GetFullPath ( _rootWikiPath + linkUrl ) ;
672
679
}
673
680
else
674
681
{
@@ -708,7 +715,12 @@ public void CorrectLinksAndImages(MarkdownObject document, FileInfo file, Markdo
708
715
//remove anchor
709
716
relPath = relPath . Split ( "#" ) [ 0 ] ;
710
717
718
+
711
719
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 , "" ) ;
712
724
relPath = relPath . Replace ( "\\ " , "" ) ;
713
725
relPath = relPath . Replace ( ".md" , "" ) ;
714
726
relPath = relPath . ToLower ( ) ;
0 commit comments