Giter VIP home page Giter VIP logo

csvtomd's Introduction

csvtomd: markdown tables made easy

The Python project is discontinued

Thanks for all your contributions! At this time I'm not continuing development on the Python version of this tool.

I'm moving work to the following JS projects:

I'm happy to point to your projects if you decide to take over development on the Python version or create a CLI for the JS version! Just let me know.


Excel โ€”> Markdown

CircleCI

Convert your CSV files into Markdown tables.

Tables Generator is a fantastic web tool for converting tabular data into all sorts of table layouts. I like how it lets me import CSV files, but I need the ability to convert many CSV files in batch for a docset on which I'm working.

I built csvtomd to convert one or more CSV files into nicely-padded Markdown tables. Now you can build your tables in Excel and convert them for use in GitHub Markdown files without having to construct them by hand.

Installation

This is a Python 3 script, so use pip3 to install:

pip3 install csvtomd

After this, run csvtomd --help from your terminal to verify it's installed properly.

Usage

csvtomd MY_SPREADSHEET.csv generates a Markdown table from MY_SPREADSHEET.csv.

csvtomd SHEET1.csv SHEET2.csv SHEET3.csv generates three Markdown tables from the input files and displays them alongside the input filename.

csvtomd or csvtomd - generates a Markdown table from standard input. You can type CSV data or pipe a file in.

Example Input

File: thrones.csv

First Name,Last Name,Location,Allegiance
Mance,Rayder,North of the Wall,Wildlings
Margaery,Tyrell,The Reach,House Tyrell
Danerys,Targaryen,Meereen,House Targaryen
Tyrion,Lannister,King's Landing,House Lannister

Example Markdown Table

Command: csvtomd thrones.csv

First Name Last Name Location Allegiance
Mance Rayder North of the Wall Wildlings
Margaery Tyrell The Reach House Tyrell
Danerys Targaryen Meereen House Targaryen
Tyrion Lannister King's Landing House Lannister

Example Raw Output

Command: csvtomd thrones.csv

First Name  |  Last Name  |  Location           |  Allegiance
------------|-------------|---------------------|-----------------
Mance       |  Rayder     |  North of the Wall  |  Wildlings
Margaery    |  Tyrell     |  The Reach          |  House Tyrell
Danerys     |  Targaryen  |  Meereen            |  House Targaryen
Tyrion      |  Lannister  |  King's Landing     |  House Lannister

Command: csvtomd --padding 0 thrones.csv

First Name|Last Name|Location         |Allegiance
----------|---------|-----------------|---------------
Mance     |Rayder   |North of the Wall|Wildlings
Margaery  |Tyrell   |The Reach        |House Tyrell
Danerys   |Targaryen|Meereen          |House Targaryen
Tyrion    |Lannister|King's Landing   |House Lannister

Requirements

Python 3.

Tested with Python 3.4.1 on Mac OS X 10.9.3.

Doesn't require any external packages, so it should be platform-agnostic.

Help

Command: csvtomd --help

usage: csvtomd.py [-h] [-n] [-p PADDING] [-d DELIMITER] csv_file [csv_file ...]

Read one or more CSV files and output their contents in the form of Markdown
tables.

positional arguments:
  csv_file              One or more CSV files to be converted

optional arguments:
  -h, --help            show this help message and exit
  -n, --no-filenames    Don't display filenames when outputting multiple
                        Markdown tables.
  -p PADDING, --padding PADDING
                        The number of spaces to add between table cells and
                        column dividers. Default is 2 spaces.
  -d DELIMITER, --delimiter DELIMITER
                        CSV delimiter, expected values: ',', ';'. Default is ,

Contributions

Bug reports, fixes, or features? Feel free to open an issue or pull request any time.

Testing

I only accept pull requests for features with tests.

# Run tests in the project root
$ py.test
============================= test session starts ==============================
platform darwin -- Python 3.5.0, pytest-3.0.5, py-1.4.31, pluggy-0.4.0
rootdir: /your/path/to/csvtomd, inifile:
collected 3 items

test/test_csvtomd.py ...

=========================== 3 passed in 0.04 seconds ===========================

Releasing

# Bump version number in setup.py and csvtomd.py
# Delete old builds
rm -rf dist
# Build source and binary wheel distribution
python setup_wrap.py sdist bdist_wheel
# Upload to PyPI
pip install twine
twine upload dist/*

Here's an actual guide to PyPI. And another really good one.

License

Copyright (c) 2017 Matthew Lewis. Licensed under the MIT License.

csvtomd's People

Contributors

kedrigern avatar mplewis avatar murphyke avatar prillan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csvtomd's Issues

Newline in csv cell is not converted into newline in markdown table.

Newline inside csv cell is not converted into newline in markdown table.

  • Input:
First Name,Last Name,Location,Allegiance
Mance,Rayder,"North 
of 
the Wall",Wildlings
Margaery,Tyrell,"The Reach",House Tyrell
Danerys,Targaryen,"Meereen",House Targaryen
Tyrion,Lannister,"King's Landing",House Lannister
  • Output:
First Name  |  Last Name  |  Location             |  Allegiance
------------|-------------|-----------------------|-----------------
Mance       |  Rayder     |  North 
of 
the Wall  |  Wildlings
Margaery    |  Tyrell     |  The Reach            |  House Tyrell
Danerys     |  Targaryen  |  Meereen              |  House Targaryen
Tyrion      |  Lannister  |  King's Landing       |  House Lannister
  • Desired:
First Name  |  Last Name  |  Location             |  Allegiance
------------|-------------|-----------------------|-----------------
Mance       |  Rayder     |  North <br/> of <br/> the Wall  |  Wildlings
Margaery    |  Tyrell     |  The Reach            |  House Tyrell
Danerys     |  Targaryen  |  Meereen              |  House Targaryen
Tyrion      |  Lannister  |  King's Landing       |  House Lannister

If I send a pull request on this issue, do you still review and hopefully merge that?

Not getting the latest version

Hi there

I'm pretty new to github, so please forgive me if this is a silly question, but I've installed csvtomd using the included instructions and have received this version:

Metadata-Version: 2.0 Name: csvtomd Version: 0.1.1 Summary: Convert your CSV files into Markdown tables. Home-page: https://github.com/mplewis/csvtomd Author: Matthew Lewis Author-email: [email protected] Installer: pip License: MIT Location: /usr/local/lib/python3.5/site-packages Requires: Classifiers: Development Status :: 5 - Production/Stable Natural Language :: English License :: OSI Approved :: MIT License Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3.4 Topic :: Text Processing :: Markup Entry-points: [console_scripts] csvtomd = csvtomd:main

I've used the 'upgrade' option for pip3 to verify that this is the latest version, and pip3 tells me this is the case. However, when running the command, I get the following:

usage: csvtomd [-h] [-n] [-p PADDING] csv_file [csv_file ...]

This is missing the delimiter option that I know has been added.

I'm obviously doing something wrong! Could you help me out?

Cheers

Ian

adding a way to escape pipes in input

Thanks for the great tool!
I have input with pipe symbols which are later interpreted as column delimiters.
would be cool to have the option to escape them during conversion.

Dropping a note to say thanks!!!!

Found this package 26 minutes after your latest release. It's amazing. Thanks so much for taking the time to put it up! I might make a pandoc filter building off your work.

TypeError: csv_to_table() missing 1 required positional argument: 'delimiter'

Hi, I am using latest released csvtomd, v. 0.2.0 from pypi on OS X with Python 3.5.2:

$ pip show csvtomd
Name: csvtomd
Version: 0.2.0
Summary: Convert your CSV files into Markdown tables.
Home-page: https://github.com/mplewis/csvtomd
Author: Matthew Lewis
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.5/site-packages
Requires:

$ which csvtomd
/usr/local/bin/csvtomd

$ head -n1 /usr/local/bin/csvtomd
#!/usr/local/opt/python3/bin/python3.5

$ /usr/local/opt/python3/bin/python3.5 --version
Python 3.5.2

..and it breaks when trying to use with:

$ csvtomd input.csv
Traceback (most recent call last):
  File "/usr/local/bin/csvtomd", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/site-packages/csvtomd/csvtomd.py", line 136, in main
    table = csv_to_table(f)
TypeError: csv_to_table() missing 1 required positional argument: 'delimiter'

Please help.

IndexErrors occur when files with uneven row-length are parsed

Example file contents:

a,b,c
d,e
f,g,h

Traceback:

Traceback (most recent call last):
  File "./csvtomd.py", line 126, in <module>
    print(md_table(csv, padding=args.padding))
  File "./csvtomd.py", line 79, in md_table
    row[cell_num] = pad_to(cell, col_sizes[cell_num])
IndexError: list index out of range

Issue when calling csvtomd function

I just installed csvtomd and have the following issue when trying to call the function csvtomd doc.csv > doc.md.

Traceback (most recent call last):
  File "/opt/conda/envs/python2/bin/csvtomd", line 11, in <module>
    load_entry_point('csvtomd==0.2.1', 'console_scripts', 'csvtomd')()
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/pkg_resources/__init__.py", line 561, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2631, in load_entry_point
    return ep.load()
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2291, in load
    return self.resolve()
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2297, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/csvtomd/__init__.py", line 1, in <module>
    from .csvtomd import *
  File "/opt/conda/envs/python2/lib/python2.7/site-packages/csvtomd/csvtomd.py", line 79
    def md_table(table, *, padding=1, divider='|', header_div='-'):
                         ^
SyntaxError: invalid syntax

support delimiter of tab '\t'

Support the entry of delimiter of TAB. The user should be able to run the below command

csvtomd mycsv.csv -d '\t'

Document for using md_table directly in python

Although it's quite obvious by reading the source code, but it would be great to add a section like this in README.md:

from csvtomd import md_table

table_2d_array = [["First Name", "Last Name", "Location" , "Allegiance"],
["Mance", "Rayder", "North of the Wall",  "Wildlings"],
["Margaery", "Tyrell",  "The Reach",  "House Tyrell"],
["Danerys", "Targaryen",  "Meereen", "House Targaryen"],
["Tyrion", "Lannister",  "King's Landing",  "House Lannister"]]

md_table(table_2d_array)
"""
('First Name  |  Last Name  |  Location           |  Allegiance\n'
 '------------|-------------|---------------------|-----------------\n'
 'Mance       |  Rayder     |  North of the Wall  |  Wildlings\n'
 'Margaery    |  Tyrell     |  The Reach          |  House Tyrell\n'
 'Danerys     |  Targaryen  |  Meereen            |  House Targaryen\n'
 "Tyrion      |  Lannister  |  King's Landing     |  House Lannister")
"""

Because I have already spent that five minutes, other people don't have to.

Column dividers open and close each row

Some applications (e.g. JIRA) require Markdown table rows to be opened and closed with the pipe character.

This can easily be fixed by piping output through sed 's/^/| /g;s/$/ |/g'. However, it would be helpful if this tool had an option to add these characters to the beginning and end of each row without requiring sed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.