Skip to content

Commit

Permalink
fixed base64 links
Browse files Browse the repository at this point in the history
  • Loading branch information
gcerik authored and MaxMelcher committed Jul 29, 2022
1 parent 3b883ec commit c4629c2
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions AzureDevOps.WikiPDFExport/MarkdownConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ public void CorrectLinksAndImages(MarkdownObject document, MarkdownFile mf)
{
string absPath = null;
string anchor = null;
bool isBase64 = false;

//handle --attachments-path case
if (
Expand Down Expand Up @@ -387,6 +388,10 @@ public void CorrectLinksAndImages(MarkdownObject document, MarkdownFile mf)
});
absPath = Path.GetFullPath(_wiki.basePath() + linkUrl);
}
else if (link.Url.StartsWith("data:"))
{
isBase64 = true;
}
else
{
var split = link.Url.Split("#");
Expand All @@ -397,24 +402,28 @@ public void CorrectLinksAndImages(MarkdownObject document, MarkdownFile mf)

//the file is a markdown file, create a link to it
var isMarkdown = false;
var fileInfo = new FileInfo(absPath);
if (fileInfo.Exists && fileInfo.Extension.Equals(".md", StringComparison.InvariantCultureIgnoreCase))
if (!isBase64)
{
isMarkdown = true;
}
else if (fileInfo.Exists)
{
//convert images to base64 and embed them in the html. Chrome/Puppeter does not show local files because of security reasons.
Byte[] bytes = File.ReadAllBytes(fileInfo.FullName);
String base64 = Convert.ToBase64String(bytes);

link.Url = $"data:image/{fileInfo.Extension};base64,{base64}";
}
var fileInfo = new FileInfo(absPath);
if (fileInfo.Exists && fileInfo.Extension.Equals(".md", StringComparison.InvariantCultureIgnoreCase))
{
isMarkdown = true;
}
else if (fileInfo.Exists)
{
//convert images to base64 and embed them in the html. Chrome/Puppeter does not show local files because of security reasons.
Byte[] bytes = File.ReadAllBytes(fileInfo.FullName);
String base64 = Convert.ToBase64String(bytes);

fileInfo = new FileInfo($"{absPath}.md");
if (fileInfo.Exists && fileInfo.Extension.Equals(".md", StringComparison.InvariantCultureIgnoreCase))
{
isMarkdown = true;
link.Url = $"data:image/{fileInfo.Extension};base64,{base64}";
}

fileInfo = new FileInfo($"{absPath}.md");
if (fileInfo.Exists && fileInfo.Extension.Equals(".md", StringComparison.InvariantCultureIgnoreCase))
{
isMarkdown = true;
}
}

//only markdown files get a pdf internal link
Expand Down

0 comments on commit c4629c2

Please sign in to comment.