コード例 #1
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);
        }