From 09b1074c2b502cc29f615b856f1b702925f8d801 Mon Sep 17 00:00:00 2001 From: Jason Blevins Date: Tue, 29 Aug 2017 20:49:11 -0400 Subject: [PATCH] Fix issue with code after headings without whitespace Fixes "Invalid face reference: markdown-header-face-7" error. Closes GH-234. --- markdown-mode.el | 4 +++- tests/markdown-test.el | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/markdown-mode.el b/markdown-mode.el index 6d6317d6..3c5efc4a 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -7170,7 +7170,9 @@ Calls `markdown-cycle' with argument t." (defun markdown-outline-level () "Return the depth to which a statement is nested in the outline." (cond - ((markdown-code-block-at-point-p) 7) ;; Only 6 header levels are defined. + ((and (match-beginning 0) + (markdown-code-block-at-pos (match-beginning 0))) + 7) ;; Only 6 header levels are defined. ((match-end 2) 1) ((match-end 3) 2) ((match-end 4) diff --git a/tests/markdown-test.el b/tests/markdown-test.el index fea47a48..1e7086af 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -2940,6 +2940,25 @@ takes precedence)." (should (markdown-on-heading-p)) (should-not (markdown-range-property-any 453 484 'face '(markdown-hr-face))))) +(ert-deftest test-markdown-font-lock/heading-code-block-no-whitespace () + "Headings immediately before code blocks should be identified correctly. +See GH-234." + (markdown-test-string + "#### code snippet +```javascript +const styles = require('gadgets/dist/styles.css'); +```" + (goto-char (point-min)) + (forward-word) + (should (markdown-on-heading-p)) + (should (markdown-match-propertized-text 'markdown-heading (point-at-eol))) + (goto-char (match-beginning 0)) + (should (markdown-outline-level)) + (should (= (markdown-outline-level) 4)) + (markdown-test-range-has-face 6 17 'markdown-header-face-4) + (end-of-line) + (should-not (markdown-code-block-at-point-p)))) + (ert-deftest test-markdown-font-lock/inline-attributes () "Test inline attributes before a fenced code block." (markdown-test-file "Leanpub.md"