diff --git a/CHANGES.md b/CHANGES.md index 6f0df291..ec60c065 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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][] @@ -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 diff --git a/markdown-mode.el b/markdown-mode.el index 0771060c..f1aee9d1 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -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)))) diff --git a/tests/markdown-test.el b/tests/markdown-test.el index 0abcbc94..8d68269f 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -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 |