示例#1
0
 private static IEnumerable<YamlHtmlPart> MarkupMultiple(IHostService host, string markdown, FileAndType ft)
 {
     try
     {
         var html = host.Markup(markdown, ft, true);
         var parts = YamlHtmlPart.SplitYamlHtml(html);
         foreach (var part in parts)
         {
             var mr = host.Parse(part.ToMarkupResult(), ft);
             part.Conceptual = mr.Html;
             part.LinkToFiles = mr.LinkToFiles;
             part.LinkToUids = mr.LinkToUids;
             part.YamlHeader = mr.YamlHeader;
             part.FileLinkSources = mr.FileLinkSources;
             part.UidLinkSources = mr.UidLinkSources;
         }
         return parts;
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Fail("Markup failed!");
         var message = $"Markup failed: {ex.Message}.";
         Logger.LogError(message);
         throw new DocumentException(message, ex);
     }
 }
示例#2
0
 private static IEnumerable <YamlHtmlPart> MarkupMultiple(IHostService host, string markdown, FileAndType ft)
 {
     try
     {
         var html  = host.Markup(markdown, ft, true);
         var parts = YamlHtmlPart.SplitYamlHtml(html);
         foreach (var part in parts)
         {
             var mr = host.Parse(part.ToMarkupResult(), ft);
             part.Conceptual      = mr.Html;
             part.LinkToFiles     = mr.LinkToFiles;
             part.LinkToUids      = mr.LinkToUids;
             part.YamlHeader      = mr.YamlHeader;
             part.FileLinkSources = mr.FileLinkSources;
             part.UidLinkSources  = mr.UidLinkSources;
         }
         return(parts);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Fail("Markup failed!");
         Logger.LogWarning($"Markup failed:{Environment.NewLine}  Markdown: {markdown}{Environment.NewLine}  Details:{ex.ToString()}");
         return(Enumerable.Empty <YamlHtmlPart>());
     }
 }
示例#3
0
 private static IEnumerable <YamlHtmlPart> MarkupMultiple(IHostService host, string markdown, FileAndType ft)
 {
     try
     {
         var html  = host.Markup(markdown, ft, true);
         var parts = YamlHtmlPart.SplitYamlHtml(html);
         foreach (var part in parts)
         {
             var mr = host.Parse(part.ToMarkupResult(), ft);
             part.Conceptual      = mr.Html;
             part.LinkToFiles     = mr.LinkToFiles;
             part.LinkToUids      = mr.LinkToUids;
             part.YamlHeader      = mr.YamlHeader;
             part.FileLinkSources = mr.FileLinkSources;
             part.UidLinkSources  = mr.UidLinkSources;
         }
         return(parts);
     }
     catch (Exception ex)
     {
         Debug.Fail("Markup failed!");
         var message = $"Markup failed: {ex.Message}.";
         throw new DocumentException(message, ex);
     }
 }
示例#4
0
        public override void Build(FileModel model, IHostService host)
        {
            if (model.Type != DocumentType.Article)
            {
                return;
            }
            var content  = (Dictionary <string, object>)model.Content;
            var markdown = (string)content[ConceptualKey];
            var result   = host.Markup(markdown, model.FileAndType);

            var htmlInfo = SeparateHtml(result.Html);

            model.Properties.IsUserDefinedTitle   = false;
            content[Constants.PropertyName.Title] = htmlInfo.Title;
            content["rawTitle"]    = htmlInfo.RawTitle;
            content[ConceptualKey] = htmlInfo.Content;

            if (result.YamlHeader != null && result.YamlHeader.Count > 0)
            {
                foreach (var item in result.YamlHeader)
                {
                    if (item.Key == Constants.PropertyName.Uid)
                    {
                        var uid = item.Value as string;
                        if (!string.IsNullOrWhiteSpace(uid))
                        {
                            model.Uids = new[] { new UidDefinition(uid, model.LocalPathFromRepoRoot) }.ToImmutableArray();
                            content[Constants.PropertyName.Uid] = item.Value;
                        }
                    }
                    else
                    {
                        content[item.Key] = item.Value;
                        if (item.Key == DocumentTypeKey)
                        {
                            model.DocumentType = item.Value as string;
                        }
                        if (item.Key == Constants.PropertyName.Title)
                        {
                            model.Properties.IsUserDefinedTitle = true;
                        }
                    }
                }
            }
            model.LinkToFiles         = result.LinkToFiles.ToImmutableHashSet();
            model.LinkToUids          = result.LinkToUids;
            model.Properties.XrefSpec = null;
            if (model.Uids.Length > 0)
            {
                model.Properties.XrefSpec = new XRefSpec
                {
                    Uid  = model.Uids[0].Name,
                    Name = TitleThumbnail(content[Constants.PropertyName.Title] as string ?? model.Uids[0].Name, TitleThumbnailMaxLength),
                    Href = ((RelativePath)model.File).GetPathFromWorkingFolder()
                };
            }
            host.ReportDependency(model, result.Dependency);
        }
 private string Markup(IHostService host, string markdown, FileModel model)
 {
     if (string.IsNullOrEmpty(markdown))
     {
         return markdown;
     }
     var mr = host.Markup(markdown, model.FileAndType);
     ((HashSet<string>)model.Properties.LinkToFiles).UnionWith(mr.LinkToFiles);
     ((HashSet<string>)model.Properties.LinkToUids).UnionWith(mr.LinkToUids);
     return mr.Html;
 }
示例#6
0
        private string Markup(IHostService host, string markdown, FileModel model)
        {
            if (string.IsNullOrEmpty(markdown))
            {
                return(markdown);
            }
            var mr = host.Markup(markdown, model.FileAndType);

            ((HashSet <string>)model.Properties.LinkToFiles).UnionWith(mr.LinkToFiles);
            ((HashSet <string>)model.Properties.LinkToUids).UnionWith(mr.LinkToUids);
            return(mr.Html);
        }
示例#7
0
        public override void Build(FileModel model, IHostService host)
        {
            if (model.Type != DocumentType.Article)
            {
                return;
            }
            var content  = (Dictionary <string, object>)model.Content;
            var markdown = (string)content[ConceputalKey];
            var result   = host.Markup(markdown, model.FileAndType);

            var htmlInfo = SeperateHtml(result.Html);

            content["title"]       = htmlInfo.Title;
            content["rawTitle"]    = htmlInfo.RawTitle;
            content[ConceputalKey] = htmlInfo.Content;

            if (result.YamlHeader != null && result.YamlHeader.Count > 0)
            {
                foreach (var item in result.YamlHeader)
                {
                    if (item.Key == "uid")
                    {
                        var uid = item.Value as string;
                        if (!string.IsNullOrWhiteSpace(uid))
                        {
                            model.Uids     = new[] { uid }.ToImmutableArray();
                            content["uid"] = item.Value;
                        }
                    }
                    else
                    {
                        content[item.Key] = item.Value;
                        if (item.Key == DocumentTypeKey)
                        {
                            model.DocumentType = item.Value as string;
                        }
                    }
                }
            }
            model.Properties.LinkToFiles = result.LinkToFiles;
            model.Properties.LinkToUids  = result.LinkToUids;
            model.Properties.XrefSpec    = null;
            if (model.Uids.Length > 0)
            {
                model.Properties.XrefSpec = new XRefSpec
                {
                    Uid  = model.Uids[0],
                    Name = TitleThumbnail(content["title"].ToString() ?? model.Uids[0], TitleThumbnailMaxLength),
                    Href = ((RelativePath)model.File).GetPathFromWorkingFolder()
                };
            }
            model.File = Path.ChangeExtension(model.File, ".json");
        }
        public override void Build(FileModel model, IHostService host)
        {
            if (model.Type != DocumentType.Article)
            {
                return;
            }
            var content = (Dictionary<string, object>)model.Content;
            var markdown = (string)content[ConceputalKey];
            var result = host.Markup(markdown, model.FileAndType);

            var htmlInfo = SeperateHtml(result.Html);
            content["title"] = htmlInfo.Title;
            content["rawTitle"] = htmlInfo.RawTitle;
            content[ConceputalKey] = htmlInfo.Content;

            if (result.YamlHeader != null && result.YamlHeader.Count > 0)
            {
                foreach (var item in result.YamlHeader)
                {
                    if (item.Key == "uid")
                    {
                        var uid = item.Value as string;
                        if (!string.IsNullOrWhiteSpace(uid))
                        {
                            model.Uids = new[] { uid }.ToImmutableArray();
                            content["uid"] = item.Value;
                        }
                    }
                    else
                    {
                        content[item.Key] = item.Value;
                        if (item.Key == DocumentTypeKey)
                        {
                            model.DocumentType = item.Value as string;
                        }
                    }
                }
            }
            model.Properties.LinkToFiles = result.LinkToFiles;
            model.Properties.LinkToUids = result.LinkToUids;
            model.Properties.XrefSpec = null;
            if (model.Uids.Length > 0)
            {
                model.Properties.XrefSpec = new XRefSpec
                {
                    Uid = model.Uids[0],
                    Name = TitleThumbnail(content["title"].ToString() ?? model.Uids[0], TitleThumbnailMaxLength),
                    Href = ((RelativePath)model.File).GetPathFromWorkingFolder()
                };
            }
            model.File = Path.ChangeExtension(model.File, ".json");
        }
        private static string Markup(IHostService host, string markdown, FileModel model, Func <string, bool> filter = null)
        {
            if (string.IsNullOrEmpty(markdown))
            {
                return(markdown);
            }

            if (filter != null && filter(markdown))
            {
                return(markdown);
            }

            var mr = host.Markup(markdown, model.OriginalFileAndType);

            model.LinkToFiles = model.LinkToFiles.Union(mr.LinkToFiles);
            model.LinkToUids  = model.LinkToUids.Union(mr.LinkToUids);

            var fls = model.FileLinkSources.ToDictionary(p => p.Key, p => p.Value);

            foreach (var pair in mr.FileLinkSources)
            {
                ImmutableList <LinkSourceInfo> list;
                if (fls.TryGetValue(pair.Key, out list))
                {
                    fls[pair.Key] = list.AddRange(pair.Value);
                }
                else
                {
                    fls[pair.Key] = pair.Value;
                }
            }
            model.FileLinkSources = fls.ToImmutableDictionary();

            var uls = model.UidLinkSources.ToDictionary(p => p.Key, p => p.Value);

            foreach (var pair in mr.UidLinkSources)
            {
                ImmutableList <LinkSourceInfo> list;
                if (uls.TryGetValue(pair.Key, out list))
                {
                    uls[pair.Key] = list.AddRange(pair.Value);
                }
                else
                {
                    uls[pair.Key] = pair.Value;
                }
            }
            model.UidLinkSources = uls.ToImmutableDictionary();

            return(mr.Html);
        }
示例#10
0
        /// <summary>
        /// TODO: merge with the one in BuildManagedReferenceDocument
        /// </summary>
        /// <param name="host"></param>
        /// <param name="markdown"></param>
        /// <param name="model"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static string Markup(IHostService host, string markdown, FileModel model, Func <string, bool> filter = null)
        {
            if (string.IsNullOrEmpty(markdown))
            {
                return(markdown);
            }

            if (filter != null && filter(markdown))
            {
                return(markdown);
            }

            var mr = host.Markup(markdown, model.FileAndType);

            ((HashSet <string>)model.Properties.LinkToFiles).UnionWith(mr.LinkToFiles);
            ((HashSet <string>)model.Properties.LinkToUids).UnionWith(mr.LinkToUids);
            return(mr.Html);
        }
示例#11
0
        private static string Markup(IHostService host, string markdown, FileModel model, Func <string, bool> filter = null)
        {
            if (string.IsNullOrEmpty(markdown))
            {
                return(markdown);
            }

            if (filter != null && filter(markdown))
            {
                return(markdown);
            }

            var mr = host.Markup(markdown, model.FileAndType);

            model.LinkToFiles = model.LinkToFiles.Union(mr.LinkToFiles);
            model.LinkToUids  = model.LinkToUids.Union(mr.LinkToUids);
            return(mr.Html);
        }
        public void Build(FileModel model, IHostService host)
        {
            if (model.Type != DocumentType.Article)
            {
                return;
            }
            var content  = (Dictionary <string, object>)model.Content;
            var markdown = (string)content[ConceputalKey];
            var result   = host.Markup(markdown, model.FileAndType);

            content[ConceputalKey] = result.Html;
            content["title"]       = result.Title;
            content["word_count"]  = WordCounter.CountWord(result.Html);
            if (result.YamlHeader != null && result.YamlHeader.Count > 0)
            {
                foreach (var item in result.YamlHeader)
                {
                    if (item.Key == "uid")
                    {
                        var uid = item.Value as string;
                        if (!string.IsNullOrWhiteSpace(uid))
                        {
                            model.Uids = new[] { uid }.ToImmutableArray();
                        }
                    }
                    else
                    {
                        content[item.Key] = item.Value;
                        if (item.Key == DocumentTypeKey)
                        {
                            model.DocumentType = item.Value as string;
                        }
                    }
                }
            }
            model.Properties.LinkToFiles = result.LinkToFiles;
            model.Properties.LinkToUids  = result.LinkToUids;
            model.File = Path.ChangeExtension(model.File, ".json");
        }
示例#13
0
        public override void Build(FileModel model, IHostService host)
        {
            if (model.Type != DocumentType.Article)
            {
                return;
            }
            var content = (Dictionary<string, object>)model.Content;
            var markdown = (string)content[ConceptualKey];
            var result = host.Markup(markdown, model.FileAndType);

            var htmlInfo = SeparateHtml(result.Html);
            model.Properties.IsUserDefinedTitle = false;
            content[Constants.PropertyName.Title] = htmlInfo.Title;
            content["rawTitle"] = htmlInfo.RawTitle;
            content[ConceptualKey] = htmlInfo.Content;

            if (result.YamlHeader != null && result.YamlHeader.Count > 0)
            {
                foreach (var item in result.YamlHeader)
                {
                    if (item.Key == Constants.PropertyName.Uid)
                    {
                        var uid = item.Value as string;
                        if (!string.IsNullOrWhiteSpace(uid))
                        {
                            model.Uids = new[] { new UidDefinition(uid, model.LocalPathFromRoot) }.ToImmutableArray();
                            content[Constants.PropertyName.Uid] = item.Value;
                        }
                    }
                    else
                    {
                        content[item.Key] = item.Value;
                        if (item.Key == DocumentTypeKey)
                        {
                            model.DocumentType = item.Value as string;
                        }
                        if (item.Key == Constants.PropertyName.Title)
                        {
                            model.Properties.IsUserDefinedTitle = true;
                        }
                    }
                }
            }
            model.LinkToFiles = result.LinkToFiles.ToImmutableHashSet();
            model.LinkToUids = result.LinkToUids;
            model.FileLinkSources = result.FileLinkSources;
            model.UidLinkSources = result.UidLinkSources;
            model.Properties.XrefSpec = null;
            if (model.Uids.Length > 0)
            {
                model.Properties.XrefSpec = new XRefSpec
                {
                    Uid = model.Uids[0].Name,
                    Name = TitleThumbnail(content[Constants.PropertyName.Title] as string ?? model.Uids[0].Name, TitleThumbnailMaxLength),
                    Href = ((RelativePath)model.File).GetPathFromWorkingFolder()
                };
            }

            foreach (var d in result.Dependency)
            {
                host.ReportDependencyTo(model, d, DependencyTypeName.Include);
            }
        }
示例#14
0
        public override void Build(FileModel model, IHostService host)
        {
            if (model.Type != DocumentType.Article)
            {
                return;
            }
            var content  = (Dictionary <string, object>)model.Content;
            var markdown = (string)content[ConceptualKey];
            var result   = host.Markup(markdown, model.OriginalFileAndType, false, true);

            var htmlInfo = HtmlDocumentUtility.SeparateHtml(result.Html);

            model.Properties.IsUserDefinedTitle   = false;
            content[Constants.PropertyName.Title] = htmlInfo.Title;
            content["rawTitle"] = htmlInfo.RawTitle;
            if (!string.IsNullOrEmpty(htmlInfo.RawTitle))
            {
                model.ManifestProperties.rawTitle = htmlInfo.RawTitle;
            }
            content[ConceptualKey] = htmlInfo.Content;

            if (result.YamlHeader?.Count > 0)
            {
                foreach (var item in result.YamlHeader)
                {
                    HandleKeyValuePair(item.Key, item.Value);
                }
            }
            model.LinkToFiles         = result.LinkToFiles.ToImmutableHashSet();
            model.LinkToUids          = result.LinkToUids;
            model.FileLinkSources     = result.FileLinkSources;
            model.UidLinkSources      = result.UidLinkSources;
            model.Properties.XrefSpec = null;
            if (model.Uids.Length > 0)
            {
                var title = content[Constants.PropertyName.Title] as string;
                model.Properties.XrefSpec = new XRefSpec
                {
                    Uid  = model.Uids[0].Name,
                    Name = string.IsNullOrEmpty(title) ? model.Uids[0].Name : title,
                    Href = ((RelativePath)model.File).GetPathFromWorkingFolder()
                };
            }

            foreach (var d in result.Dependency)
            {
                host.ReportDependencyTo(model, d, DependencyTypeName.Include);
            }

            void HandleKeyValuePair(string key, object value)
            {
                switch (key)
                {
                case Constants.PropertyName.Uid:
                    var uid = value as string;
                    if (!string.IsNullOrWhiteSpace(uid))
                    {
                        model.Uids = new[] { new UidDefinition(uid, model.LocalPathFromRoot) }.ToImmutableArray();
                        content[Constants.PropertyName.Uid] = value;
                    }
                    break;

                case DocumentTypeKey:
                    content[key]       = value;
                    model.DocumentType = value as string;
                    break;

                case Constants.PropertyName.Title:
                    if (value is string str && !string.IsNullOrEmpty(str))
                    {
                        content[key] = str;
                        model.Properties.IsUserDefinedTitle = true;
                    }
                    break;

                case Constants.PropertyName.OutputFileName:
                    content[key] = value;
                    var outputFileName = value as string;
                    if (!string.IsNullOrWhiteSpace(outputFileName))
                    {
                        string fn = null;
                        try
                        {
                            fn = Path.GetFileName(outputFileName);
                        }
                        catch (ArgumentException) { }
                        if (fn == outputFileName)
                        {
                            model.File = (RelativePath)model.File + (RelativePath)outputFileName;
                        }
                        else
                        {
                            Logger.LogWarning($"Invalid output file name in yaml header: {outputFileName}, skip rename output file.");
                        }
                    }
                    break;

                default:
                    content[key] = value;
                    break;
                }
            }
        }
示例#15
0
        private static string Markup(IHostService host, string markdown, FileModel model, Func<string, bool> filter = null)
        {
            if (string.IsNullOrEmpty(markdown))
            {
                return markdown;
            }

            if (filter != null && filter(markdown))
            {
                return markdown;
            }

            var mr = host.Markup(markdown, model.FileAndType);
            model.LinkToFiles = model.LinkToFiles.Union(mr.LinkToFiles);
            model.LinkToUids = model.LinkToUids.Union(mr.LinkToUids);

            var fls = model.FileLinkSources.ToDictionary(p => p.Key, p => p.Value);
            foreach (var pair in mr.FileLinkSources)
            {
                ImmutableList<LinkSourceInfo> list;
                if (fls.TryGetValue(pair.Key, out list))
                {
                    fls[pair.Key] = list.AddRange(pair.Value);
                }
                else
                {
                    fls[pair.Key] = pair.Value;
                }
            }
            model.FileLinkSources = fls.ToImmutableDictionary();

            var uls = model.UidLinkSources.ToDictionary(p => p.Key, p => p.Value);
            foreach (var pair in mr.UidLinkSources)
            {
                ImmutableList<LinkSourceInfo> list;
                if (uls.TryGetValue(pair.Key, out list))
                {
                    uls[pair.Key] = list.AddRange(pair.Value);
                }
                else
                {
                    uls[pair.Key] = pair.Value;
                }
            }
            model.UidLinkSources = uls.ToImmutableDictionary();

            return mr.Html;
        }
 public void Build(FileModel model, IHostService host)
 {
     if (model.Type != DocumentType.Article)
     {
         return;
     }
     var content = (Dictionary<string, object>)model.Content;
     var markdown = (string)content[ConceputalKey];
     var result = host.Markup(markdown, model.FileAndType);
     content[ConceputalKey] = result.Html;
     content["title"] = result.Title;
     content["word_count"] = WordCounter.CountWord(result.Html);
     if (result.YamlHeader != null && result.YamlHeader.Count > 0)
     {
         foreach (var item in result.YamlHeader)
         {
             if (item.Key == "uid")
             {
                 var uid = item.Value as string;
                 if (!string.IsNullOrWhiteSpace(uid))
                 {
                     model.Uids = new[] { uid }.ToImmutableArray();
                 }
             }
             else
             {
                 content[item.Key] = item.Value;
                 if (item.Key == DocumentTypeKey)
                 {
                     model.DocumentType = item.Value as string;
                 }
             }
         }
     }
     model.Properties.LinkToFiles = result.LinkToFiles;
     model.Properties.LinkToUids = result.LinkToUids;
     model.File = Path.ChangeExtension(model.File, ".json");
 }