Skip to content

Commit

Permalink
Merge pull request #154 from jrblevin/imenu-with-metadata
Browse files Browse the repository at this point in the history
Don't correct header like statement in metadata
  • Loading branch information
jrblevin authored Jul 22, 2016
2 parents c5f9265 + e751be3 commit 3ba1851
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
18 changes: 10 additions & 8 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4817,14 +4817,16 @@ See `imenu-create-index-function' and `imenu--index-alist' for details."
(save-excursion
(goto-char (point-min))
(while (re-search-forward markdown-regex-header (point-max) t)
(cond
((setq heading (match-string-no-properties 1))
(setq pos (match-beginning 1)))
((setq heading (match-string-no-properties 5))
(setq pos (match-beginning 4))))
(or (> (length heading) 0)
(setq heading empty-heading))
(setq index (append index (list (cons heading pos)))))
(when (and (not (markdown-code-block-at-point))
(not (markdown-text-property-at-point 'markdown-yaml-metadata-begin)))
(cond
((setq heading (match-string-no-properties 1))
(setq pos (match-beginning 1)))
((setq heading (match-string-no-properties 5))
(setq pos (match-beginning 4))))
(or (> (length heading) 0)
(setq heading empty-heading))
(setq index (append index (list (cons heading pos))))))
index)))


Expand Down
19 changes: 19 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -3990,6 +3990,25 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/79"
(window-start) (window-point))
final-win-st-diff)))))))

;; Tests for imenu

(ert-deftest test-markdown-imenu/metadata ()
"Don't correct header like statement in metadata.
https://github.com/jrblevin/markdown-mode/issues/145"
(markdown-test-string "---
title = \"Blah\"
comments = false
---

# Header1

## Header2
"
(let ((headers (mapcar #'car (markdown-imenu-create-flat-index))))
(should (member "Header1" headers))
(should (member "Header2" headers))
(should-not (member "comments = false" headers)))))

(provide 'markdown-test)

;;; markdown-test.el ends here

0 comments on commit 3ba1851

Please sign in to comment.