MarkdownToOpenXML
MarkdownToOpenXML copied to clipboard
Functionality - Horizontal rules
This one should be fairly straight forward. If the line just contains -
's or *
's then insert a horizontal rule. Strip out whitespace in the check (allowing a pattern like - - - -
).
Horizontal rules in markdown How do I create horizontal rule in Word with open XML SDK?
@dangerdan I am working on this enhancement.
@dangerdan
OK, I have got the Horizontal rule being applied but the existing logic under "GenerateRuns" will not work for Horizontal Rules. For instance in MD Horizontal rules are usually specified as "---"
There is no text afterwards or before. So the position will always match the range but the buffer never gets filled before the total length reaches its limit and hence the Horizontal Rule rendering will never happen. For testing I wrote the rendering code outside the existing logic and the document rendered without issues. However, we need to figure out a better way of rendering the formatting elements in Open Xml.
Horizontal rules are block level elements in html, and in markdown they are only generated if they're the only thing on that line. So really the code needs to go into ParagraphBuilder for this.
For example, ---
outputs:
But --- hello
outputs:
--- hello
In paragraph builder, there needs to be a method called something like doHorizontalRule
, it should check the string member current
(the string representing the current paragraph) to see if it only has ---
's (or ***
's or - - - -
etc) . If it does, fill in the paragraph with a horizontal rule with OXML and empty the current
string (so other rules, including the rules in run builder, don't apply).
@dangerdan That's how I finished the implementation, but then it feels we are putting too much of code into ParagrahBuilder class and that defeats SRP of OOPS. I am working on making it truly generic.
@dangerdan commit done to a new branch "applyoo". I am still working on making the project more Object Oriented. However the Horizontal rule rendering code is in there. And I have included Unit Tests. When you get a chance please do a take a look at them, and let me know if it looks good.
Most of the unit test cases fail. I have put them as a place holder to improve the test coverage and features to the library.
@dangerdan did you get a chance to look at the branch ?