Пример #1
0
		static bool ProcessTags(string tag, Range tagRange, TagProcessor tagProcessor, bool isSingle = false)
		{
			var startTag = "<" + tag + ">";
			var endTag = "</" + tag + ">";

			var found = false;
			var range = tagRange.Duplicate;
			int startTagOffset;

			while(range.Start < range.End && (startTagOffset = range.Text.IndexOf(startTag)) != -1)
			{
				found = true;

				// Remove start tag
				range.Start += startTagOffset;
				DeleteChars(range, startTag.Length);

				if (!isSingle)
				{
					// Remove end tag
					var endTagOffset = range.Text.IndexOf(endTag);
					DeleteCharsAt(range, endTagOffset, endTag.Length);
					range.End = range.Start + endTagOffset;
				}
				else
				{
					range.End = range.Start;
				}

				// Process at tag position
				tagProcessor(tag, range);

				range.Start = tagRange.Start;
				range.End = tagRange.End;
			}

			return found;
		}
        protected override async Task PublishFileToDestinationAsync(FileInfo sourceFile, DirectoryInfo destinationRoot, DocFile page)
        {
            this.LogMessage(new ValidationMessage(sourceFile.Name, "Publishing file to HTML"));

            var destinationPath = this.GetPublishedFilePath(sourceFile, destinationRoot, HtmlOutputExtension);

            // Create a tag processor
            string tagsInput = PageParameters.ValueForKey<string>("tags", StringComparison.OrdinalIgnoreCase) ?? string.Empty;

            TagProcessor tagProcessor = new TagProcessor(tagsInput,
                page.Parent.SourceFolderPath, LogMessage);

            var converter = this.GetMarkdownConverter();
            var html = converter.Transform(tagProcessor.Preprocess(sourceFile));
            html = await tagProcessor.PostProcess(html, sourceFile, converter);

            var pageData = page.Annotation ?? new PageAnnotation();
            if (string.IsNullOrEmpty(pageData.Title))
            {
               pageData.Title = (from b in converter.Blocks
                             where b.BlockType == BlockType.h1
                             select b.Content).FirstOrDefault();
            }
            page.Annotation = pageData;
            await this.WriteHtmlDocumentAsync(html, page, destinationPath, destinationRoot.FullName);
        }
Пример #3
0
 protected virtual string GetContentsOfFile(string tags)
 {
     // Preprocess file content
     FileInfo docFile = new FileInfo(this.FullPath);
     TagProcessor tagProcessor = new TagProcessor(tags, Parent.SourceFolderPath);
     return tagProcessor.Preprocess(docFile);
 }