Skip to content

Commit

Permalink
remove opening space in each toc item
Browse files Browse the repository at this point in the history
  • Loading branch information
snosov1 committed May 18, 2017
1 parent d30b57f commit 421956e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
32 changes: 17 additions & 15 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ It is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]]
name conflict with one of the org contrib modules.

* Table of Contents :TOC:
- [[#about][About]]
- [[#installation][Installation]]
- [[#via-packageel][via package.el]]
- [[#manual][Manual]]
- [[#use][Use]]
- [[#follow-links][Follow links]]
- [[#exclude-headings][Exclude headings]]
- [[#shortcut-for-toc-tag][Shortcut for TOC tag]]
- [[#different-href-styles][Different href styles]]
- [[#example][Example]]
- [[#about][About]]
- [[#installation][Installation]]
- [[#via-packageel][via package.el]]
- [[#manual][Manual]]
- [[#use][Use]]
- [[#follow-links][Follow links]]
- [[#exclude-headings][Exclude headings]]
- [[#shortcut-for-toc-tag][Shortcut for TOC tag]]
- [[#different-href-styles][Different href styles]]
- [[#example][Example]]

* Installation
** via package.el
Expand Down Expand Up @@ -127,11 +127,13 @@ E.g. for =org= style it makes links to be the same as their visible text:
#+BEGIN_SRC org
* About
* Table of Contents :TOC:
- [[#about][About]]
- [[#installation][Installation]]
- [[#via-packageel][via package.el]]
- [[#manual][Manual]]
- [[#use][Use]]
- [[#about][About]]
- [[#installation][Installation]]
- [[#via-packageel][via package.el]]
- [[#manual][Manual]]
- [[#use][Use]]
- [[#example][Example]]

* Installation
** via package.el
** Manual
Expand Down
22 changes: 11 additions & 11 deletions toc-org-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@
(should (equal (toc-org-hrefify-toc "* About\n"
(lambda (str &optional hash) (upcase str))
hash)
" - [[ABOUT][About]]\n"))
"- [[ABOUT][About]]\n"))
(should (equal (gethash "ABOUT" hash) "About")))
;; check trailing space: https://github.com/snosov1/toc-org/pull/31
(let ((hash (make-hash-table :test 'equal)))
(should (equal (toc-org-hrefify-toc "* About \n"
(lambda (str &optional hash) (upcase str))
hash)
" - [[ABOUT][About]]\n"))
"- [[ABOUT][About]]\n"))
(should (equal (gethash "ABOUT" hash) "About")))
(let ((hash (make-hash-table :test 'equal)))
(should (equal (toc-org-hrefify-toc "* About\n* Installation\n** via package.el\n** Manual\n* Use\n* Different href styles\n* Example\n" (lambda (str &optional hash) (upcase str)) hash)
" - [[ABOUT][About]]\n - [[INSTALLATION][Installation]]\n - [[VIA PACKAGE.EL][via package.el]]\n - [[MANUAL][Manual]]\n - [[USE][Use]]\n - [[DIFFERENT HREF STYLES][Different href styles]]\n - [[EXAMPLE][Example]]\n"))
"- [[ABOUT][About]]\n- [[INSTALLATION][Installation]]\n - [[VIA PACKAGE.EL][via package.el]]\n - [[MANUAL][Manual]]\n- [[USE][Use]]\n- [[DIFFERENT HREF STYLES][Different href styles]]\n- [[EXAMPLE][Example]]\n"))
(should (equal (gethash "ABOUT" hash) "About"))
(should (equal (gethash "INSTALLATION" hash) "Installation"))
(should (equal (gethash "VIA PACKAGE.EL" hash) "via package.el"))
Expand Down Expand Up @@ -190,33 +190,33 @@
(let ((beg "* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents "))
(test-toc-org-insert-toc-gold-test
(concat beg ":TOC:")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC:\n - [[#about][About]]\n - [[#hello][Hello]]\n - [[#good-bye][Good-bye]]\n")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC:\n- [[#about][About]]\n- [[#hello][Hello]]\n - [[#good-bye][Good-bye]]\n")

(test-toc-org-insert-toc-gold-test
(concat beg ":TOC_1:")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC_1:\n - [[#about][About]]\n - [[#hello][Hello]]\n")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC_1:\n- [[#about][About]]\n- [[#hello][Hello]]\n")

(test-toc-org-insert-toc-gold-test
(concat beg ":TOC_3:")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC_3:\n - [[#about][About]]\n - [[#hello][Hello]]\n - [[#good-bye][Good-bye]]\n - [[#salut][Salut]]\n")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC_3:\n- [[#about][About]]\n- [[#hello][Hello]]\n - [[#good-bye][Good-bye]]\n - [[#salut][Salut]]\n")

(test-toc-org-insert-toc-gold-test
(concat beg ":TOC_1_org:")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC_1_org:\n - [[About][About]]\n - [[Hello][Hello]]\n")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC_1_org:\n- [[About][About]]\n- [[Hello][Hello]]\n")

(test-toc-org-insert-toc-gold-test
(concat beg ":TOC_3_org:")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC_3_org:\n - [[About][About]]\n - [[Hello][Hello]]\n - [[Good-bye][Good-bye]]\n - [[Salut][Salut]]\n")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC_3_org:\n- [[About][About]]\n- [[Hello][Hello]]\n - [[Good-bye][Good-bye]]\n - [[Salut][Salut]]\n")

(test-toc-org-insert-toc-gold-test
(concat beg ":TOC:\n:PROPERTIES:\n:VISIBILITY: content\n:END:\n")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC:\n:PROPERTIES:\n:VISIBILITY: content\n:END:\n - [[#about][About]]\n - [[#hello][Hello]]\n - [[#good-bye][Good-bye]]\n")
"* About\n:TOC:\n drawer\n:END:\n\ntoc-org is a utility to have an up-to-date table of contents in the\norg files without exporting (useful primarily for readme files on\nGitHub).\n\nIt is similar to the [[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works for org files.\n:TOC:\n drawer\n:END:\n* Hello\n** Good-bye\n*** Salut\n* Table of Contents :TOC:\n:PROPERTIES:\n:VISIBILITY: content\n:END:\n- [[#about][About]]\n- [[#hello][Hello]]\n - [[#good-bye][Good-bye]]\n")

(test-toc-org-insert-toc-gold-test
"* H1\n* H2\n* TOC :TOC:\n - [[#header-1][Header 1]]\n - [[#header-2][Header 2]]\n"
"* H1\n* H2\n* TOC :TOC:\n - [[#h1][H1]]\n - [[#h2][H2]]\n")
"* H1\n* H2\n* TOC :TOC:\n- [[#h1][H1]]\n- [[#h2][H2]]\n")

(test-toc-org-insert-toc-gold-test
"* H1\n* TODO H2\n* TOC :TOC:\n \n"
"* H1\n* TODO H2\n* TOC :TOC:\n - [[#h1][H1]]\n - [[#h2][H2]]\n")
"* H1\n* TODO H2\n* TOC :TOC:\n- [[#h1][H1]]\n- [[#h2][H2]]\n")
))
2 changes: 1 addition & 1 deletion toc-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ each heading into a link."
(+ 2 (or (bound-and-true-p org-list-indent-offset) 0))
?\s)))

(insert "-")
(skip-chars-forward " ")
(insert "- ")

(save-excursion
(delete-trailing-whitespace (point) (line-end-position)))
Expand Down

0 comments on commit 421956e

Please sign in to comment.