Skip to content

Commit

Permalink
Merge pull request #818 from jrblevin/issue/817
Browse files Browse the repository at this point in the history
Fix table alignment if there is a separator in inline code
  • Loading branch information
syohex committed Nov 30, 2023
2 parents b1a862f + e0f2926 commit 141f9a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
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

0 comments on commit 141f9a0

Please sign in to comment.