Skip to content

Commit 42b03e2

Browse files
committed
Implement basic RTF parser
1 parent 1c05cd2 commit 42b03e2

File tree

11 files changed

+295
-56
lines changed

11 files changed

+295
-56
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ Forked:
6060
- [markdig.docx](https://github.com/morincer/markdig.docx)
6161

6262
Others:
63-
- [Html2OpenXml](https://github.com/onizet/html2openxml) for images header decoding and unit conversions.
64-
- [dwml_cs](https://github.com/m-x-d/dwml_cs) for Office Math (OMML) to LaTex conversion
65-
- [addFormula2docx](https://github.com/Sun-ZhenXing/addFormula2docx) for Office Math (OMML) to MathML conversion
66-
- [OpenMcdf](https://github.com/ironfede/openmcdf) for better understanding Microsoft Compound format.
63+
- [Html2OpenXml](https://github.com/onizet/html2openxml) for images header decoding and unit conversions.
64+
- [dwml_cs](https://github.com/m-x-d/dwml_cs) for Office Math (OMML) to LaTex conversion
65+
- [addFormula2docx](https://github.com/Sun-ZhenXing/addFormula2docx) for Office Math (OMML) to MathML conversion
66+
- [OpenMcdf](https://github.com/ironfede/openmcdf) for better understanding Microsoft Compound format.
67+
- [RtfPipe](https://github.com/erdomke/RtfPipe) and [FridaysForks.RtfPipe](https://github.com/cezarypiatek/FridaysForks.RtfPipe) for part of the RTF parsing logic.
6768

6869
Used in the sample app or for internal tests/comparisons (*not* dependencies when installing packages):
69-
- [RtfPipe](https://github.com/erdomke/RtfPipe)
7070
- [XlsxToHtmlConverter](https://github.com/Fei-Sheng-Wu/XlsxToHtmlConverter)
7171
- [PeachPdf](https://github.com/jhaygood86/PeachPDF)
7272
- [HTML-Renderer](https://github.com/ArthurHub/HTML-Renderer)

src/DocSharp.Docx/Helpers/SectionHelpers.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ public static class SectionHelpers
6363

6464
return sections;
6565
}
66+
67+
// Needed for DOCX to EPUB conversion. Rather than using sections, it detects paragraph heading styles.
68+
internal static List<(List<OpenXmlElement> content, string title)> GetChapters(this Body body)
69+
{
70+
// TODO
71+
return [];
72+
}
6673
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
namespace DocSharp.Rtf;
22

3-
internal class RtfControlWord(string name) : RtfToken
3+
internal class RtfControlWord : RtfToken
44
{
5-
public string Name { get; set; } = name;
5+
public string Name { get; set; }
6+
public int? Value { get; set; }
7+
public bool HasValue { get; set; }
8+
public bool DelimitedBySpace { get; set; }
9+
public RtfControlWord(string name)
10+
{
11+
Name = name;
12+
}
613
}
714

src/DocSharp.Docx/RtfToDocx/RtfControlWordWithValue.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
namespace DocSharp.Rtf;
22

3-
internal class RtfDestination(string name) : RtfGroup(name)
3+
internal class RtfDestination : RtfGroup
44
{
5+
public string Name { get; }
6+
7+
public RtfDestination(string name)
8+
{
9+
Name = name ?? string.Empty;
10+
}
511
}
612

src/DocSharp.Docx/RtfToDocx/RtfDocument.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ namespace DocSharp.Rtf;
44

55
internal class RtfDocument
66
{
7-
internal IEnumerable<RtfToken> Tokens = [];
7+
public RtfGroup Root { get; } = new RtfGroup();
88
}
9-

src/DocSharp.Docx/RtfToDocx/RtfGroup.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
namespace DocSharp.Rtf;
44

5-
internal class RtfGroup : RtfControlWord
5+
internal class RtfGroup : RtfToken
66
{
7-
internal IEnumerable<RtfToken> Tokens;
8-
9-
public RtfGroup(string name) : base(name)
10-
{
11-
Tokens = [];
12-
}
7+
public List<RtfToken> Tokens { get; } = new List<RtfToken>();
8+
public RtfGroup() { }
139
}
1410

0 commit comments

Comments
 (0)