protected string RelativeUrlFromCurrentPage(DocFile docFile, string destinationFile, string rootDestinationFolder, string optionalBookmark = null) { string linkDestinationRelative = docFile.DisplayName.TrimStart(new char[] { '\\', '/' }); var relativeLinkToDocFile = DocSet.RelativePathToRootFromFile(destinationFile, Path.Combine(rootDestinationFolder, linkDestinationRelative), true); var result = this.QualifyUrl(relativeLinkToDocFile); if (optionalBookmark != null) { result += optionalBookmark; } return(result); }
public override void GetText(TextWriter writer, Dictionary <string, object> arguments, Scope context) { var filenameToReplace = arguments["filename"] as string; if (null != filenameToReplace) { var relativeFileUrl = DocSet.RelativePathToRootFromFile( this.DestinationFile, Path.Combine(this.RootDestinationFolder, filenameToReplace), true); writer.Write(relativeFileUrl); } }
/// <summary> /// Apply the HTML template to the parameters and write the file to the destination. /// </summary> /// <param name="bodyHtml"></param> /// <param name="page"></param> /// <param name="destinationFile"></param> /// <param name="rootDestinationFolder"></param> /// <returns></returns> protected virtual async Task WriteHtmlDocumentAsync(string bodyHtml, DocFile page, string destinationFile, string rootDestinationFolder) { List <string> variablesToReplace = new List <string>(); string pageHtml = null; if (this.TemplateHtml != null) { var matches = ExtensionMethods.PathVariableRegex.Matches(this.TemplateHtml); variablesToReplace.AddRange(from Match match in matches select match.Groups[0].Value); string templateHtmlForThisPage = this.TemplateHtml; foreach (var key in variablesToReplace.ToArray()) { if (key == "{page.title}") { templateHtmlForThisPage = templateHtmlForThisPage.Replace(key, page.Annotation.Title); } else if (key == "{body.html}") { templateHtmlForThisPage = templateHtmlForThisPage.Replace(key, bodyHtml); } else if (key.StartsWith("{if ")) { string value = this.ParseDocumentIfStatement(key, destinationFile); templateHtmlForThisPage = templateHtmlForThisPage.Replace(key, value); } else { string filename = key.Substring(1, key.Length - 2); string value = DocSet.RelativePathToRootFromFile(destinationFile, Path.Combine(rootDestinationFolder, filename), true); templateHtmlForThisPage = templateHtmlForThisPage.Replace(key, value); } } pageHtml = templateHtmlForThisPage; } else { pageHtml = string.Concat(string.Format(HtmlHeader, page.Annotation.Title, HtmlStyles), bodyHtml, HtmlFooter); } pageHtml = await this.ConvertLineEndingsAsync(pageHtml, this.OutputLineEndings); using (var outputWriter = new StreamWriter(destinationFile)) { await outputWriter.WriteAsync(pageHtml); } }