protected override void Write(OpenXMLRenderer renderer, CodeBlock obj) { renderer.PushParagraphFormat(FormatStyle.CodeBlock); var paragraph = renderer.PushNewParagraph(); if (obj.Inline != null) { // there was a post-processor which has already processed the lines in this code block renderer.WriteChildren(obj.Inline); } else // there was no post-processor - we have to do the writing of the code lines { // original code: renderer.WriteLeafRawLines(obj); // Expand this call directly here in order to be able to include tags var lines = obj.Lines; if (lines.Lines != null) { var slices = lines.Lines; for (var i = 0; i < lines.Count; i++) { var run = renderer.Push(new Run(new DocumentFormat.OpenXml.Wordprocessing.Text() { Text = slices[i].Slice.ToString(), Space = SpaceProcessingModeValues.Preserve })); renderer.PopTo(run); if (i < lines.Count - 1) { run = renderer.Push(new Run(new Break())); renderer.PopTo(run); } } } } renderer.PopTo(paragraph); renderer.PopParagraphFormat(); }
protected override void Write(OpenXMLRenderer renderer, HeadingBlock obj) { FormatStyle id; switch (obj.Level) { case 1: id = FormatStyle.Heading1; break; case 2: id = FormatStyle.Heading2; break; case 3: id = FormatStyle.Heading3; break; case 4: id = FormatStyle.Heading4; break; case 5: id = FormatStyle.Heading5; break; case 6: id = FormatStyle.Heading6; break; case 7: id = FormatStyle.Heading7; break; case 8: id = FormatStyle.Heading8; break; case 9: id = FormatStyle.Heading9; break; default: throw new NotImplementedException(); } renderer.PushParagraphFormat(id); var paragraph = renderer.PushNewParagraph(); renderer.WriteLeafInline(obj); renderer.PopTo(paragraph); renderer.PopParagraphFormat(); renderer.AddBookmarkIfNeccessary(obj, paragraph); }
protected override void Write(OpenXMLRenderer renderer, Markdig.Extensions.Figures.FigureCaption obj) { if (null != renderer.FigureCaptionList) { var idx = renderer.FigureCaptionList.FindIndex(x => object.ReferenceEquals(x.FigureCaption, obj)); if (idx >= 0) { renderer.CurrentFigureCaptionListIndex = idx; } } renderer.PushParagraphFormat(FormatStyle.Caption); var paragraph = renderer.PushNewParagraph(); renderer.WriteLeafInline(obj); renderer.PopTo(paragraph); renderer.PopParagraphFormat(); renderer.CurrentFigureCaptionListIndex = null; }
/// <summary> /// Adds the list items. /// </summary> /// <param name="renderer">The renderer.</param> /// <param name="listBlock">The list block for which the items should be added.</param> /// <param name="level">The current level of this list (1= main list, 2 = first sub list, etc.)</param> /// <param name="numberId">The unique identifier identifying this list. Note: it is the same identifier independent on the level.</param> public void AddListItems(OpenXMLRenderer renderer, ListBlock listBlock, int level, int numberId) { foreach (var item in listBlock) { // Create items for paragraph properties renderer.PushParagraphFormat(FormatStyle.ListParagraph); renderer.NumberingProperties = new NumberingProperties(new NumberingLevelReference() { Val = level - 1 }, new NumberingId() { Val = numberId }); var listItem = (ListItemBlock)item; renderer.WriteChildren(listItem); renderer.NumberingProperties = null; renderer.PopParagraphFormat(); } }
protected override void Write(OpenXMLRenderer renderer, QuoteBlock obj) { renderer.PushParagraphFormat(FormatStyle.QuoteBlock); renderer.WriteChildren(obj); renderer.PopParagraphFormat(); }