branch: elpa/markdown-mode commit de365c070c7deecbabfd5a7294bc8c2603d9ec22 Merge: 9977753 4af8d20 Author: Shohei YOSHIDA <syo...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #617 from MrChenWithCapsule/master Fix delimiter regex in markdown-table-align --- CHANGES.md | 1 + markdown-mode.el | 2 +- tests/markdown-test.el | 32 +++++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a1269e8..12cf68a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -44,6 +44,7 @@ - Fix highlighting consecutive HTML comments[GH-584][] - Fix `markdown-follow-thing-at-point` failing on subdir search [GH-590][] - Fix `markdown-table-backward-cell' so it always goes back a single cell + - Fix 'markdown-table-align' to detect delimiters surrounded by spaces [gh-290]: https://github.com/jrblevin/markdown-mode/issues/290 [gh-311]: https://github.com/jrblevin/markdown-mode/issues/311 diff --git a/markdown-mode.el b/markdown-mode.el index 999df6f..aba9e6f 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -9087,7 +9087,7 @@ This function assumes point is on a table." (indent (progn (looking-at "[ \t]*") (match-string 0))) ;; Split table in lines and save column format specifier (lines (mapcar (lambda (l) - (if (string-match-p "\\`[ \t]*|[-:]" l) + (if (string-match-p "\\`[ \t]*|[ \t]*[-:]" l) (progn (setq fmtspec (or fmtspec l)) nil) l)) (markdown--split-string (buffer-substring begin end) "\n"))) ;; Split lines in cells diff --git a/tests/markdown-test.el b/tests/markdown-test.el index f25c398..a597d76 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -5921,7 +5921,7 @@ Details: https://github.com/jrblevin/markdown-mode/issues/308" (markdown-table-align) (should (string= (buffer-substring-no-properties (point-min) (point-max)) "| Col1 | Col2 | -| :-: | :-: | +|:----:|:----:| | AAA | A\\|B |\n")))) (ert-deftest test-markdown-table/align-with-wiki-link () @@ -6903,6 +6903,36 @@ title: asdasdasd | A very very very long cell | | ")))) +(ert-deftest test-markdown-table/align-with-spaces-before-delimiter () + "Test table realignment when there are spaces before a delimiter" + (markdown-test-string " +| A | B | C | D | +| - | :- | :-: | -: | +| aaa | bbbb | ccccc | dddddd | +" + (search-forward "A") + (markdown-table-align) + (should (string= (buffer-string) " +| A | B | C | D | +|-----|:-----|:-----:|-------:| +| aaa | bbbb | ccccc | dddddd | +")))) + +(ert-deftest test-markdown-table/align-with-tabs-before-delimiter () + "Test table realignment when there are tabs before a delimiter" + (markdown-test-string " +| A | B | C | D | +| - | :-|:-: |-:| +| aaa | bbbb | ccccc | dddddd | +" + (search-forward "A") + (markdown-table-align) + (should (string= (buffer-string) " +| A | B | C | D | +|-----|:-----|:-----:|-------:| +| aaa | bbbb | ccccc | dddddd | +")))) + (provide 'markdown-test) ;;; markdown-test.el ends here