123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- (require 'org-html)
- (require 'org-compat)
- (declare-function org-open-par "org-html" ())
- (declare-function org-close-par-maybe "org-html" ())
- (defvar org-special-blocks-ignore-regexp "^\\(LaTeX\\|HTML\\)$"
- "A regexp indicating the names of blocks that should be ignored
- by org-special-blocks. These blocks will presumably be
- interpreted by other mechanisms.")
- (defvar org-export-current-backend)
- (defun org-special-blocks-make-special-cookies ()
- "Adds special cookies when #+begin_foo and #+end_foo tokens are
- seen. This is run after a few special cases are taken care of."
- (when (or (eq org-export-current-backend 'html)
- (eq org-export-current-backend 'latex))
- (goto-char (point-min))
- (while (re-search-forward "^[ \t]*#\\+\\(begin\\|end\\)_\\(.*\\)$" nil t)
- (unless (org-string-match-p org-special-blocks-ignore-regexp (match-string 2))
- (replace-match
- (if (equal (downcase (match-string 1)) "begin")
- (concat "ORG-" (match-string 2) "-START")
- (concat "ORG-" (match-string 2) "-END"))
- t t)))))
- (add-hook 'org-export-preprocess-after-blockquote-hook
- 'org-special-blocks-make-special-cookies)
- (defun org-special-blocks-convert-latex-special-cookies ()
- "Converts the special cookies into LaTeX blocks."
- (goto-char (point-min))
- (while (re-search-forward "^ORG-\\([^ \t\n]*\\)[ \t]*\\(.*\\)-\\(START\\|END\\)$" nil t)
- (replace-match
- (if (equal (match-string 3) "START")
- (concat "\\begin{" (match-string 1) "}" (match-string 2))
- (concat "\\end{" (match-string 1) "}"))
- t t)))
- (add-hook 'org-export-latex-after-blockquotes-hook
- 'org-special-blocks-convert-latex-special-cookies)
- (defvar line)
- (defun org-special-blocks-convert-html-special-cookies ()
- "Converts the special cookies into div blocks."
-
- (when (string-match "^ORG-\\(.*\\)-\\(START\\|END\\)$" line)
- (message "%s" (match-string 1))
- (when (equal (match-string 2 line) "START")
- (org-close-par-maybe)
- (insert "\n<div class=\"" (match-string 1 line) "\">")
- (org-open-par))
- (when (equal (match-string 2 line) "END")
- (org-close-par-maybe)
- (insert "\n</div>")
- (org-open-par))
- (throw 'nextline nil)))
- (add-hook 'org-export-html-after-blockquotes-hook
- 'org-special-blocks-convert-html-special-cookies)
- (provide 'org-special-blocks)
|