Skip to content

Commit

Permalink
Merge pull request #27 from ardumont/0.1.2
Browse files Browse the repository at this point in the history
0.1.2
  • Loading branch information
ardumont authored Jul 25, 2016
2 parents 31fe505 + 7ab7f32 commit 15587c7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
2 changes: 1 addition & 1 deletion markdown-toc-pkg.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(define-package "markdown-toc" "0.1.1" "A simple TOC generator for markdown file"
(define-package "markdown-toc" "0.1.2" "A simple TOC generator for markdown file"
'((s "1.9.0")
(dash "2.11.0")
(markdown-mode "2.1")))
34 changes: 21 additions & 13 deletions markdown-toc.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Maintainer: Antoine R. Dumont
;; URL: http://github.com/ardumont/markdown-toc
;; Created: 24th May 2014
;; Version: 0.1.1
;; Version: 0.1.2
;; Keywords: markdown, toc, tools,
;; Package-Requires: ((markdown-mode "2.1") (dash "2.11.0") (s "1.9.0"))

Expand Down Expand Up @@ -62,7 +62,7 @@
(require 'dash)
(require 'markdown-mode)

(defconst markdown-toc--toc-version "0.1.1" "Current version installed.")
(defconst markdown-toc--toc-version "0.1.2" "Current version installed.")

(defgroup markdown-toc nil
"A simple TOC generator for markdown file."
Expand Down Expand Up @@ -124,19 +124,27 @@
(markdown-toc--to-link title))))
(s-join "\n")))

(defconst markdown-toc--header-toc-start
"<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->")
(defconst markdown-toc--header-toc-title
"**Table of Contents**")
(defconst markdown-toc--header-toc-end
"<!-- markdown-toc end -->")
(defcustom markdown-toc-header-toc-start
"<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->"
"Beginning delimiter comment."
:group 'markdown-toc)

(defcustom markdown-toc-header-toc-title
"**Table of Contents**"
"Title comment on TOC header."
:group 'mardown-toc)

(defcustom markdown-toc-header-toc-end
"<!-- markdown-toc end -->"
"Ending delimiter comment."
:group 'mardown-toc)

(defun markdown-toc--toc-already-present-p ()
"Determine if a TOC has already been generated.
Return the end position if it exists, nil otherwise."
(save-excursion
(goto-char (point-min))
(re-search-forward markdown-toc--header-toc-start nil t)))
(re-search-forward markdown-toc-header-toc-start nil t)))

(defun markdown-toc--toc-start ()
"Compute the toc's starting point."
Expand All @@ -148,7 +156,7 @@ Return the end position if it exists, nil otherwise."
"Compute the toc's end point."
(save-excursion
(goto-char (point-min))
(re-search-forward markdown-toc--header-toc-end nil t)))
(re-search-forward markdown-toc-header-toc-end nil t)))

(defun markdown-toc--generate-toc (toc-structure)
"Given a TOC-STRUCTURE, compute a new toc."
Expand All @@ -159,10 +167,10 @@ Return the end position if it exists, nil otherwise."
(defun markdown-toc--compute-full-toc (toc)
"Given the TOC's content, compute the full toc with comments and title."
(format "%s\n%s\n\n%s\n\n%s\n"
markdown-toc--header-toc-start
markdown-toc--header-toc-title
markdown-toc-header-toc-start
markdown-toc-header-toc-title
toc
markdown-toc--header-toc-end))
markdown-toc-header-toc-end))

(defcustom markdown-toc-user-toc-structure-manipulation-fn
(lambda (toc-structure) toc-structure)
Expand Down
6 changes: 6 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.1.2

- [X] Make markdown-toc-header-toc-* customizable - Closes #26
- [X] Update version
- [X] Release notes

# 0.1.1

- [X] Update version
Expand Down
22 changes: 22 additions & 0 deletions test/markdown-toc-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ For this, you need to install a snippet of code in your emacs configuration file
"
(markdown-toc-generate-toc)))))

(ert-deftest markdown-toc-generate-toc--with-customs ()
(should (equal "<!-- markdown-toc start -->
** foobar **
- [something](#something)
- [Sources](#sources)
<!-- markdown-toc end -->
blahblah.
# something
## Sources
"
(let ((markdown-toc-header-toc-start "<!-- markdown-toc start -->")
(markdown-toc-header-toc-title "** foobar **")
(markdown-toc-header-toc-end "<!-- markdown-toc end -->"))
(markdown-toc-with-temp-buffer-and-return-buffer-content
"blahblah.
# something
## Sources
"
(markdown-toc-generate-toc))))))

(ert-deftest markdown-toc-generate-toc--first-toc-with-user-override ()
(should (equal "<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
**Table of Contents**
Expand Down
6 changes: 6 additions & 0 deletions todo.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#+title: dev backlog
#+author: ardumont

* DONE 0.1.2 [100%]
CLOSED: [2016-07-25 Mon 13:55]
- [X] Make markdown-toc-header-toc-* customizable - Closes #26
- [X] Update version
- [X] Release notes

* DONE 0.1.1 [100%]
CLOSED: [2016-07-20 Wed 11:40]
- [X] Update version
Expand Down

0 comments on commit 15587c7

Please sign in to comment.