Giter Site home page Giter Site logo

commonmark-ext-table's Introduction

CommonMark Table Extension

Latest Version Build Status Code Quality Code Coverage

DEPRECATED

This extension has been deprecated. All of its functionality now exists in league/commonmark 1.3+ under the League\CommonMark\Extension\Table namespace, so you should upgrade to that version and use that bundled extension instead of this one.

Overview

The Table extension adds the ability to create tables in CommonMark documents.

Installation

This project can be installed via Composer:

composer require league/commonmark-ext-table

Usage

Configure your Environment as usual and simply add the TableExtension provided by this package:

use League\CommonMark\Converter;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use League\CommonMark\Ext\Table\TableExtension;

// Obtain a pre-configured Environment with all the standard CommonMark parsers/renderers ready-to-go
$environment = Environment::createCommonMarkEnvironment();

// Add this extension
$environment->addExtension(new TableExtension());

// Instantiate the converter engine and start converting some Markdown!
$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));

echo $converter->convertToHtml('# Hello World!');

Syntax

This package is fully compatible with GFM-style tables:

Simple

Code:

th | th(center) | th(right)
---|:----------:|----------:
td | td         | td

Result:

<table>
<thead>
<tr>
<th style="text-align: left">th</th>
<th style="text-align: center">th(center)</th>
<th style="text-align: right">th(right<)/th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">td</td>
<td style="text-align: center">td</td>
<td style="text-align: right">td</td>
</tr>
</tbody>
</table>

Advanced

| header 1 | header 2 | header 2 |
| :------- | :------: | -------: |
| cell 1.1 | cell 1.2 | cell 1.3 |
| cell 2.1 | cell 2.2 | cell 2.3 |

Table caption

header 1 | header 2
-------- | --------
cell 1.1 | cell 1.2
[Simple table]

Code:

header 1 | header 2
-------- | --------
cell 1.1 | cell 1.2
[*Prototype* table][reference_table]

Result:

<table>
<caption id="reference_table"><em>Prototype</em> table</caption>
<thead>
<tr>
<th>header 1</th>
<th>header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>cell 1.1</td>
<td>cell 1.2</td>
</tr>
</tbody>
</table>
<table>

Changelog

Please refer to the CHANGELOG for more information on what has changed recently.

Development

You need to have php or docker installed to develop the library. To list all available commands run:

./run

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

This library is licensed under the MIT license. See the License File for more information.

commonmark-ext-table's People

Contributors

baijunyao avatar colinodell avatar glensc avatar hason avatar michalbundyra avatar nanaya avatar onigoetz avatar rcole5 avatar rejinka avatar shulard avatar yenyasinn 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

commonmark-ext-table's Issues

caption and table id

Table caption isn't a part of MD standard, but it would be great if (optionally) we are able to define it (and table id too). Do you intend to allow optional non-standard syntax?

A possible approach is to get information like https://github.com/fletcher/MultiMarkdown propose here https://fletcher.github.io/MultiMarkdown-4/tables.html

| Head 1  | Head 2  | Head 3  |
| ------- | ------- | ------- |
| cel 1 a | cel 2 a | cel 3 a |
| cel 1 b | cel 2 b | cel 3 b |
[Caption Text][table-id]

Move to the PHP League?

Hey @hason,

We're looking to make league/commonmark-extras be fully compatible with GFM. We have pretty much everything we need except for table functionality.

Would you have any interest in bringing this project into the PHP League as league/commonmark-ext-tables? If so, I'd be happy to have you as a co-maintainer!

Bringing this into the League could offer several advantages:

  • It'll be easier to keep this up-to-date, especially with work being done in the core engine
    • We did this for our other official extensions - everything was ready on the release date
  • More maintainers = faster issue remediation
  • We can bring it into the league/commonmark-extras meta-package, thus greatly increasing the number of people using this

I'd be willing to do virtually all of the work to change the namespace, add to Packagist, etc. We did this with another community extension (the strikethrough one) and that seemed to go really well, so I'd like to offer you that same opportunity if you're interested. The only bit I'd really need from you is marking the current package as deprecated once everything has been moved over.

Just let me know! :)

support 0.19

Is it possible to update this extension to support thephpleague/commonmark
0.19? Thanks! :)

Cursor::getFirstNonSpacePosition() deprecated since 0.15.4

Starting with CommonMark 0.15.4, the function Cursor::getFirstNonSpacePosition() triggers a deprecation notice.

See thephpleague/commonmark#280

#0 unknown:unknown ErrorException("/var/www/vendor/league/commonmark/src/Cursor.php:79 Cursor::getFirstNonSpacePosition() will be removed in a future 0.x release. Use getNextNonSpacePosition() instead. See https://github.com/thephpleague/commonmark/issues/280")
#1 /vendor/league/commonmark/src/Cursor.php:79 trigger_error('Cursor::getFirstNonSpacePositi…', 16384)
#2 /vendor/webuni/commonmark-table-extension/src/TableParser.php:40 getFirstNonSpacePosition()
#3 /vendor/league/commonmark/src/DocParser.php:192 parse([Context], [Cursor])
#4 /vendor/league/commonmark/src/DocParser.php:107 parseBlocks([Context], [Cursor])
#5 /vendor/league/commonmark/src/DocParser.php:83 incorporateLine([Context])
#6 /vendor/league/commonmark/src/Converter.php:59 parse('Image downloaded from 

Conflict between colons and tables

Hi,

I have spotted an issue in Daux.io which uses your library and I have
been asked to report it here.

It seems that there is a problem when parsing colons before a table.

Please have a look at the following example

text1

:

| a | b |
| --- | --- |
| 1 | 2 |

text2

The table is not formatted correctly, and everything before the second dash
separator is truncated.

If I use the HTML entity for colon, it works fine:

text1

&#58;

| a | b |
| --- | --- |
| 1 | 2 |

text2

Also, a colon after the table works correctly:

text1

| a | b |
| --- | --- |
| 1 | 2 |

:

text2

Thanks

Integration with Laravel-Markdown

Trying to use Laravel-Markdown, which is a CommonMark wrapper for Laravel 5.

It appears that the Laravel-Markdown package is working properly - HTML is being rendered from md files as expected. However, it appears the commonmark-table-extension is not being integrated completely - tables are not rendering - just the plain text.

For more details: GrahamCampbell/Laravel-Markdown#66

Misc 2.0.0 tasks

  • Review the README, combine it with our usual structure for CommonMark extensions
  • Add a link to this on our main commonmark repo
  • Add this to the league/commonmark-extras library
  • Other stuff?

Does it work with commonmark .14?

Is there any known issue of this may not be working in the latest version? It can be my installation but I can't seem to get table working, only empty table tag is printed out, all other table content are printed as paragraphs style.

Update

How to update to the latest commonmark?

License change?

I'm thinking of bringing all of the "official" League extensions into the main library so that everyone can use things like tables out-of-the-box without needing additional packages. This will make it MUCH easier to test extension compatibility each time we release a new version of league/commonmark too.

To do this, we'd probably want to change the license of this library from MIT to BSD-3-Clause so that everything is using the same license.

@hason What are your thoughts on this?

Table rendered with empty <td>

Hey!

Noticed that if there is a closing | the extension will output an extra empty <td>

Example:

| Th 1 | Th 2 | Th 3 |     | 
|------|------|------|-----| 
| td1  | td2  | td3  | td4 | 

Outputs:

<table>
<thead>
<tr>
<th>Th 1</th>
<th>Th 2</th>
<th>Th 3</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>td1</td>
<td>td2</td>
<td>td3</td>
<td>td4</td>
<td></td>
</tr>
</tbody>
</table>

If I change the markdown and remove the ending pipe it works as expected:

| Th 1 | Th 2 | Th 3 |     | 
|------|------|------|-----|
| td1  | td2  | td3  | td4 <!-- removed pipe here -->

The reason I'm asking this is because many other markdown renderers accept the above behaviour, maybe it's not part of the spec that this extension is referring to.

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.