Giter Site home page Giter Site logo

fcrespo82 / vscode-markdown-table-formatter Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 8.0 1.35 MB

A (not so) simple Visual Studio Code markdown plugin to format tables and some other features.

Home Page: https://marketplace.visualstudio.com/items?itemName=fcrespo82.markdown-table-formatter

License: GNU General Public License v3.0

TypeScript 97.26% JavaScript 0.46% Python 2.22% PowerShell 0.06%
vscode vscode-extension openvsx open-vsx markdown formatter visual-studio-code visual-studio-code-extension hacktoberfest

vscode-markdown-table-formatter's Introduction

Markdown table formatter

Installs Downloads Rating

A (not so) simple markdown plugin to format tables and other table related features.

Changelog

Features

  • Format markdown tables
  • Sort tables
  • Organize columns moving it left/right

Usage

Uses VSCode Format Document and Format Selection

Settings

  • enable: Enable or disable the formatter;
  • enableSort: Enable or disable table sorter;
  • spacePadding: How many spaces between left and right of each column content;
  • keepFirstAndLastPipes: Keep first and last pipes "|" in table formatting. Tables are easier to format when pipes are kept;
  • defaultTableJustification: Defines the default justification for tables that have only "-" on the formatting line;
  • removeColonsIfSameAsDefault: Remove colons from the format line if the justification is the same as default;
  • globalColumnSizes: Format tables locally, with same column sizes or same table size;
  • delimiterRowPadding: Calculates the column sizes based on all tables on the document;
  • limitLastColumnLength: Control how the last column size is calculated;
  • sortCaseInsensitive: Sort table columns without considering text case;
  • allowEmptyLines: Format tables even if lines have less columns than header;
  • markdownGrammarScopes: File language grammar that will be considered Markdown by this package;
  • whichCodeLensesToShow: Control what is shown on CodeLens;

Tips

Enable Markdown Table Formatter for the current file type

To enable Markdown Table Formatter for your current file type: put your cursor in the file, open the Command Palette ^ (CONTROL)+⇧ (SHIFT)+P (⌘ (CMD)+⇧ (SHIFT)+P for mac), and run the Markdown Table Formatter: Enable for current language command. This will add language grammar from current editor to the list of languages in the settings for the Markdown Table Formatter package. You can edit this setting manually later if you want to.

Thanks

Thanks all users for the awesome community that was built here. I never imagined that this extension would be used by more than installs users with installs downloads.

Thanks for the support, bug reports and PRs!

Donating

If you like this extension, please consider donating and/or take a moment to write a review and share on Facebook or Twitter

vscode-markdown-table-formatter's People

Contributors

dependabot[bot] avatar fcrespo82 avatar quentiumyt 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

Watchers

 avatar  avatar  avatar

vscode-markdown-table-formatter's Issues

Formatting removes indentation of tables

If I have a table that is indented (for example: because it is part of a list):

* Stuff:
  | One | Two | Three |
  | --- | --- | ----- |
  | `1` | `2` | `3`   |
  • Stuff:
    One Two Three
    1 2 3

It gets incorrectly re-formatted to:

* Stuff:
| One | Two | Three |
| --- | --- | ----- |
| `1` | `2` | `3`   |
  • Stuff:
    | One | Two | Three |
    | --- | --- | ----- |
    | 1 | 2 | 3 |

Also, if the table starts on the same line as the list:

* | One | Two | Three |
  | --- | --- | ----- |
  | `1` | `2` | `3`   |
  • One Two Three
    1 2 3

It gets incorrectly re-formatted to:

| *   | One | Two | Three |
| --- | --- | --- | ----- |
| `1` | `2` | `3` |       |
* One Two Three
1 2 3

Invalid count value

settings: { "markdown-table-formatter.delimiterRowPadding": "Follow Space Padding" }

try to format:

a|c
-|-
c|d

=> Warning: Invalid count value

Sort - Ignore Case

It would be nice if sort could ignore the Case while Sorting.

I just used this awesome FOSS extension of urs to move columns & sort from this markdown table (~160 rows - massive for me in context of markdown tables) of Jupyter-kernels - and woah, it worked so fast & brilliantly. Now i have one less reason to use the Typora Markdown Editor

https://github.com/jupyter/jupyter/wiki/Jupyter-kernels

  • The capital letter was being placed ahead of small letter (likely ASCII) - I got around it by Making first letter capital of all offenders.
  • But it still tripped me where whole word had different cases: MATLAB vs Matlab

There was one more offender reason - the [ opening square bracket symbol in front of letters - though, this was pretty simple to overcome - as i just removed it & sorted again - then added [ it back.

makdown table formatter version 2.2.4 on vscodium

Add an option to choose table separators spacing

What I would like to propose is adding ability to have table separator to also be affected by the "How many spaces between left and right of each column content" setting.

The default behavior right now is the following. If the setting is set to 1, we don't have any padding:

|------|------|------|

What I would like it to be is the following:

| ------ | ------ | ------ |

It would be awesome to either have the existing option also affect that spacing or have another option that would control spacing of separators.

doesn't handle some emojis

As an example the following snippet is not changed.

| a   | b |
|-----|---|
| one | ❌ |

but most other emojis I've test do work.

please add back: Limit Last Column Padding

This is a super handy feature - i often have tables where the last column is a notes field, that occasionally contains lengthy text. This feature assured the rest of the table did not get blown out by these entries.

No other markdown table formatting library provided this capability

Unable to format with extension

Hi,

Thanks for this great extension - I've definitely used in a few months ago and found it invaluable. However recent versions seems to have stopped working (on just .md files).

Any tips on how to provider better logs for you to debug?

The only errors I see are:

When I try to format:
image

When I try to use the command pallette:
image

And I don't see a format selection option (not sure if it was there before though!)


Version: 2.1.5

Better data structure for tables

Today tables are represented by a anonymous object with match and range.

It would be better if it was a class that conformed to an interface?

Sort table lines

Function to sort table lines

  • Needs #9 first

Core funcionality done. Test sort algorithms to have the most performance.

Add "sort" in actions - available via command palette

The implementation for which column to sort according to - can be similar to how which column to move left/right is decided.

i.e. the column in which cursor currently is (ref: #10 (comment))

also, it would be nice to have an action for refresh sort. so that the currently chosen sort (whether ascending or descending) is applied again - rather than requiring toggle twice.

md-table formatter: v2.2.4 on vscodium

Really Slow Performance in `settings.json`

I recently experienced some severe lagginess when I opened settings.json, which I initially reported here: VSCodeVim/Vim/issues/5003. Feel free to check out the initial description and the screencast I made to see what was going on.

When I disabled this extension, all the lagginess I previously saw went away. I narrowed it down to this extension because the following message would load in the JS console every time that the UI became responsive again:

WARN UNRESPONSIVE extension host, 'fcrespo82.markdown-table-formatter' took 91% of 6207.224ms, saved PROFILE here: '/var/folders/h_/3f3z91t936q41d46hflhqq640000gn/T/exthost-739699.cpuprofile'

I copy/pasted the .cpuprofile file that it spit out, which is available below. I'm not exactly sure why this extension would be loading in a JSON document anyway, and I don't have any settings that force this extension to load, so it's a bit of a mystery. For the time being, I'm just going to completely disable this extension to get my performance back; hopefully you can figure out what's going on here.

File: /var/folders/h_/3f3z91t936q41d46hflhqq640000gn/T/exthost-739699.cpuprofile

Leading and trailing space when formatting without pipes

When formatting with the "Keep First And Last Pipes" option disabled, one space character is inserted before each line, and spaces are included at the end of each line up to the padding limit. IMO it would look better without (particularly the leading space).

Here's a copy-paste. It's much more pronounced if you see it in an editor that displays whitespace.

 Attribute  | Description                                      | Rules                                                                                           
------------|--------------------------------------------------|-------------------------------------------------------------------------------------------------
 vehicle_id | The driver's Vehicle Identification Number (VIN) | String of length 17. Raise an `ArgumentError` if it's the wrong length.                         
 status     | Is this `Driver` available to drive?             | Must be one of `:AVAILABLE` or `:UNAVAILABLE`                                                 
 trips      | A list of trips this driver has driven           | Optional parameter. If not provided, initialize to an empty array (similar to `Passenger`).

Exception: Cannot read property 'trim' of undefined

Hi,

at first thanks for that great extension - it is very useful and safes a lot time :)

Unfortunately since the last vscode update to version 1.43.2 I am getting a Cannot read property 'trim' of undefined exception when trying to format some documents - this does not happen on all documents. With your extension disabled I don't get this error. If you tell me how I can provide you more information for debugging this please tell me what you need ;-)

Would be very nice to get that fixed :)

Best regards!

Numeric sort in tables

I love the table sort feature! A helpful enhancement would be if columns containing integers or floats could be sorted numerically rather than alphanumerically. This would ensure a sort of 1, 2, 10 rather than 1, 10, 2.

Feature Request: Add CodeLens to format table

I think it would be really handy to have a link in the codelens to format the table.

I think it could be the first link in the code lens:

Format | column1 | column2 

It should also be possible to display the codelens with the formatting link, but without the sorting links.

Configuration option for delimiter row padding

Currently, the formatter doesn't pad the delimiter row:

|:----|-----|:---:|----:|

It would be nice to have this configurable, so it can be matched with a user's existing delimiter row style, e.g.:

"Space or alignment marker":

|:--- | --- |:---:| ---:|

"Single space always":

| :-- | --- | :-: | --: |

Allow backticked pipes (`|`) in tables

Love it, so far!

Issue: It doesn’t allow backticked pipes (|) in tables. For example:

Before:

| a        | b | c |
|:---------|:--|:--|
| fdasdfas | x `|` y | z |

After:

| a        | b   | c       |
|:---------|:----|:--------|
| fdasdfas | x ` | ` y | z |

Doesn't work

Can you post a quick example of how to use it that presumes the end user eats paste and crayons? #AskingForAFriend

What would be super helpful is example text on the plugin page in VSC that shows how to format and what buttons to press to get it to do its thing. Ex:

Header A | Header B | Header C
blah | blah | blah

then, press some key sequence and it'll automagically it'll look like this:

Header A | Header B | Header C
blah     | blah     | blah

I was hoping I could highlight the stuff I want to turn into a table, press command + shift + p (on a Mac) and find a markdown table formatter command that'll format. The only thing I see is setting it for the current language.

Feature request: Limit Last Column Width tied to header, not wordWrapColumn

What would make this formatter perfect for me would be to have a second option for Limit Last Column Width so that it has:

Limit Last Column Width:

  • () Do not extend last column to more than your editor's wordWrapColumn setting.
  • () Do not extend last column to more than the table's header row. <-- Feature Request

This would mean that short rows still line up with the header, but long rows can extend past the header. Then you don't have all kinds of extra whitespace that serves no purpose (and clutters up diffs). Also, without this feature, if you add a new row that's longer than the rest and reformat, every other row in the table will change as well (if it's less than the wordWrapColumn setting).

For example:

  • Before, Limit setting disabled:

    | App name   | Default status | Requirements                                                                                                                 |
    |------------|----------------|------------------------------------------------------------------------------------------------------------------------------|
    | App one    | Enabled        | None                                                                                                                         |
    | App ten    | Disabled       | Use on Thursdays                                                                                                             |
    | App twenty | Enabled        | If you are going to use this application, ensure you have fulfilled the prerequisites and can no longer use any other option |
  • Before, limit setting enabled, with 80 char wordWrapColumn seting:

    | App name   | Default status | Requirements                                   |
    |------------|----------------|------------------------------------------------|
    | App one    | Enabled        | None                                           |
    | App ten    | Disabled       | Use on Thursdays                               |
    | App twenty | Enabled        | If you are going to use this application, ensure you have fulfilled the prerequisites and can no longer use any other option |
  • After, with proposed feature:

    | App name   | Default status | Requirements |
    |------------|----------------|--------------|
    | App one    | Enabled        | None         |
    | App ten    | Disabled       | Use on Thursdays |
    | App twenty | Enabled        | If you are going to use this application, ensure you have fulfilled the prerequisites and can no longer use any other option |

Reorganize columns

Option to move columns around.

Should enter an edit mode?
Ask for column from and to?
Reorganize by column number? e.g.: 1,4,3,2

Support heading separator with Spaces/Tabs

for a long time, i thought this Extension doesn't work .

because it doesn't support 1 of the most justified syntaxes:

| <<name>>	| <<name>>	| <<name>>
| ---		| ---		| ---
| <<value>>	| <<value>>	| <<value>>

plz make it: recognize this and keep when Formatting . also would be good if it would support Tabs for indenting the next column, but thats not as important .

Wrong whitespace padding when formatting content with emojis

Trying to format a table with emoji results in wrong whitespace padding:

| First column | Second column | Third column |
|--------------|---------------|--------------|
| First row    | ✅             | ❌            |
| Second row   | ✅             | ❌            |

JavaScript assumes each Unicode character taking up 2 bytes, but some characters take up more bytes (for example emojis):

// This is wrong
'✅'.length === 2
> true

Using Intl.Segmenter fixes this issue:

// Much better!
[...new Intl.Segmenter().segment('✅')].length 
> 1

[...new Intl.Segmenter().segment('✅ hello world')].length
> 13

See also: How to count the correct length of a string with emojis in javascript?

Backtick-quoted pipe symbol misinterpreted as column boundary

Given the following table:

| Name              | Syntax               | Equivalent GLSL       |
|-------------------|----------------------|-----------------------|
| Negate            | `-a`                 | `-a`                  |
| Not               | `not a`              | `!a`                  |
| Sine              | `sin a`              | `sin(a)`              |
| Cosine            | `cos a`              | `cos(a)`              |
| Tangent           | `tan a`              | `tan(a)`              |
| InverseSine       | `asin a`             | `asin(a)`             |
| InverseCosine     | `acos a`             | `acos(a)`             |
| InverseTangent    | `atan a`             | `atan(a)`             |
| InverseTangent2   | `a atan b`           | `atan(a, b)`          |
| Exponential       | `exp a`              | `exp(a)`              |
| Logarithm         | `log a`              | `log(a)`              |
| Exponential2      | `exp2 a`             | `exp2(a)`             |
| Logarithm2        | `log2 a`             | `log2(a)`             |
| SquareRoot        | `sqrt a`             | `sqrt(a)`             |
| InverseSquareRoot | `inversesqrt a`      | `inversesqrt(a)`      |
| Absolute          | `abs a`              | `abs(a)`              |
| Sign              | `sign a`             | `sign(a)`             |
| Floor             | `floor a`            | `floor(a)`            |
| Ceiling           | `ceil a`             | `ceil(a)`             |
| Fractional        | `fract a`            | `fract(a)`            |
| Multiply          | `a * b`              | `a * b`               |
| Divide            | `a / b`              | `a / b`               |
| Add               | `a + b`              | `a + b`               |
| Subtract          | `a - b`              | `a - b`               |
| LessThan          | `a < b`              | `a < b`               |
| GreaterThan       | `a > b`              | `a > b`               |
| LessThanEqual     | `a <= b`             | `a <= b`              |
| GreaterThanEqual  | `a >= b`             | `a >= b`              |
| Equal             | `a is b`             | `a == b`              |
| NotEqual          | `a not b`            | `a != b`              |
| And               | `a && b`             | `a && b`              |
| Or                | `a || b`             | `a || b`              |
| Exponentiate      | `a pow b`            | `pow(a, b)`           |
| Modulo            | `a % b`              | `mod(a, b)`           |
| Minimum           | `a min b`            | `min(a, b)`           |
| Maximum           | `a max b`            | `max(a, b)`           |
| Conditional       | `a ? b : c`          | `a ? b : c`           |
| Clamp             | `a clamp b : c`      | `clamp(b, c, a)`      |
| Step              | `a step b`           | `step(b, a)`          |
| SmoothStep        | `a smoothstep b : c` | `smoothstep(b, c, a)` |
| LinearInterpolate | `a mix b : c`        | `mix(b, c, a)`        |

markdown-table-formatter will produce:

| Name              | Syntax               | Equivalent GLSL             |
|-------------------|----------------------|-----------------------------|
| Negate            | `-a`                 | `-a`                        |
| Not               | `not a`              | `!a`                        |
| Sine              | `sin a`              | `sin(a)`                    |
| Cosine            | `cos a`              | `cos(a)`                    |
| Tangent           | `tan a`              | `tan(a)`                    |
| InverseSine       | `asin a`             | `asin(a)`                   |
| InverseCosine     | `acos a`             | `acos(a)`                   |
| InverseTangent    | `atan a`             | `atan(a)`                   |
| InverseTangent2   | `a atan b`           | `atan(a, b)`                |
| Exponential       | `exp a`              | `exp(a)`                    |
| Logarithm         | `log a`              | `log(a)`                    |
| Exponential2      | `exp2 a`             | `exp2(a)`                   |
| Logarithm2        | `log2 a`             | `log2(a)`                   |
| SquareRoot        | `sqrt a`             | `sqrt(a)`                   |
| InverseSquareRoot | `inversesqrt a`      | `inversesqrt(a)`            |
| Absolute          | `abs a`              | `abs(a)`                    |
| Sign              | `sign a`             | `sign(a)`                   |
| Floor             | `floor a`            | `floor(a)`                  |
| Ceiling           | `ceil a`             | `ceil(a)`                   |
| Fractional        | `fract a`            | `fract(a)`                  |
| Multiply          | `a * b`              | `a * b`                     |
| Divide            | `a / b`              | `a / b`                     |
| Add               | `a + b`              | `a + b`                     |
| Subtract          | `a - b`              | `a - b`                     |
| LessThan          | `a < b`              | `a < b`                     |
| GreaterThan       | `a > b`              | `a > b`                     |
| LessThanEqual     | `a <= b`             | `a <= b`                    |
| GreaterThanEqual  | `a >= b`             | `a >= b`                    |
| Equal             | `a is b`             | `a == b`                    |
| NotEqual          | `a not b`            | `a != b`                    |
| And               | `a && b`             | `a && b`                    |
| Or                | `a                   | | b`             | `a || b` |
| Exponentiate      | `a pow b`            | `pow(a, b)`                 |
| Modulo            | `a % b`              | `mod(a, b)`                 |
| Minimum           | `a min b`            | `min(a, b)`                 |
| Maximum           | `a max b`            | `max(a, b)`                 |
| Conditional       | `a ? b : c`          | `a ? b : c`                 |
| Clamp             | `a clamp b : c`      | `clamp(b, c, a)`            |
| Step              | `a step b`           | `step(b, a)`                |
| SmoothStep        | `a smoothstep b : c` | `smoothstep(b, c, a)`       |
| LinearInterpolate | `a mix b : c`        | `mix(b, c, a)`              |

My interpretation of the fix for #1 was that it only fixed |, not anything|anything.

I think I might have a fix for this, will raise PR.

First and last pipe are not kept when sorting

First and last pipe are not kept when sorting even though the option is enabled.

Versions

Version: 1.55.2 (user setup)
Commit: 3c4e3df9e89829dce27b7b5c24508306b151f30d
Date: 2021-04-13T09:35:57.887Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19042

Shortcuts for move column right/left conflict with next/previous editor shortcuts on macOS

This is a follow-up on #16.

The markdown-table-formatter.moveColumnLeft command is mapped to cmd+alt+left, which is also the standard shortcut for Next Editor. I understand that it might be difficult to change the shortcut but maybe just changing "when": "editorTextFocus" to `"when": "editorTextFocus && editorLangId == 'markdown' " in https://github.com/fcrespo82/vscode-markdown-table-formatter/blob/master/package.json#L76 would already help.

The same problem arises for markdown-table-formatter.moveColumnRight.

Formatting bug: empty column headings

Before:

|                 |  |
|-----------------|---------|
| abc | defghi        |
|                 |         |
|                 |         |

After:

|-------------------|-----------|
| ----------------- | --------- |
| abc               | defghi    |
|                   |           |
|                   |           |
|                   |           ||

As soon as I insert a non-space in the first line, the table is formatted properly.

global table padding option

This is the current behavior

## Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
| Topic                      | Status    | Notes |
|----------------------------|-----------|-------|
| Is source control used?    | `NO`      |       |
| Are changes peer reviewed? | `PARTIAL` |       |


## Sed lacinia
Sed lacinia tortor et ultrices semper.
| Topic        | Status | Notes |
|--------------|--------|-------|
| Is Iot used? | `NO`   |       |

will be nice to have an option to globally pad the tables...
the final output will be:

## Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
| Topic                      | Status    | Notes |
|----------------------------|-----------|-------|
| Is source control used?    | `NO`      |       |
| Are changes peer reviewed? | `PARTIAL` |       |


## Sed lacinia
Sed lacinia tortor et ultrices semper.
| Topic                      | Status    | Notes |
|----------------------------|-----------|-------|
| Is Iot used?               | `NO`      |       |

Installation Problem

I have problems installing the extenseion in VS-Core 2020-07.23.
I don't get the "Enable" entry in the command palette.
When trying to format I get:
notificationsAlerts.ts:40 Command 'Markdown Table Formatter: Sort table by header' resulted in an error (command 'markdown-table-formatter.sortTable' not found)

nice to have: default option for justification

every markdown processor I have ever used has defaulted to align left, so I never use the justification syntax.

It would be nice, if we could choose default from the formatting options, and it would omit the :-

Mis-detecting code block as table

I'm on version v2.2.3, and it gives me the error:

Table at line 144 has a line with different column number as the header.

This is despite the line the error is on actually being a line in an indentation-based code block.

My Markdown source (with <---- error on this line added):

(Paragraph omitted) blah blah blah:

    with mask:
        # x y and out are all 16-bit so are subdivided at:
        # |      mask[0]     mask[1]     mask[3]         |
        # |  0-3    |    4-7    |   8-11    |   12-15    | <---- error on this line
        x = PartitionedSignal(16)    # identical except for mask
        y = PartitionedSignal(16)    # identical except for mask
        out = PartitionedSignal(16)  # identical except for mask

Backtick ` causes skipped cell

Using a backtick `, even when escaped \`, causes the formatting to skip a cell. Here's an example:

| symbol | name
|-|-
| " | quote
| « | left-pointing double angle quote
| \` | backtick

is formatted into

| symbol        | name                             |
|---------------|----------------------------------|
| "             | quote                            |
| «             | left-pointing double angle quote |
| \` | backtick |                                  |

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.