fletcher / MultiMarkdown-4

This project is now deprecated. Please use MultiMarkdown-6 instead!
https://github.com/fletcher/MultiMarkdown-5
Other
307 stars 59 forks source link

Syntax proposal for tables #50

Open mn4367 opened 10 years ago

mn4367 commented 10 years ago

Looking at issue #49 it seems that 'correct' column alignment isn't possible with the indicators in the alignment/divider line alone. The following syntax proposal could help. The basic idea is to allow individual cell alignment by using colons in a similar same way they are used in the alignment/divider line:

|    Col A    |    Col B    |    Col C    |
| ----------- | ----------- | ----------- |
|   Cell 1A   |:  Cell 1B  :|   Cell 1C  :|
|:  Cell 2A   |:  Cell 2B               :||

The alignment of Cell 1A is driven by the system as before, Cell 1B is centered, Cell 1C is right aligned, Cell 2A is left aligned and Cell 2B is centered.

|    Col X    |    Col Y    |    Col Z    |
| :---------- | :---------: | ----------: |
|   Cell 1X   |   Cell 1Y   |   Cell 1Z   |
|   Cell 2X  :|:  Cell 2Y   |:  Cell 2Z  :|

The alignment of the cells in the first row is controlled by the alignment/divider line as before, Cell 2X is right aligned, Cell 2YC is left aligned and Cell 2Z is centered.

In general, the following rules should apply:

  1. There must be no space between the pipe and the colon(s) which indicate alignment. If there is a space, the colon is considered to be cell text.
  2. Cell alignment with colons always overrides column alignment driven by the alignment/divider line.
  3. Cell alignment with colons is available for cells in the table header and the table body.
  4. Left or center alignment in the first cell of a row require the use of the pipe at the beginning of the line.
  5. Right or center alignment in the last cell of a row require the use of the pipe at the end of the line.

I know that you are cautious in syntax extensions (for good reasons) but maybe you can consider this extension. Cell alignment is hard to get right with CSS or XSLT after MMD conversion for arbitrary tables.

It is also clear that this extension would break backwards compatibility with (a small amount of) existing documents, so it probably needs to be controllable with a command-line switch or a metadata key.

Thanks, Michael

fletcher commented 10 years ago

I worry that this is starting to get too specific, and not something that most MMD users need.

I'll leave this issue open for now as a reminder to keep thinking about this, but no promises.

Either way, however, I do appreciate your making the suggestion!

F-

manuel-rubio commented 9 years ago

I'd like to add something to the specification, the possibility to use custom classes:

|    Col X    |    Col Y    |    Col Z    |
| :---------- | :---------: | ----------: |
|   Cell 1X   |   Cell 1Y   |   Cell 1Z   |
|   Cell 2X  :|:  Cell 2Y   |:  Cell 2Z  :|
{:.table}

or even:

{:.table}
|    Col X    |    Col Y    |    Col Z    |
| :---------- | :---------: | ----------: |
|   Cell 1X   |   Cell 1Y   |   Cell 1Z   |
|   Cell 2X  :|:  Cell 2Y   |:  Cell 2Z  :|

to render the table envelop as:

<table class="table"> ... </table>