Skip to content

Commit 326767c

Browse files
authored
Merge pull request #19 from MiroRadenovic/main
Check null for LinkInLine identified but without Url
2 parents 87a7670 + 35baec7 commit 326767c

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

AzureDevOps.WikiPDFExport/WikiPDFExporter.cs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -349,50 +349,52 @@ public void CorrectLinksAndImages(MarkdownObject document, FileInfo file, Markdo
349349
// and relative links to markdown pages
350350
foreach (var link in document.Descendants().OfType<LinkInline>())
351351
{
352-
if (!link.Url.StartsWith("http"))
352+
if (link.Url != null)
353353
{
354+
if (!link.Url.StartsWith("http"))
355+
{
354356

355-
string absPath = null;
357+
string absPath = null;
356358

357-
if (link.Url.StartsWith("/"))
358-
{
359-
absPath = Path.GetFullPath(_path + link.Url);
360-
}
361-
else
362-
{
363-
absPath = Path.GetFullPath(file.Directory.FullName + "/" + link.Url);
364-
}
365-
//the file is a markdown file, create a link to it
366-
var isMarkdown = false;
367-
var fileInfo = new FileInfo(absPath);
368-
if (fileInfo.Exists && fileInfo.Extension.Equals(".md", StringComparison.InvariantCultureIgnoreCase))
369-
{
370-
isMarkdown = true;
371-
}
372-
else if (fileInfo.Exists)
373-
{
374-
link.Url = $"file:///{absPath}";
375-
}
359+
if (link.Url.StartsWith("/"))
360+
{
361+
absPath = Path.GetFullPath(_path + link.Url);
362+
}
363+
else
364+
{
365+
absPath = Path.GetFullPath(file.Directory.FullName + "/" + link.Url);
366+
}
367+
//the file is a markdown file, create a link to it
368+
var isMarkdown = false;
369+
var fileInfo = new FileInfo(absPath);
370+
if (fileInfo.Exists && fileInfo.Extension.Equals(".md", StringComparison.InvariantCultureIgnoreCase))
371+
{
372+
isMarkdown = true;
373+
}
374+
else if (fileInfo.Exists)
375+
{
376+
link.Url = $"file:///{absPath}";
377+
}
376378

377-
fileInfo = new FileInfo($"{absPath}.md");
378-
if (fileInfo.Exists && fileInfo.Extension.Equals(".md", StringComparison.InvariantCultureIgnoreCase))
379-
{
380-
isMarkdown = true;
381-
}
379+
fileInfo = new FileInfo($"{absPath}.md");
380+
if (fileInfo.Exists && fileInfo.Extension.Equals(".md", StringComparison.InvariantCultureIgnoreCase))
381+
{
382+
isMarkdown = true;
383+
}
382384

383-
//only markdown files get a pdf internal link
384-
if (isMarkdown)
385-
{
386-
var relPath = mf.RelativePath + "\\" + link.Url;
387-
relPath = relPath.Replace("/", "\\");
388-
relPath = relPath.Replace("\\", "");
389-
relPath = relPath.Replace(".md", "");
390-
relPath = relPath.ToLower();
391-
Log($"\tMarkdown link: {relPath}");
392-
link.Url = $"#{relPath}";
385+
//only markdown files get a pdf internal link
386+
if (isMarkdown)
387+
{
388+
var relPath = mf.RelativePath + "\\" + link.Url;
389+
relPath = relPath.Replace("/", "\\");
390+
relPath = relPath.Replace("\\", "");
391+
relPath = relPath.Replace(".md", "");
392+
relPath = relPath.ToLower();
393+
Log($"\tMarkdown link: {relPath}");
394+
link.Url = $"#{relPath}";
395+
}
393396
}
394397
}
395-
396398
CorrectLinksAndImages(link, file, mf);
397399
}
398400
}

0 commit comments

Comments
 (0)