-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocxObjectRenderer.cs
More file actions
58 lines (51 loc) · 2.07 KB
/
DocxObjectRenderer.cs
File metadata and controls
58 lines (51 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Markdig.Helpers;
namespace Markdig.Renderer.Docx;
public abstract class DocxObjectRenderer<TObject> : IDocxObjectRenderer
where TObject : MarkdownObject
{
public virtual bool CanRender(MarkdownObject obj) => obj.GetType() == typeof(TObject) || obj is TObject;
public abstract void Write(IDocxRenderer owner, IDocument document, Paragraph currentParagraph, TObject obj);
void IDocxObjectRenderer.Write(IDocxRenderer owner, IDocument document, Paragraph currentParagraph, MarkdownObject obj)
=> Write(owner, document, currentParagraph, (TObject)obj);
public void WriteChildren(LeafBlock leafBlock, IDocxRenderer owner, IDocument document, Paragraph currentParagraph)
{
var inlines = leafBlock.Inline;
if (inlines != null)
{
foreach (var child in inlines)
{
Write(child, owner, document, currentParagraph);
}
}
if (leafBlock.Lines.Count > 0)
{
int index = 0;
int count = leafBlock.Lines.Count;
foreach (var text in leafBlock.Lines.Cast<StringLine>().Take(count))
{
currentParagraph.AddRange(Run.Create(Helpers.CleanText(text.ToString())));
if (++index < count)
currentParagraph.Newline();
}
}
}
public void WriteChildren(ContainerBlock container, IDocxRenderer owner, IDocument document, Paragraph currentParagraph)
{
foreach (var block in container)
{
Write(block, owner, document, currentParagraph);
}
}
public void WriteChildren(ContainerInline container, IDocxRenderer owner, IDocument document, Paragraph currentParagraph)
{
foreach (var inline in container)
{
Write(inline, owner, document, currentParagraph);
}
}
public void Write(MarkdownObject item, IDocxRenderer owner, IDocument document, Paragraph currentParagraph)
{
var renderer = owner.FindRenderer(item);
renderer?.Write(owner, document, currentParagraph, item);
}
}