haltcase / tablemark Goto Github PK
View Code? Open in Web Editor NEWGenerate markdown tables from JSON data.
License: MIT License
Generate markdown tables from JSON data.
License: MIT License
Trying to apply some prams as per example below, but seems does not work
import * as table from "tablemark";
const items = [
{ name: “a”, id: “1” },
{ name: “b”, id: “2” }
]
table(items, { caseHeaders: false, wrap: {width: 1, gutters: false}});
Any ideas?
👌
Hi,
tablemark([])
will throw:
TypeError: Cannot convert undefined or null to object
Maybe there's a reason for it but IMO it would be more convenient to return an empty string.
Nice tool! Any thoughts how this might be used in VS Code / MD-based note taking environment?
The use case I have in mind is referring to a local JSON file with some kind of tag, and import the the markdown output from tablemark within a markdown file.
The current method of converting to strings does not take newlines into consideration, which are probably not that uncommon. The current state of "newlines in markdown tables" seems pretty bad from a quick search on the internet.
Current:
echo '{"message":"Wr\nong"}' | tablemark
| Message |
| ------- |
| Wr
ong |
\n
with <br />
:| Message | Code |
| ----------- | ----- |
| Wr<br />ong | 2 |
Message | Code |
---|---|
Wr ong |
2 |
| Message | Code |
| ------- | ----- |
| Wr | 2 |
| ong | |
| Good | 0 |
Message | Code |
---|---|
Wr | 2 |
ong | |
Good | 0 |
| Message | Code |
| ------- | ----- |
| Wr | 2 |
ong
| Good | 0 |
Message | Code |
---|---|
Wr | 2 |
ong | |
Good | 0 |
Since only the first produces valid markdown (GitHub-usable), I think that should definitely be an option. Apart from that consideration, I'm mostly into the last one (wrapping and aligning but without gutters/separators).
My rough proposal is:
Wrap at newlines and after any 80 characters run. Do not add gutters and separators, but align content. Provide an option to tweak characters per line or disable automatic line wrapping. Provide an option to replace newlines with <br />
and disable any wrapping.
I'm missing the latest fixes :-)
Hi and thanks for the great library,
I noticed
tablemark([{foo: null}, {foo: null}, {foo: null}], { padHeaderSeparator: true })
Will generate
| Foo |
| :---- | // 4 dashes
| null |
| null |
| null |
instead of
| Foo |
| :--- | // 3 dashes
| null |
| null |
| null |
This triggers a reformat on VSC and Sublime.
Hello!
Nice little lib.
Unfortunately, WebStorm complains about the formatting of the headers:
| first name | how old | are they cool |
| :--------- | :-----: | :------------ |
It seems it would prefer:
| first name | how old | are they cool |
|:-----------|:-------:|:--------------|
Could we add an option for that?
Looking at the code, a post-generation regex around line 49 would probably be simplest option:
separator.replace(/ (:?\-+:?) /g, (all, inner) => inner.replace('-', '---'))
I'm happy to PR this.
The os
module is only used to retrieve the system EOL, requiring a patch such as the one I commented on here to work in other environments:
plesk@3dbca4b#commitcomment-52865560
I'm thinking maybe make EOL configurable, then either wrap require('os') in a try/catch (would that prevent this error?) to get a default or get rid of it entirely and just default to \n.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.