kgar / ts-markdown

An extensible TypeScript markdown generator that takes JSON and creates a markdown document
https://kgar.github.io/ts-markdown/
MIT License
10 stars 4 forks source link

Added "pipeReplacer" and "prefixCellValues" options to table entries. #46

Closed skleinjung closed 4 months ago

skleinjung commented 5 months ago

pipeReplacer: This option supports use cases that require a different mechanism for escaping pipes within tables. For example, including an Obsidian link with a display name requires escaping with a slash (i.e. "|") instead of using an HTML entity.

prefixCellValues: The default table rendering is to include the "prefix" string before the value in every table cell, in addition to prefixing each individual table row. This option allows this behavior to be disabled, so that cell values are not prefixed. (It is possible the default behavior is a bug, but by providing a flag to change it this PR maintains backwards compatibility.)


Combined, these options allow me to use the default table entry to render ITS Theme infoboxes which contain fully-functional Obsidian links. An example of the type of output I want (which is a table embedded in a blockquote) is:

> [!infobox|wikipedia no-table-header center wm-sm static]
> 
> # 5th Month of the Year
> 
> ###### woopieo
> 
> | abc       | def                                                         |
> | --------- | ----------------------------------------------------------- |
> | Season    | [[Database/Calendar/seasons/Spring.md\|Mid Spring]]         |
> | Length    | 29 days                                                     |
> | Wysendays | - Smithing                                                  |
> | Moon Sign | [[Database/Calendar/moon signs/Knight's Moon.md\|Knight's]] |
> | New On    | 5th day                                                     |
> | Full On   | 19th day                                                    |
> 
> ###### Boopio
> 
> | abc         | def                                                |
> | ----------- | -------------------------------------------------- |
> | Preceded by | [[Database/Calendar/months/Symswald.md\|Symswald]] |
> | Followed by | [[Database/Calendar/months/Iggwyld.md\|Iggwyld]]   |
skleinjung commented 5 months ago

These are the changes I'm running with locally to meet my requirements. I figured I would submit a PR to start a conversation on incorporating some version of these capabilities upstream. I'm definitely open to more holistic approaches if you have a better plan than just adding new options like this.

kgar commented 5 months ago

This is awesome. I'll dig into this soon and try to get it pushed through and released. Thank you for contributing!