Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Later separator-like rows overwrite established alignments, and separators without both outer pipes remain incorrectly handled.
2 open issues
What changed in this PR
Adds separator-driven column alignment to Markdown tables, addressing #11 by rendering alignment attributes on header and data cells.
Changes:
- Extracts column alignments from separator rows using shared cell-splitting logic.
- Stores alignments on
TableTokenand applies them during HTML rendering. - Adds alignment tests and updates existing expectations.
| File | Description |
|---|---|
tests/Tokens/TableTokenTest.php |
Tests rendering with explicit column alignments. |
tests/Rules/TableRuleTest.php |
Adds separator alignment cases and updates expected HTML. |
src/Tokens/TableToken.php |
Stores alignments and renders attributes on table cells. |
src/Tokens/TableRow.php |
Documents cells as a list with integer indexes. |
src/Rules/TableRule.php |
Extracts separator alignments and shares cell splitting. |
Review effort: Balanced
Benchmark ResultsComparison of Open to see the benchmark resultsNo benchmark changes above ±5%. Generated by phpbench against commit b279367 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #11
The separator row of a table now sets the alignment of each column, as in GFM:
:---align="left":---:align="center"---:align="right"---The alignment is applied to every
<th>and<td>of the column. I used thealignattribute because that's what the GFM spec andleague/commonmarkrender by default. Happy to switch tostyle="text-align: …"if you'd prefer.Changes
TableRulereads the alignments from the separator row instead of discarding it. Splitting a row into cells is moved to acells()method, used by both regular and separator rows.TableTokenhas a new$alignmentsproperty (alist<string|null>, one entry per column).TableRow::$cellsis typed aslist<string>, so that the column index passed toalign()is anint.Tests
TableTokenunit test with alignmentstest_lex_separator_with_alignmentandtest_table_with_empty_cells, which expected the alignment to be ignoredmago analyse,mago lintandmago fmtreport nothing new.