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

Lines beginning with hash symbol in literal code blocks treated as headers #33

Closed
duncanburke opened this issue Oct 26, 2015 · 4 comments

Comments

@duncanburke
Copy link

For the purposes of commands such as outline-next-visible-heading and outline-forward-same-level, it is not expected that lines beginning with the # symbol in literal code blocks be treated as headers.

For example:

### Third level ###

* A list item
* and another
  with some overhang
   + and a sublist
     with overhang
- And a third with a different marker

### Third level number two ###

~~~ {.bash}
#!/bin/bash

# In a code block, this shouldn't be a header
~~~

### Level two again

followed by some body text
@jrblevin
Copy link
Owner

jrblevin commented Dec 6, 2015

I think the new markdown-collect-fm-code-blocks function introduced in #40 could be used for font lock to fix this issue also. By identifying fenced code blocks first, then identifying headings that are not already marked as code blocks. I'll try to take a look soon, but if anyone can get to it sooner please submit a pull request.

@syohex
Copy link
Collaborator

syohex commented Dec 7, 2015

In outline-next-visible-heading, outline-mode uses only regular expression(outline-regexp) for searching header. We can control its behaviour only by outline-regexp. So we need to write wrapper command for avoiding this issue as below.

(defun markdown-move-visible-header-common (move-fn arg)
  (let ((blocks (markdown-collect-gfm-code-blocks)))
    (funcall move-fn arg)
    (while (markdown-gfm-code-block-p blocks (point))
      (funcall move-fn arg))))

(defun markdown-next-visible-heading (arg)
  (interactive "p")
  (markdown-move-visible-header-common #'outline-next-visible-heading arg))

(defun markdown-next-visible-heading (arg)
  (interactive "p")
  (markdown-move-visible-header-common #'outline-previous-visible-heading arg))

I don't understand outline-forward-same-level behavior yet :-(

@syohex
Copy link
Collaborator

syohex commented Dec 10, 2015

I sent PR #41. Please check it.

@jrblevin
Copy link
Owner

Thanks for this report, @duncanburke, and thanks @syohex for the patch. As I mentioned in #41 I have been working on syntax table support for code blocks. In addition to helping with font lock, this is also related to the heading movement commands. I used #41 as a basis for the changes. So, this should be fixed in 5daa9fc.

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

Successfully merging a pull request may close this issue.

3 participants