feat(extension-table): add markdown table column alignment support#7610
Open
weilinzung wants to merge 9 commits intoueberdosis:mainfrom
Open
feat(extension-table): add markdown table column alignment support#7610weilinzung wants to merge 9 commits intoueberdosis:mainfrom
weilinzung wants to merge 9 commits intoueberdosis:mainfrom
Conversation
🦋 Changeset detectedLatest commit: fad545f The changes in this PR will be included in the next version bump. This PR includes changesets to release 72 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds end-to-end table column alignment support to @tiptap/extension-table, including parsing alignment from Markdown/HTML and serializing it back to Markdown/HTML.
Changes:
- Introduces a shared
alignattribute forTableCellandTableHeader, with HTML parsing/rendering viatext-align. - Extends Markdown table parsing/serialization to roundtrip column alignment markers (
:---,---:,:---:). - Adds coverage via a Vitest spec and updates the Markdown parsing demo + changeset.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/extension-table/src/utilities/parseAlign.ts | New utilities for normalizing/parsing alignment and generating a reusable attribute config. |
| packages/extension-table/src/table/utilities/markdown.ts | Emits Markdown alignment markers in the separator row based on cell/header align attrs. |
| packages/extension-table/src/table/table.ts | Reads token.align / per-cell align info from Markdown tokens and stores align on created cells. |
| packages/extension-table/src/header/table-header.ts | Adds align attribute to table header nodes. |
| packages/extension-table/src/cell/table-cell.ts | Adds align attribute to table cell nodes. |
| packages/extension-table/tests/tableMarkdown.spec.ts | New test ensuring parse + serialize roundtrip for left/right/center alignment. |
| demos/src/Markdown/Parse/React/index.jsx | Updates demo markdown table to showcase alignment markers/columns; removes unused React import and tweaks TableKit config. |
| .changeset/table-cell-alignment.md | Declares a minor bump for the new user-facing Markdown/HTML alignment support. |
@tiptap/core
@tiptap/extension-audio
@tiptap/extension-blockquote
@tiptap/extension-bold
@tiptap/extension-bullet-list
@tiptap/extension-bubble-menu
@tiptap/extension-code
@tiptap/extension-code-block
@tiptap/extension-collaboration
@tiptap/extension-code-block-lowlight
@tiptap/extension-collaboration-caret
@tiptap/extension-color
@tiptap/extension-details
@tiptap/extension-document
@tiptap/extension-drag-handle
@tiptap/extension-drag-handle-react
@tiptap/extension-drag-handle-vue-2
@tiptap/extension-drag-handle-vue-3
@tiptap/extension-emoji
@tiptap/extension-file-handler
@tiptap/extension-floating-menu
@tiptap/extension-hard-break
@tiptap/extension-font-family
@tiptap/extension-heading
@tiptap/extension-highlight
@tiptap/extension-horizontal-rule
@tiptap/extension-image
@tiptap/extension-italic
@tiptap/extension-invisible-characters
@tiptap/extension-link
@tiptap/extension-mathematics
@tiptap/extension-list
@tiptap/extension-mention
@tiptap/extension-node-range
@tiptap/extension-paragraph
@tiptap/extension-ordered-list
@tiptap/extension-subscript
@tiptap/extension-strike
@tiptap/extension-superscript
@tiptap/extension-table-of-contents
@tiptap/extension-table
@tiptap/extension-text
@tiptap/extension-text-align
@tiptap/extension-text-style
@tiptap/extension-twitch
@tiptap/extension-typography
@tiptap/extension-underline
@tiptap/extension-youtube
@tiptap/extensions
@tiptap/extension-unique-id
@tiptap/html
@tiptap/markdown
@tiptap/pm
@tiptap/starter-kit
@tiptap/react
@tiptap/static-renderer
@tiptap/suggestion
@tiptap/vue-2
@tiptap/extension-character-count
@tiptap/vue-3
@tiptap/extension-dropcursor
@tiptap/extension-focus
@tiptap/extension-gapcursor
@tiptap/extension-history
@tiptap/extension-list-item
@tiptap/extension-placeholder
@tiptap/extension-list-keymap
@tiptap/extension-table-cell
@tiptap/extension-table-header
@tiptap/extension-table-row
@tiptap/extension-task-item
@tiptap/extension-task-list
commit: |
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.
Changes Overview
The table extension was not handling Markdown column alignment markers. This adds full parse and serialize support for
left(:----),right(----:), andcenter(:----:) alignment ontableHeaderandtableCellnodes.Implementation Approach
alignattribute toTableCellandTableHeader, parsed fromstyle="text-align: ..."/ legacyalignHTML attribute and rendered back to inline styleparseMarkdowninTableto readtoken.align(the column alignment array marked provides) and pass it as{ align }attrs when creating header/body cellsrenderTableToMarkdownto emit alignment markers in the separator row based on per-columnalignattrspackages/extension-table/src/utilities/parseAlign.ts:TableCellAlignenum (Left,Right,Center)normalizeTableCellAlign(value)— validates unknown inputnormalizeTableCellAlignFromAttributes(attrs)— typed extraction from node attrs objectsparseAlign(element)— parses alignment from an HTML elementcreateAlignAttribute()— shared TiptapAttributeconfig for both cell and headerBefore
After
Testing Done
packages/extension-table/__tests__/tableMarkdown.spec.tsVerification Steps
pnpm devpnpm vitest run packages/extension-table/__tests__/tableMarkdown.spec.tsAdditional Notes
Alignment is stored per-cell as a schema attribute (
align: 'left' | 'right' | 'center' | null). During serialization, alignment is resolved per column by scanning all rows and using the first non-null value found.Checklist
Related Issues
Fixes #7502