Giter VIP home page Giter VIP logo

markdown-toc's Introduction

markdown-toc

Build Status Coverage Status MELPA Stable MELPA SWH

Table of Contents

A simple mode to create TOC in a well-formed markdown file.

Note that the TOC is well-formed if the markdown is (cf. #15).

Use

Create

Inside a markdown file, the first time, place yourself where you want to insert the TOC:

M-x markdown-toc-generate-toc

This will compute the TOC and insert it at current position.

You can also execute: M-x markdown-toc-generate-or-refresh-toc to either gnerate a TOC when none exists or refresh the currently existing one.

Here is one possible output:

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

- [Use](#use)
    - [Create](#create)
    - [Update](#update)
    - [Create elsewhere](#create-elsewhere)
- [Install](#install)
    - [emacs package repository](#emacs-package-repository)
        - [Setup](#setup)
            - [melpa stable](#melpa-stable)
            - [melpa](#melpa)
            - [marmalade](#marmalade)
        - [Install](#install)
    - [emacs-lisp file](#emacs-lisp-file)
- [Inspiration](#inspiration)

User toc manipulation

If the user would want to enhance the generated toc, (s)he could use the following function markdown-toc-user-toc-structure-manipulation-fn:

It expects as argument the toc-structure markdown-toc uses to generate the toc. The remaining code expects a similar structure.

Example:

'((0 . "some markdown page title")
  (0 . "main title")
  (1 . "Sources")
  (2 . "Marmalade (recommended)")
  (2 . "Melpa-stable")
  (2 . "Melpa (~snapshot)")
  (1 . "Install")
  (2 . "Load org-trello")
  (2 . "Alternative")
  (3 . "Git")
  (3 . "Tar")
  (0 . "another title")
  (1 . "with")
  (1 . "some")
  (1 . "heading"))

So for example, as asked in #16, one could drop the first element:

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

Or drop all h1 titles... or whatever:

(require 'dash)
(custom-set-variables '(markdown-toc-user-toc-structure-manipulation-fn
  (lambda (toc-structure)
  (-filter (lambda (l) (let ((index (car l)))
                    (<= 1 index)))
           toc-structure)))

Update

To update the existing TOC, simply execute: M-x markdown-toc-refresh-toc

This will update the current TOC.

Create elsewhere

To create another updated TOC elsewhere, execute M-x markdown-toc-generate-toc again, this will remove the old TOC and insert the updated one from where you stand.

Remove

To remove a TOC, execute M-x markdown-toc-delete-toc.

Customize

Currently, you can customize the following:

  • markdown-toc-header-toc-start
  • markdown-toc-header-toc-title
  • markdown-toc-header-toc-end
  • markdown-toc-indentation-space

Customize them as following format:

(custom-set-variables
 '(markdown-toc-header-toc-start "<!-- customized start-->")
 '(markdown-toc-header-toc-title "**customized title**")
 '(markdown-toc-header-toc-end "<!-- customized end -->")
 '(markdown-toc-indentation-space 4))

Minor mode

markdown-toc-mode provides a minor mode with the following default binding:

(setq markdown-toc-mode-map
      (let ((map (make-sparse-keymap)))
        (define-key map (kbd "C-c m .") 'markdown-toc-follow-link-at-point)
        (define-key map (kbd "C-c m t") 'markdown-toc-generate-or-refresh-toc)
        (define-key map (kbd "C-c m d") 'markdown-toc-delete-toc)
        (define-key map (kbd "C-c m v") 'markdown-toc-version)
        map))

To (de)activate this in an org file: /M-x markdown-toc-mode/

You can also use emacs to setup your own bindings.

Install

emacs package repository

You need to add melpa or melpa-stable package repository before installing it.

Setup

melpa stable

(require 'package)
(add-to-list 'package-archives '("melpa-stable" .
                                 "http://melpa-stable.milkbox.net/packages/"))
(package-initialize)

Then hit M-x eval-buffer to evaluate the buffer's contents.

melpa

(require 'package)
(add-to-list 'package-archives '("melpa" .
                                 "http://melpa.milkbox.net/packages/"))
(package-initialize)

Then hit M-x eval-buffer to evaluate the buffer's contents.

Install

M-x package-install RET markdown-toc RET

emacs-lisp file

Retrieve the markdown-toc.el https://github.com/ardumont/markdown-toc/releases.

Then hit M-x package-install-file RET markdown-toc.el RET

Inspiration

https://github.com/thlorenz/doctoc

The problem I had with doctoc is the installation process. I do not want to install the node tools just for this.

markdown-toc's People

Contributors

ardumont avatar cesquivias avatar lucaskalves avatar pierre-rouleau avatar sdwolfz avatar syohex avatar tarsius avatar wilfred avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

markdown-toc's Issues

Generate TOC does not respect heading levels.

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

Wrong type argument: consp, nil

Hello,

Please, provide the following information and remove the useless parts.
Thanks in advance.

bug -> yes, I suppose

M-x markdown-toc-bug-report

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.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.29, cairo version 1.16.0)
 of 2021-11-30
- markdown-mode path: /home/claus/.emacs.d/elpa/markdown-mode-20211022.55/markdown-mode.el
- markdown-toc version: 0.1.5
- markdown-toc path: /home/claus/.emacs.d/elpa/markdown-toc-20210905.738/markdown-toc.el

Expected behavior

What command did you use and what were you expecting?

markdown-toc-generate-toc, markdown-toc-refresh-toc, markdown-toc-generate-or-refresh-toc

Actual behavior

When running the command markdown-toc-generate-toc I get the error Wrong type argument: consp, nil with the following test-file:

PROJECT
========

# Heading #

## Sub-Heading ##

Blah blah.

# Another Heading #

Blah blah.

When I remove the second-level heading the toc is generated successfully.

PROJECT
========

# Heading #

Blah blah.

# Another Heading #

Blah blah.

Steps to reproduce the behavior

How can we try and reproduce?

See above, simple example mark-down code.

Thanks for sharing!

Cheers,

Don't assume that a document has an h1

Given the markdown:

## foo

### bar

markdown-toc produces:

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

- [-](#-)
    - [bar](#bar)

<!-- markdown-toc end -->

Conditionally exclude h1

I tend to organize my docs like:

# Title of Document
[table of contents]
## Section 1
### Subsection a
## Section 2
...

I would like to be able to tell markdown-toc-generate-toc not to include "Title of Document" in the generated TOC.

Can't load markdown-toc mode or call any functions

I set up markdown-toc using use-package like so:

(use-package markdown-toc
  :bind (:map markdown-mode
              ("C-c t" . markdown-toc-generate-toc)
              :map markdown-toc-mode-map
              ("C-c m ." . markdown-toc-follow-link-at-point)
              ("C-c m t" . markdown-toc-generate-or-refresh-toc)
              ("C-c m d" . markdown-toc-delete-toc)
              ("C-c m v" . markdown-toc-version)))

When I call markdown-toc-mode or markdown-toc-generate-toc I get the following error:

Debugger entered--Lisp error: (void-variable markdown-mode)
  (and markdown-mode (symbolp markdown-mode))
  (if (and markdown-mode (symbolp markdown-mode)) (symbol-value markdown-mode) markdown-mode)
  (or (if (and markdown-mode (symbolp markdown-mode)) (symbol-value markdown-mode) markdown-mode) global-map)
  (let* ((name "C-c t") (key (if (vectorp name) name (read-kbd-macro name))) (kmap (or (if (and markdown-mode (symbolp markdown-mode)) (symbol-value markdown-mode) markdown-mode) global-map)) (kdesc (cons (if (stringp name) name (key-description name)) (if (symbolp markdown-mode) markdown-mode 'markdown-mode))) (binding (lookup-key kmap key))) (let ((entry (assoc kdesc personal-keybindings)) (details (list #'markdown-toc-generate-toc (if (numberp binding) nil binding)))) (if entry (setcdr entry details) (add-to-list 'personal-keybindings (cons kdesc details)))) (define-key kmap key #'markdown-toc-generate-toc))
  (lambda nil (let* ((name "C-c t") (key (if (vectorp name) name (read-kbd-macro name))) (kmap (or (if (and markdown-mode (symbolp markdown-mode)) (symbol-value markdown-mode) markdown-mode) global-map)) (kdesc (cons (if (stringp name) name (key-description name)) (if (symbolp markdown-mode) markdown-mode 'markdown-mode))) (binding (lookup-key kmap key))) (let ((entry (assoc kdesc personal-keybindings)) (details (list #'markdown-toc-generate-toc (if (numberp binding) nil binding)))) (if entry (setcdr entry details) (add-to-list 'personal-keybindings (cons kdesc details)))) (define-key kmap key #'markdown-toc-generate-toc)))()
  eval-after-load-helper("/home/sean/.emacs.d/straight/build/markdown-toc/markdown-toc.elc")
  run-hook-with-args(eval-after-load-helper "/home/sean/.emacs.d/straight/build/markdown-toc/markdown-toc.elc")
  do-after-load-evaluation("/home/sean/.emacs.d/straight/build/markdown-toc/markdown-toc.elc")
  autoload-do-load((autoload "markdown-toc" "Functionality for generating toc in markdown file.\nWith no argument, the mode is toggled on/off.\nNon..." t nil) markdown-toc-mode)
  command-execute(markdown-toc-mode record)
  counsel-M-x-action("markdown-toc-mode")
  ivy-call()
  ivy-read("M-x " [okr js-jsx-regexps ts-lang-node-type lsp-omnisharp-code-structure-request\? gnus-cloud-download-data 0 rng-what-schema vc-git-stash-snapshot denied edebug-trace js-jsx--text-properties org-publish--store-crossrefs mmm-mode-off duplicate org-emphasis-regexp-components company-box--add-icon lsp-dart-running-test-start-time--cmacro switch-function gnus-agent-group-covered-p nnmail-fix-eudora-headers flycheck-error-list-mode-line-map sgml-syntax-propertize gnus-summary-recenter avl-tree--stack-store--cmacro cl-print--preprocess lsp:set-ccls-inheritance-name thumb-buf edebug-clear-frequency-count org-agenda-regexp-filter-preset vc-git-conflicted-files ccls-code-lens-position post-deadline ---- ! \" gnus-tree-buffer Edebug\ All\ Defs org-duration-format & \' nnoo-import-1 gnus-summary-catchup-from-here :start-time always-end request-list elfeed-search-date-face tagger-params gnus-data-mark use-< Inline\ Code ...] :predicate #f(compiled-function (sym) #<bytecode 0x1562fc54ff25>) :require-match t :history counsel-M-x-history :action counsel-M-x-action :keymap (keymap (67108908 . counsel--info-lookup-symbol) (67108910 . counsel-find-symbol)) :initial-input nil :caller counsel-M-x)
  counsel-M-x()
  funcall-interactively(counsel-M-x)
  call-interactively(counsel-M-x nil nil)
  command-execute(counsel-M-x)

When I open a markdown file and use C-h m to view the modes for the file, markdown-toc doesn't show up.

For reference, here's how I've configured markdown-mode:

(use-package markdown-mode
  :custom
  (markdown-fontify-code-blocks-natively t)
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "multimarkdown")
  :config
  (use-package livedown
    :custom
    (livedown-autostart nil)
    (livedown-open t)
    (livedown-port 1337)
    (livedown-browser "firefox")))

System information:

  • system-type: gnu/linux
  • locale-coding-system: utf-8
  • emacs-version: GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.29, cairo version 1.17.4)
    of 2021-06-15
  • markdown-mode path: /home/sean/.emacs.d/straight/build/markdown-mode/markdown-mode.el
  • markdown-toc version: 0.1.5
  • markdown-toc path: /home/sean/.emacs.d/straight/build/markdown-toc/markdown-toc.el

Please add a prefix to test-helper.el to avoid conflicts with 68 other packages

There exist at least 69 packages that contain a file named test-helper.el that also provides the feature test-helper.

This leads to issues for users who have at least two of these packages installed. It is unlikely that such a user would be able to run the tests of all of those packages. If the primary test file of one of those packages does (require 'test-helper), then it is undefined which of the various test-helper.el files gets loaded. Which it is, depends on the order of the load-path.

To avoid this conflicts, you should rename your test-helper.el to <your-package>-test-helper.el and adjust the feature and symbol prefixes accordingly.

Also don't forget to update the require form in your primary test file and/or update references to the library/feature elsewhere. Also, if your primary test file is named something like test.el, then please consider renaming that too (same for any other utility elisp files your repositoroy may contain).

Thanks!

PS: This issue is a bit generic because I had to open 69 issues.

markdown-imenu-create-nested-index function definition is void

Hello,

Please, provide the following information and remove the useless parts.
Thanks in advance.

bug?

Yes,

markdown-imenu-create-nested-index, find-library-name are not known to be defined, produce errors when running markdown-toc-generate-toc.

M-x markdown-toc-bug-report

Report back the output from that command here.
(You can quote it with ``` for a better readability).

Expected behavior

What command did you use and what were you expecting?

A TOC generated when running markdown-toc-generate-toc

Actual behavior

What really happened?

error, Symbol's function definition is void: markdown-imenu-create-nested-index

Steps to reproduce the behavior

How can we try and reproduce?

Improvments?

What do you want?

Why is it better?

Thanks for sharing!

Cheers,

Always start TOC on first column

if for example the structure post-manipulation doesn't have any bottom-level elements, the generated TOC is indented 4 spaces, yielding something like this:

- [My first TOC entry](#my-first-toc-entry)
    - [Subsection 1](#subsection-1)
- [My second TOC entry](#my-second-toc-entry)

Maybe you could normalize the structure automatically so that the bottom-most level in the output always gets placed at column 1, like so:

Need to insert empty line before TOC header

I was having trouble getting the TOC to display properly.

System information:

  • system-type: gnu/Linux
  • os: Ubuntu 14.04.3 LTS
  • locale-coding-system: utf-8-unix
  • emacs-version: GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7)
    of 2014-03-07 on lamiak, modified by Debian
  • markdown-toc version: 0.1.2
  • markdown-toc path: /home/tekberg/.emacs.d/elpa/markdown-toc-20160727.908/markdown-toc.el

Expected behavior

I ran M-x markdown-toc-generate-toc to (re)generate the TOC. Then I ran M-x markdown-preview. I expected to see something line this:

    Table of Contents

	Introduction
	Ansible Instructions
	Role Documentation
	    Logwatch
	    Duply
		Install Duply
		    Variables
		    Automatic Settings
		Duply Setup

Actual behavior

What I actually got was this:

**Table of Contents** - [Introduction](#introduction) - [Ansible Instructions](#ansible-instructions) - [Role Documentation](#role-documentation) - [Logwatch](#logwatch) - [Duply](#duply) - [Install Duply](#install-duply) - [Variables](#variables) - [Automatic Settings](#automatic-settings) - [Duply Setup](#duply-setup) 

Steps to reproduce the behavior

Create a file bar.md with this contents

# First
First section.

# Second
Second section.

Run M-x markdown-toc-generate-toc to generate the TOC. Then run M-x markdown-preview. You will see something like this:

 **Table of Contents** 59f3daaf7f3ba5d330794074fe78c457 

If you add a \n before the TOC header you will see this:

Table of Contents

    First
    Second

What do you want?

Either insert the \n in the lisp code or change the default value of markdown-toc-header-toc-title to be "\nTable of Contents". I did the latter.

Why is it better?

It properly formats the TOC.

How to follow the link in TOC?

Hi,
First of all, thanks for the package.

I am using this package within the Markdown of Spacemacs. I would like to follow the links in the TOC to the corresponding sections. I tried SPC m f (markdown-follow-thing-at-point), but it does not work with TOC.

Is it possible to follow the link? Or it is a new feature that can be implemented.

Looking forward to your reply. Thanks in advance.

Proposal: Implement the same API as other toc generators

I would like to see the same API implemented by these two projects supported here as well:

https://github.com/nok/markdown-toc
https://github.com/AlanWalk/Markdown-TOC

The idea is to be able to generate an identical TOC from multiple code editors (Atom, VSCode, Emacs). This would allow TOC refreshes to be automatically done from any compatible editor without messing up the diff.

Generally this would mean having the TOC between the generic html comments:

<!-- TOC -->
<!-- /TOC -->

And controlling the behaviour through attributes:

<!-- TOC withLinks:1 updateOnSave:1 -->
<!-- /TOC -->

Those two projects seem to adhere to these settings already.
I am willing to put in the effort to implement this as I already am familiar with the functionality, but I don't make any promise on when this will be delivered.

Let me know what you think!

/cc @nok @alanwalk in case you have anything extra to add.

Ignore # characters in GFM code blocks

Given the markdown:

# Heading

## subheading

```
foo
# bar
baz
```

## another subheading

markdown-toc generates:

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

- [Heading](#heading)
    - [subheading](#subheading)
- [bar](#bar)
    - [another subheading](#another-subheading)

<!-- markdown-toc end -->

update TOC on save

I always forget to call markdown-toc-generate-or-refresh-toc before I save (half my commits just say "TOC" ;-))

So I wrote this little function

(defun my-markdown-toc-refresh ()
  "Refresh markdown TOC if present in the document."
  (interactive)
  (when (memq major-mode '(markdown-mode gfm-mode))
    (require 'markdown-toc)
    (when (markdown-toc--toc-already-present-p)
      (markdown-toc-generate-toc t))))
(add-hook 'before-save-hook #'my-markdown-toc-refresh)

(Note: #41 mentions updateOnSave as a feature of Atom and VSCode)

strip links from headings

Improvments

What do you want?

Strip links from headings.

Why is it better?

This:

### [Government Digital Service (GDS)](https://gds.blog.gov.uk/)

Outputs:

- [[Government Digital Service (GDS)](https://gds.blog.gov.uk/)](#government-digital-service-gdshttpsgdsbloggovuk)

When it could be:

- [Government Digital Service (GDS)](#government-digital-service-gds)

0.1.3 depends on unreleased s.el, and Package-Requires needs to be corrected

Hello,

Thank you for maintaining markdown-toc, and thank you for the new release :-) I am the maintainer of the Debian package, and I found the following issue while updating our copy of your work:

s-replace-regexp does not exist in s.el 1.12.0, and markdown-toc declares it requires 1.9.0 in Package-Requires, thus Package-Requires needs to be corrected:

Test test-markdown-toc-generate-or-refresh-toc--with-existing-toc condition:
    (void-function s-replace-regexp)
   FAILED  17/21  test-markdown-toc-generate-or-refresh-toc--with-existing-toc
Test test-markdown-toc-generate-or-refresh-toc--without-existing-toc backtrace:
  signal(void-function (s-replace-regexp))
  apply(signal (void-function (s-replace-regexp)))
  (setq value-97 (apply fn-95 args-96))
  (unwind-protect (setq value-97 (apply fn-95 args-96)) (setq form-des
  (if (unwind-protect (setq value-97 (apply fn-95 args-96)) (setq form
  (let (form-description-99) (if (unwind-protect (setq value-97 (apply
  (let ((value-97 (quote ert-form-evaluation-aborted-98))) (let (form-
  (let* ((fn-95 (function equal)) (args-96 (condition-case err (let ((
  (lambda nil (let* ((fn-95 (function equal)) (args-96 (condition-case
  ert--run-test-internal(#s(ert--test-execution-info :test #s(ert-test
  ert-run-test(#s(ert-test :name test-markdown-toc-generate-or-refresh
  ert-run-or-rerun-test(#s(ert--stats :selector t :tests [#s(ert-test
  ert-run-tests(t #f(compiled-function (event-type &rest event-args) #
  ert-run-tests-batch(nil)
  ert-run-tests-batch-and-exit()
  eval((ert-run-tests-batch-and-exit))
  command-line-1(("-l" "package" "--eval" "(add-to-list 'package-direc
  command-line()
  normal-top-level()

11 unexpected results:
   FAILED  markdown-toc--to-link
   FAILED  markdown-toc--to-markdown-toc
   FAILED  markdown-toc-generate-toc--first-toc
   FAILED  markdown-toc-generate-toc--first-toc-with-user-override
   FAILED  markdown-toc-generate-toc--replace-old-toc
   FAILED  markdown-toc-generate-toc--replace-old-toc-if-already-present
   FAILED  markdown-toc-generate-toc--with-customs
   FAILED  markdown-toc-generate-toc--with-duplicate-titles
   FAILED  test-markdown-toc--refresh-toc--with-existing-toc
   FAILED  test-markdown-toc-generate-or-refresh-toc--with-existing-toc
   FAILED  test-markdown-toc-generate-or-refresh-toc--without-existing-toc

The upstream issue requesting a new s.el release is here: magnars/s.el#135

When that issue has been resolved, please update ELPA metadata to require that release, and please tag a new release.

Best,
Nicholas

`markdown-toc--to-link` need remove the un-ascii char

bug?

I think so.

M-x markdown-toc-bug-report

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: darwin
- locale-coding-system: utf-8-unix
- emacs-version: GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin23.3.0, NS appkit-2487.40 Version 14.3.1 (Build 23D60))
 of 2024-02-10
- markdown-mode path: /Users/user/.emacs.d/straight/build/markdown-mode/markdown-mode.el
- markdown-toc version: 0.1.5
- markdown-toc path: /Users/user/.emacs.d/straight/build/markdown-toc/markdown-toc.el

Expected behavior

When I run M-x markdown-toc-generate-toc, one of section title and link should be

- [[hello · world](#hello--world)]

Because the · isn't the ascii char which isn't supported by github readme render and should be replaced by empty string.

Actual behavior

- [hello · world](#hello-·-world)

There is · inside the link which it shouldn't be there.

Steps to reproduce the behavior

  1. making one section like ### hello · world
  2. M-x markdown-toc-generate-toc or M-x markdown-toc-refresh-toc
  3. check the TOC part

Solution

I tried to figure out what's going on. I was running the markdown-toc--to-link "hello · world" in *scratch* buffer. And it gives me right link.

But in my markdown file, it returns the -·-.

After several tries, I find the (replace-regexp-in-string "[[:punct:]]" "") inside markdown-toc--to-link function has the inconsistent behaviors in markdown file and my *scratch* buffer.

After some googling, in emacs doc actually says:

This matches any punctuation character. (At present, for multibyte characters, it matches anything that has non-word syntax, and thus its exact definition can vary from one major mode to another, since the syntax of a character depends on the major mode.)

So I guess in markdown mode, · isn't the :punct:.

Then I change the regex in markdown-toc--to-link from (replace-regexp-in-string "[[:punct:]]" "") to (replace-regexp-in-string "[[:punct:][:nonascii:]]" ""). And it worked.

Not working on emacs 24.5

Hi,
I just installed emacs 24.5 and (markdown-toc-generate-toc) has stopped working. It says:
markdown-toc-generate-toc: Symbol's function definition is void: markdown-imenu-create-index

Any idea?
PD: thanks for your work, is not easy to find a toc creator that doesn't rely on node.

Generate invalid link when heading contains underscore `_`

System information:

  • system-type: gnu/linux
  • locale-coding-system: utf-8-unix
  • emacs-version: GNU Emacs 26.1 (build 1, x86_64-Ubuntu-linux-gnu, X toolkit, Xaw scroll bars)
    of 2019-03-12
  • markdown-toc version: 0.1.2

heading contains underscore _:

# under_socre

github generate link #under_score
but markdown-toc generate - [under_score][#undersocre].

Because _ is matched [[:punct:]] so replace into "" in markdown-toc--to-link.

Lines starting with # in code sections are treated as headings

bug?

Leading hash symbols in code sections are interpreted as headings and the corresponding lines are added to TOC.

I have the following in my README.md:

    ```shell
    # Add --with-postgresql if you need PostgreSQL support
    brew install sysbench
    ```

Note the leading hash symbol which is meant as a shell comment. However, markdown-toc apparently treats it as a heading, so the following ends up added to my TOC:

- [Add --with-postgresql if you need PostgreSQL support](#add---with-postgresql-if-you-need-postgresql-support)

Expected behavior

Ignore leading hash symbols in code sections.

Actual behavior

Lines corresponding to lines with a leading # are added to TOC.

Steps to reproduce the behavior

See above.

generating toc for a big file requires jumping to the end (markdown-toc-generate-toc: Wrong type argument: consp, 148688)

bug

M-x markdown-toc-bug-report

System information:
- system-type: gnu/linux
- locale-coding-system: utf-8-unix
- emacs-version: GNU Emacs 25.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.22.19)
 of 2017-09-15
- markdown-toc version: 0.1.2
- markdown-toc path: /home/michal/.emacs.d/elpa/markdown-toc-20170711.1249/markdown-toc.el

installed markdown-toc using melpa

Expected behavior

I was working on a version controlled (not sure if it matters) file that is >6000 lines long and has >200k characters. When running:

markdown-toc-generate-toc (but also markdown-toc-refresh-toc)

I get the following error message (with the number at the end being sometimes different):

markdown-toc-generate-toc: Wrong type argument: consp, 148688

I was expecting the toc to be generated.

This is the minimal repro scenario that I managed to narrow it down to. Originally I hit this when trying to make a change at the top of the file and then updating toc. Both functions work fine if I jumped above 148688 character before running them. In other words, the workaround is: open the file, jump to the end of it and then make the desired changes (e.g. at the beginning of the file) and regenerate toc.

Actual behavior

got an error message and no toc

Steps to reproduce the behavior

  • install versions as above
  • open emacs
  • open a pretty big file (>200k chars, >6k lines), do NOT navigate down
  • try to generate toc (or refresh existing)

Improvments?

What do you want?

I shouldn't need to go to the end of file to generate/refresh toc

not sure if the problem is with markdown-toc or emacs. Maybe emacs is not making the entire file available to markdown-toc? or markdown-toc is asking for the loaded part only? maybe it's a matter of changing some emacs config, e.g. how much of the buffer should be loaded to memory?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.