|
14 | 14 | (require 's)
|
15 | 15 | (require 'dash)
|
16 | 16 | (require 'f)
|
| 17 | +(require 'toc-org) |
| 18 | +(require 'org-id) |
17 | 19 |
|
18 | 20 | (defvar spacemacs--category-names
|
19 | 21 | '(("config-files" . "Configuration files")
|
|
86 | 88 | (format "%s\n%s%s" beginning-of-content toc-string rest-of-content)
|
87 | 89 | content)))
|
88 | 90 |
|
| 91 | +(defun spacemacs//toc-org-unhrefify-toc () |
| 92 | + "Make TOC classical org-mode TOC." |
| 93 | + (let ((toc-org-hrefify-default "org")) |
| 94 | + (toc-org-insert-toc))) |
| 95 | + |
| 96 | +(defun spacemacs//org-heading-annotate-custom-id () |
| 97 | + "Annotate headings with the indexes that GitHub uses for linking. |
| 98 | +`org-html-publish-to-html' will use them instead of the default #orgheadline{N}. |
| 99 | +This way the GitHub links and the http://spacemacs.org/ links will be compatible." |
| 100 | + (progn (goto-char (point-min)) |
| 101 | + (goto-char (point-min)) |
| 102 | + (while (re-search-forward "^[\\*]+\s\\(.*\\).*$" nil t) |
| 103 | + (let ((heading (match-string 1))) |
| 104 | + (progn (move-end-of-line nil) |
| 105 | + (open-line 1) |
| 106 | + (next-line 1) |
| 107 | + (insert (format (concat " :PROPERTIES:\n" |
| 108 | + " :CUSTOM_ID: %s\n" |
| 109 | + " :END:\n") |
| 110 | + (substring (toc-org-hrefify-gh |
| 111 | + (replace-regexp-in-string |
| 112 | + toc-org-tags-regexp |
| 113 | + "" |
| 114 | + heading)) |
| 115 | + ;; Remove # prefix added by `toc-org-hrefify-gh'. |
| 116 | + 1)))))))) |
| 117 | + |
| 118 | +(defun spacemacs//reroot-links () |
| 119 | + "Find the links that start with https://github.com/syl20bnr/spacemacs/blob/ |
| 120 | +and end with .org{#an-optional-heading-link} (i.e the links between the local org files). |
| 121 | +Change their root to http://spacemacs.org/ so the links will point at files located on the site. |
| 122 | +For the file to file links to work properly the exported org files should be processed with |
| 123 | +the `spacemacs//org-heading-annotate-custom-id' function." |
| 124 | + (let ((git-url-root-regexp |
| 125 | + (concat "\\[\\[[\\s]*\\(https\\:\\/\\/github\\.com\\/syl20bnr" |
| 126 | + "\\/spacemacs\\/blob\\/[^/]+\\/\\)[^]]+\\(\\.org\\).*$")) |
| 127 | + (site-url "http://spacemacs.org/") |
| 128 | + (site-doc-postf ".html")) |
| 129 | + (progn (goto-char (point-min)) |
| 130 | + (while (re-search-forward git-url-root-regexp nil t) |
| 131 | + (progn (replace-match site-url nil t nil 1) |
| 132 | + (replace-match site-doc-postf nil t nil 2)))))) |
| 133 | + |
89 | 134 | (defun spacemacs//add-org-meta-readtheorg-css (filename)
|
90 | 135 | (let* ((head-css-extra-readtheorg-head (concat
|
91 | 136 | "#+HTML_HEAD_EXTRA:"
|
|
98 | 143 | (goto-char (point-min))
|
99 | 144 | (if (search-forward "#+TITLE:" nil t nil)
|
100 | 145 | (beginning-of-line 2)
|
101 |
| - (error "Can't find #+TITLE:")) |
| 146 | + (error (format "Can't find #+TITLE: in %s" |
| 147 | + (buffer-file-name)))) |
102 | 148 | (insert (concat head-css-extra-readtheorg-head
|
103 | 149 | (f-relative user-emacs-directory
|
104 | 150 | (file-name-directory filename))
|
|
115 | 161 | (save-match-data
|
116 | 162 | (insert-file-contents filename t)
|
117 | 163 | (spacemacs//add-org-meta-readtheorg-css filename)
|
118 |
| - |
119 |
| - |
120 |
| - |
| 164 | + (spacemacs//toc-org-unhrefify-toc) |
| 165 | + (spacemacs//reroot-links) |
| 166 | + (spacemacs//org-heading-annotate-custom-id) |
121 | 167 | (apply origfunc args)
|
122 | 168 | (not-modified)))
|
123 | 169 | ;; Restore `buffer-file-name' for the buffers that previously visited the org files.
|
|
0 commit comments