Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line with a colon is highlighted as footnote #437

Closed
kartikynwa opened this issue Apr 8, 2020 · 3 comments
Closed

Line with a colon is highlighted as footnote #437

kartikynwa opened this issue Apr 8, 2020 · 3 comments

Comments

@kartikynwa
Copy link

kartikynwa commented Apr 8, 2020

When a line contains a colon, it is highlighted the same way as a footnote.

For example, here is a screenshot of an entirety of a file.
screenshot-20200408043639

This can be worked around by adding a space before the line or escaping the colon but I felt it was worth reporting anyway.

Edit: I realised that this doesn't happen all the time so I am attaching the file for reference:
example.zip

Expected Behavior

Line shouldn't be highlighted.

Actual Behavior

Line is highlighted as a footnote.

Software Versions

  • Markdown Mode: 2.4-dev
  • Emacs: 26.6
  • OS: Void GNU/Linux
@syohex
Copy link
Collaborator

syohex commented Apr 8, 2020

It seems meta-data highlighting does not works well. It is necessary to check the line which has contains colon is meta-data block or not more strictly. I suppose following patch fixes your issue and does not break tests(all tests are passed)

diff --git a/markdown-mode.el b/markdown-mode.el
index 7df1e0a..3d9223c 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -3261,6 +3261,17 @@ Made into a variable to allow for dynamic let-binding.")
       (setq ret (funcall condition)))
     ret))
 
+(defun markdown-metadata-line-p (pos regexp)
+  (save-excursion
+    (or (= (line-number-at-pos pos) 1)
+        (progn
+          (forward-line -1)
+          ;; skip multi-line metadata
+          (while (and (looking-at-p "^\\s-+[[:alpha:]]")
+                      (> (line-number-at-pos (point)) 1))
+            (forward-line -1))
+          (looking-at-p regexp)))))
+
 (defun markdown-match-generic-metadata (regexp last)
   "Match metadata declarations specified by REGEXP from point to LAST.
 These declarations must appear inside a metadata block that begins at
@@ -3281,7 +3292,8 @@ the buffer)."
       ;; before the beginning of the block, start there. Otherwise,
       ;; move back to FIRST.
       (goto-char (if (< first block-begin) block-begin first))
-      (if (re-search-forward regexp (min last block-end) t)
+      (if (and (re-search-forward regexp (min last block-end) t)
+               (markdown-metadata-line-p (point) regexp))
           ;; If a metadata declaration is found, set match-data and return t.
           (let ((key-beginning (match-beginning 1))
                 (key-end (match-end 1))

@kartikynwa
Copy link
Author

@syohex thanks a lot for this

@syohex
Copy link
Collaborator

syohex commented Apr 12, 2020

@kartikynwa I have merged #438. Please check latest version.

@syohex syohex closed this as completed Apr 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants