Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table alignment if there is a separator in inline code #818

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

* Bug fixes:
- Don't highlight superscript/subscript in math inline/block [GH-802][]
- Fix table alignment when a column has a seperator in code block [GH-817][]

* Improvements:
- Apply url-unescape against URL in an inline link [GH-805][]
Expand All @@ -19,6 +20,7 @@
[gh-802]: https://github.com/jrblevin/markdown-mode/issues/802
[gh-804]: https://github.com/jrblevin/markdown-mode/issues/804
[gh-805]: https://github.com/jrblevin/markdown-mode/issues/805
[gh-817]: https://github.com/jrblevin/markdown-mode/issues/817

# Markdown Mode 2.6

Expand Down
21 changes: 11 additions & 10 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -9300,16 +9300,17 @@ This function assumes point is on a table."
(goto-char (point-min))
(let ((cur (point))
ret)
(while (re-search-forward "\\s-*\\(|\\)\\s-*" nil t)
(if (markdown--first-column-p (match-beginning 1))
(setq cur (match-end 0))
(cond ((eql (char-before (match-beginning 1)) ?\\)
;; keep spaces
(goto-char (match-end 1)))
((markdown--thing-at-wiki-link (match-beginning 1))) ;; do nothing
(t
(push (buffer-substring-no-properties cur (match-beginning 0)) ret)
(setq cur (match-end 0))))))
(while (and (re-search-forward "\\s-*\\(|\\)\\s-*" nil t))
(when (not (markdown--face-p (match-beginning 1) '(markdown-inline-code-face)))
(if (markdown--first-column-p (match-beginning 1))
(setq cur (match-end 0))
(cond ((eql (char-before (match-beginning 1)) ?\\)
;; keep spaces
(goto-char (match-end 1)))
((markdown--thing-at-wiki-link (match-beginning 1))) ;; do nothing
(t
(push (buffer-substring-no-properties cur (match-beginning 0)) ret)
(setq cur (match-end 0)))))))
(when (< cur (length line))
(push (buffer-substring-no-properties cur (point-max)) ret))
(nreverse ret))))
Expand Down
15 changes: 15 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -7379,6 +7379,21 @@ title: asdasdasd
| aaa | bbbb | ccccc | dddddd |
"))))

(ert-deftest test-markdown-table/align-with-seperator-in-inline-code ()
"Test table realignment when separator is in inline code.
Detail: https://github.com/jrblevin/markdown-mode/issues/817"
(markdown-test-string "| `<|--` | Inheritance |
| `..|>` | Realization |
"
(let ((columns (markdown--table-line-to-columns
(buffer-substring (line-beginning-position) (line-end-position)))))
(should (equal columns '("`<|--`" "Inheritance"))))

(forward-line)
(let ((columns (markdown--table-line-to-columns
(buffer-substring (line-beginning-position) (line-end-position)))))
(should (equal columns '("`..|>`" "Realization"))))))

(ert-deftest test-markdown-table/disable-table-align ()
"Test disable table alignment."
(let ((input "| 12345 | 6 |
Expand Down