[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/toc-org 7291a3b08d 100/128: Enable link following in markd
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/toc-org 7291a3b08d 100/128: Enable link following in markdown mode |
Date: |
Sun, 2 Jan 2022 09:59:13 -0500 (EST) |
branch: elpa/toc-org
commit 7291a3b08d84d71879f16b6ce618503f3a2f50ec
Author: Sergei Nosov <sergei.nosov@gmail.com>
Commit: Sergei Nosov <sergei.nosov@gmail.com>
Enable link following in markdown mode
---
README.org | 40 +++++++++++++++++++++++++++++++++++++++-
toc-org.el | 30 ++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index fb302c305d..a175ae989c 100644
--- a/README.org
+++ b/README.org
@@ -5,7 +5,8 @@
toc-org helps you to have an up-to-date table of contents in org files without
exporting (useful primarily for readme files on GitHub).
-It is similar to the
[[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works
for org files.
+It is similar to the
[[https://github.com/ardumont/markdown-toc][markdown-toc]] package, but works
for org files. Since
+recently, it, actually, works in [[Markdown support][markdown]], too!
*NOTE:* Previous name of the package is =org-toc=. It was changed because of a
name conflict with one of the org contrib modules.
@@ -21,6 +22,7 @@ name conflict with one of the org contrib modules.
- [[#exclude-headings][Exclude headings]]
- [[#quote-table-of-contents][Quote table of contents]]
- [[#shortcut-for-toc-tag][Shortcut for TOC tag]]
+- [[#markdown-support][Markdown support]]
- [[#different-href-styles][Different href styles]]
- [[#example][Example]]
#+END_QUOTE
@@ -37,6 +39,10 @@ repository and then put the following snippet in your
~/.emacs file
#+BEGIN_SRC elisp
(if (require 'toc-org nil t)
(add-hook 'org-mode-hook 'toc-org-mode)
+
+ ;; enable in markdown, too
+ (add-hook 'markdown-mode-hook 'toc-org-mode)
+ (define-key markdown-mode-map (kbd "\C-c\C-o")
'toc-org-markdown-follow-thing-at-point))
(warn "toc-org not found"))
#+END_SRC
@@ -52,6 +58,10 @@ repository and then put the following snippet in your
~/.emacs file
(add-to-list 'load-path "~/.emacs.d/toc-org")
(if (require 'toc-org nil t)
(add-hook 'org-mode-hook 'toc-org-mode)
+
+ ;; enable in markdown, too
+ (add-hook 'markdown-mode-hook 'toc-org-mode)
+ (define-key markdown-mode-map (kbd "\C-c\C-o")
'toc-org-markdown-follow-thing-at-point))
(warn "toc-org not found"))
#+END_SRC
@@ -112,6 +122,34 @@ In your emacs' setup, you can bind a tag =:TOC:= to a
binding =T=:
Now =C-c C-q T RET= and you are done putting the =:TOC:= entry.
+* Markdown support
+
+You can also enable the mode in Markdown files and get pretty much the same
+functionality. The package will
+1. Look for '#'s instead of '*'s as heading markers (so, markdown syntax with
+ trailing pounds, like, =## Heading 2 ##= is not supported).
+2. Expect the =:TOC:= tag to appear as comment, like, =<-- :TOC: -->=
+3. Format the links and the quote block according to Markdown syntax
+
+Example:
+
+#+BEGIN_SRC markdown
+ # About
+ # Table of Contents <-- :TOC: -->
+ - [About](#about)
+ - [Installation](#installation)
+ - [via package.el](#via-packageel)
+ - [Manual](#manual)
+ - [Use](#use)
+ - [Example](#example)
+
+ # Installation
+ ## via package.el
+ ## Manual
+ # Use
+ # Example
+#+END_SRC
+
* Different href styles
Currently, only 2 href styles are supported: =gh= and =org=. You can easily
diff --git a/toc-org.el b/toc-org.el
index 03d69e209b..ef84811875 100644
--- a/toc-org.el
+++ b/toc-org.el
@@ -80,6 +80,17 @@ files on GitHub)"
equal to `org-drawer-regexp'. However, some older versions of
org (notably, 8.2.10) restrict the values that can be placed
between the colons. So, the value here is set explicitly.")
+(defconst toc-org-markdown-link-regexp ;; copy-paste from markdown-mode
+
"\\(!\\)?\\(\\[\\)\\([^]^][^]]*\\|\\)\\(\\]\\)\\((\\)\\([^)]*?\\)\\(?:\\s-+\\(\"[^\"]*\"\\)\\)?\\()\\)"
+ "Regular expression for a [text](file) or an image link ![text](file).
+Group 1 matches the leading exclamation point (optional).
+Group 2 matches the opening square bracket.
+Group 3 matches the text inside the square brackets.
+Group 4 matches the closing square bracket.
+Group 5 matches the opening parenthesis.
+Group 6 matches the URL.
+Group 7 matches the title (optional).
+Group 8 matches the closing parenthesis.")
(defcustom toc-org-max-depth 2
"Maximum depth of the headings to use in the table of
@@ -428,6 +439,25 @@ not :noexport_#:."
(insert new-toc)))))
(message (concat "Hrefify function " hrefify-string " is not
found"))))))))
+(defun toc-org-follow-markdown-link ()
+ "Follow the markdown link (mimics `org-open-at-point')"
+ (interactive)
+ (when (thing-at-point-looking-at toc-org-markdown-link-regexp)
+ (let ((pos (point)))
+ (goto-char (point-min))
+ (if (re-search-forward (concat "^#+\s+" (match-string-no-properties 3))
(point-max) t)
+ (beginning-of-line)
+ (goto-char pos)))))
+
+(defun toc-org-markdown-follow-thing-at-point (arg)
+ "Try to follow the link with `toc-org-follow-markdown-link',
+fallback to `markdown-follow-thing-at-point' on failure"
+ (interactive "P")
+ (let ((pos (point)))
+ (toc-org-follow-markdown-link)
+ (when (equal pos (point))
+ (markdown-follow-thing-at-point arg))))
+
;;;###autoload
(defun toc-org-enable ()
"Enable toc-org in this buffer."
- [nongnu] elpa/toc-org e38e81af3f 088/128: Merge pull request #57 from JAremko/master, (continued)
- [nongnu] elpa/toc-org e38e81af3f 088/128: Merge pull request #57 from JAremko/master, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org cda8f73640 073/128: Merge pull request #37 from snosov1/handle-comment, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org ee70dd23e1 104/128: resolve missing functions warnings, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org d52f95fae8 105/128: Handle trailing #'s, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 5ce7c24920 096/128: handle paranthesis in #+TODO line (fixes #65), ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org b1bab4c078 072/128: handle nil that is sometimes returned by (current-word), ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 9efeec690c 111/128: Remove the "backup" variable, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org ff8d49c2c7 113/128: Merge pull request #69 from htsr/comment-stripping, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 95a558b362 099/128: add tests for markdown-style syntax, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org e33e4cc00a 084/128: Merge pull request #50 from snosov1/handle-custom-keywords, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 7291a3b08d 100/128: Enable link following in markdown mode,
ELPA Syncer <=
- [nongnu] elpa/toc-org f455bd4c88 103/128: Call batch compile before running the tests, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 8321d3c76b 120/128: Revert "Respect the file-local value of org-list-indent-offset.", ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 6eca67f9a8 127/128: Merge pull request #83 from skangas/silence-byte-compiler, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 328d34144f 124/128: Bump version to 1.1, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org ebff38bfa4 094/128: make toc-org a minor mode (#61), ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org aa9aea6d69 102/128: Supress warnings, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org 215d3e41e3 114/128: fix C-c C-o for links with cookies, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org a2cb4c254f 128/128: Merge pull request #84 from skangas/nongnu-elpa, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org d66a41f6b7 010/128: strip tags, ELPA Syncer, 2022/01/02
- [nongnu] elpa/toc-org cac667fabd 018/128: Add a small note about global tag setup, ELPA Syncer, 2022/01/02