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

Generate TOC does not respect heading levels. #53

Open
TheAifam5 opened this issue May 13, 2022 · 9 comments
Open

Generate TOC does not respect heading levels. #53

TheAifam5 opened this issue May 13, 2022 · 9 comments

Comments

@TheAifam5
Copy link

TheAifam5 commented May 13, 2022

bug

Generated TOC does not respect heading levels and every TOC entry is on the same level.

Emacs Doom: master
Emacs Version: 28.1 with native-compilation

markdown-toc - Please:
- Describe your problem with clarity and conciceness (cf. https://www.gnu.org/software/emacs/manual/html_node/emacs/Understanding-Bug-Reporting.html)
- Explicit your installation choice (melpa, marmalade, el-get, tarball, git clone...).
- Report the following message trace inside your issue.

System information:
- system-type: gnu/linux
- locale-coding-system: utf-8-unix
- emacs-version: GNU Emacs 28.1 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0)
of 2022-05-19
- markdown-mode path: /home/theaifam5/.config/emacs/.local/straight/build-28.1/markdown-mode/markdown-mode.el
- markdown-toc version: 0.1.5
- markdown-toc path: /home/theaifam5/.config/emacs/.local/straight/build-28.1/markdown-toc/markdown-toc.el

Config

With and without it, the issue still occurs.

(custom-set-variables '(markdown-toc-user-toc-structure-manipulation-fn 'cdr))

Expected behavior

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
**Table of Contents**

- [Example 1](#example-1)
  - [Content](#content)
- [Example 2](#example-2)
  - [Content](#content-1)

<!-- markdown-toc end -->

Actual behavior

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
**Table of Contents**

- [Example 1](#example-1)
- [Content](#content)
- [Example 2](#example-2)
- [Content](#content-1)

<!-- markdown-toc end -->

Steps to reproduce the behavior

Title
=====

# Example 1
aa

## Content
xx

# Example 2
yy

## Content 
dd
@TheAifam5 TheAifam5 changed the title Generated TOC does generate nesting Generate TOC does not respect heading levels. May 22, 2022
@dominicm00
Copy link

To make a nested TOC, the buffer-local imenu-create-index-function has to be set to markdown-imenu-create-nested-index instead of markdown-imenu-create-flat-index.

@goetzc
Copy link

goetzc commented Aug 28, 2022

Did this chance with a new recent Emacs version?

@dominicm00
Copy link

dominicm00 commented Aug 28, 2022

Did this chance with a new recent Emacs version?

It did; maybe a default value was changed? Although this would be a change in markdown-mode rather than Emacs itself right?

@andorsk
Copy link

andorsk commented Dec 4, 2022

I tried setting it like this: (custom-set-variables '(imenu-create-index-function markdown-imenu-create-nested-index) but it didn't work. any advice here?

@sochotnicky
Copy link

I tried setting it like this: (custom-set-variables '(imenu-create-index-function markdown-imenu-create-nested-index) but it didn't work. any advice here?

It took a while digging around and this seems related to native compilation as far as I can tell. I have a workaround in my config here:
https://codeberg.org/sochotnicky/dotfiles/src/branch/main/dot_doom.d/config.org#headline-64

Basically - disable native compilation for markdown-mode & add a hook to enable nested TOC generation. Might help you as well?

@andorsk
Copy link

andorsk commented Dec 4, 2022

Good idea, but didn't work unfortunately. This is a bummer, as this is a super useful feature for me.

@sochotnicky
Copy link

I tried setting it like this: (custom-set-variables '(imenu-create-index-function markdown-imenu-create-nested-index) but it didn't work. any advice here?

To be clear - you need to delete any already natively-compiled markdown-mode files or that first part won't be effective. Just make sure you do that...

@andorsk
Copy link

andorsk commented Dec 4, 2022

I had to restart my emacs, but it worked! Nice callout @sochotnicky

@xiliuya
Copy link

xiliuya commented May 25, 2023

Hi, replace this funtion will fix it.

(defun markdown-toc--compute-toc-structure (imenu-index)
  "Given a IMENU-INDEX, compute the TOC structure."
  (--mapcat (markdown-toc--compute-toc-structure-from-level
             (if (eq markdown-toc-user-toc-structure-manipulation-fn 'cdr)
                 -1
               0)
             it)
            imenu-index)) 

xiliuya added a commit to xiliuya/markdown-toc that referenced this issue May 25, 2023
pierre-rouleau added a commit to pierre-rouleau/markdown-toc that referenced this issue Nov 14, 2024
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

6 participants