public bool ImportHbp(string inputFile, string outputFolder = null, string kavaDocsAddinFolder = null) { if (kavaDocsAddinFolder == null) { kavaDocsAddinFolder = KavaDocsConfiguration.Current.HomeFolder; } if (outputFolder == null) { outputFolder = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(inputFile)); } if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } if (!Directory.Exists(Path.Combine(outputFolder, "images"))) { Directory.CreateDirectory(Path.Combine(outputFolder, "images")); } if (!string.IsNullOrEmpty(kavaDocsAddinFolder)) { FileUtils.CopyDirectory(Path.Combine(kavaDocsAddinFolder, "ProjectTemplates"), Path.Combine(outputFolder, "_kavadocs")); } else { if (!Directory.Exists(Path.Combine(outputFolder, "_kavadocs"))) { Directory.CreateDirectory(Path.Combine(outputFolder, "_kavadocs")); } } var oldTopics = JsonSerializationUtils.DeserializeFromFile(inputFile, typeof(List <HbpTopic>)) as List <HbpTopic>; var project = new DocProject(Path.Combine(outputFolder, "_toc.json")); var newTopics = new ObservableCollection <DocTopic>(); project.Topics = newTopics; foreach (var oldTopic in oldTopics) { if (oldTopic.pk == "CONFIG") { continue; } var newTopic = new DocTopic(project) { Id = oldTopic.pk, ParentId = oldTopic.parentpk, Title = oldTopic.topic, DisplayType = oldTopic.type?.ToLower(), Keywords = oldTopic.keywords, Remarks = oldTopic.remarks, Example = oldTopic.example, SeeAlso = oldTopic.seealso, SortOrder = oldTopic.sortorder, IsLink = oldTopic.external, Incomplete = oldTopic.followup, HelpId = oldTopic.helpid.ToString(), ClassInfo = new ClassInfo() { Syntax = string.IsNullOrEmpty(oldTopic.syntax) ? null : oldTopic.syntax, Classname = string.IsNullOrEmpty(oldTopic._class) ? null : oldTopic._class, MemberName = string.IsNullOrEmpty(oldTopic.method) ? null : oldTopic.method, Parameters = string.IsNullOrEmpty(oldTopic.parameters) ? null : oldTopic.parameters, Returns = string.IsNullOrEmpty(oldTopic.returns) ? null : oldTopic.returns, Scope = string.IsNullOrEmpty(oldTopic.scope) ? null : oldTopic.scope, Implements = string.IsNullOrEmpty(oldTopic.implements) ? null : oldTopic.implements, Inherits = string.IsNullOrEmpty(oldTopic.inherits) ? null : oldTopic.inherits, InheritanceTree = string.IsNullOrEmpty(oldTopic.inh_tree) ? null : oldTopic.inh_tree, Signature = string.IsNullOrEmpty(oldTopic.signature) ? null : oldTopic.signature, Assembly = oldTopic.assembly, Contract = oldTopic.contract, Namespace = oldTopic._namespace, Exceptions = oldTopic.exceptions, }, }; newTopic.Project = project; int format = oldTopic.viewmode; newTopic.Type = format == 2 ? TopicBodyFormats.Markdown : TopicBodyFormats.HelpBuilder; newTopic.SetBodyWithoutSavingTopicFile(oldTopic.body); // Properties have to be parsed out // BodyFormats project.Topics.Add(newTopic); } if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } // Copy images string sourceFolder = Path.GetDirectoryName(inputFile); KavaUtils.CopyDirectory(Path.Combine(sourceFolder, "Images"), Path.Combine(outputFolder, "images")); project.Title = Title; project.Owner = Owner; project.GetTopicTreeFromFlatList(project.Topics); // fix up image links relative to hierarchy project.WalkTopicsHierarchy(project.Topics, (topic, proj) => { string find = "](images/"; if (!topic.Body.Contains(find) || topic.Parent == null) { return; } int foldersDown = 0; var parent = topic.Parent; while (parent != null) { foldersDown++; parent = parent.Parent; } if (foldersDown < 1) { return; } string replace = "](" + new StringBuilder().Insert(0, "../", foldersDown) + "images/"; topic.Body = topic.Body.Replace(find, replace); }); return(project.SaveProject(Path.Combine(outputFolder, "_toc.json"))); }