[Snippet] Add support to csv file, and auto convert to markdown table #2273
-
DescriptionHello, Currently, I can write a markdown syntaxed table in a markdown file, and inject it into another markdown file by using snippet feature like this:
The issue is that, if I have a big table of random_data, with long lines, the markdown table (the source code part) is less readable and editable. And I would like to see the Snippet extension can automatically convert the csv file to markdown table when rendering.
My current workaround is to keep the csv file, and during CICD process, I've a script to convert the csv to markdown. BenefitsMaking large markdown table more editable and readable during sourcering. Solution IdeaNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
People have various niche things they would love to have implemented, but I unfortunately do not have the time to provide custom solutions for everyone's niche needs. What you want can be accomplished within the existing framework. You can use a custom fence. I have a recent issue where I explored their niche case here: #2240. Essentially, you could inject your CSV in a code block, and with custom fences, provide your own CSV language type and process the CSV content any way that you'd like. You would need to write the processing and provide the function to the SuperFence extension as described in the documentation: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/#custom-fences.
Another option is to use the current block extension API to write you own custom block extension: https://facelessuser.github.io/pymdown-extensions/extensions/blocks/api/. I simply cannot provide custom solutions for everyone, sorry. |
Beta Was this translation helpful? Give feedback.
-
Thx a lot for the details ! |
Beta Was this translation helpful? Give feedback.
-
@facelessuser My tried this in my markdown file: ```csv
my_csv_path.csv
``` By using your example, I created a function But the probleme is that, say, in
I tried to return in 3 ways:
None of them works, the 3 first are shown as raw text (the value of |
Beta Was this translation helpful? Give feedback.
You still aren't giving me the root cause. Table sorting in Material is being done by a JS library once loading into the browser. So the JS library expects something in order to "prettify" the table. So that leads me to believe the output of
df.to_html
is different than what the Markdown table is rendered as. So my question is, what is the difference?Basically, you haven't properly debugged the why. The why is everything in understanding the issue. Alternatively, you can have panda output the Markdown and just run it through Python Markdown with the
tables
extension and then return the HTML that way.