Skip to content

Commit

Permalink
Keep metadata visible when cycling visibility
Browse files Browse the repository at this point in the history
Metadata blocks like the following appear to contain setext headers when
using regexp matching (as `outline-minor-mode` does).

    ---
    title = Post Name
    date = May 6, 2016 11:15 EDT
    ---

As a result, when cycling visibility of sections the last line of the
block would be hidden.  This patch adds code to detect and revert this
in `markdown-outline-fix-visibility`.

Closes GH-136.
  • Loading branch information
jrblevin committed May 6, 2016
1 parent 8786c21 commit a646fea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
14 changes: 13 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -5563,9 +5563,21 @@ Derived from `org-end-of-subtree'."
(defun markdown-outline-fix-visibility ()
"Hide any false positive headings that should not be shown.
For example, headings inside preformatted code blocks may match
`outline-regexp' but should not be shown as headings when cycling."
`outline-regexp' but should not be shown as headings when cycling.
Also, the ending --- line in metadata blocks appears to be a
setext header, but should not be folded."
(save-excursion
(goto-char (point-min))
;; Unhide any false positives in metadata blocks
(when (markdown-text-property-at-point 'markdown-yaml-metadata-begin)
(let* ((body (progn (forward-line)
(markdown-text-property-at-point
'markdown-yaml-metadata-section)))
(end (progn (goto-char (cl-second body))
(markdown-text-property-at-point
'markdown-yaml-metadata-end))))
(outline-flag-region (point-min) (1+ (cl-second end)) nil)))
;; Hide any false positives in code blocks
(unless (outline-on-heading-p)
(outline-next-visible-heading 1))
(while (< (point) (point-max))
Expand Down
15 changes: 15 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,21 @@ x: x
(should (eq (point) 159))
(should (looking-at "^# Level one again")))))

(ert-deftest test-markdown-outline/visibility-with-metadata ()
"Test outline visibility cycling with metadata blocks."
(markdown-test-string
"---
layout = post
date = 2015-08-13 11:35:25 EST
---
"
(let (last-command this-command)
;; Cycle global visibility to "overview" mode
(setq this-command 'markdown-cycle)
(markdown-cycle t)
;; Check that text is visible
(markdown-test-range-has-property (point-min) (point-max) 'invisible nil))))

;;; Movement tests:

(ert-deftest test-markdown-movement/defun ()
Expand Down

0 comments on commit a646fea

Please sign in to comment.