MarkdownToOpenXML icon indicating copy to clipboard operation
MarkdownToOpenXML copied to clipboard

Functionality - Horizontal rules

Open danbroooks opened this issue 11 years ago • 7 comments

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?

danbroooks avatar Aug 06 '13 08:08 danbroooks

@dangerdan I am working on this enhancement.

vikramjb avatar Apr 08 '14 08:04 vikramjb

@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.

vikramjb avatar Apr 08 '14 11:04 vikramjb

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

danbroooks avatar Apr 08 '14 16:04 danbroooks

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).

danbroooks avatar Apr 08 '14 17:04 danbroooks

@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.

vikramjb avatar Apr 09 '14 02:04 vikramjb

@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.

vikramjb avatar Apr 09 '14 09:04 vikramjb

@dangerdan did you get a chance to look at the branch ?

vikramjb avatar Apr 16 '14 22:04 vikramjb