emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob 4a2bc3c78183ea69f6a60e3489456ed93916abee 3633 bytes (raw)
name: contrib/lisp/org-special-blocks.el 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
;;; org-special-blocks.el --- Turn blocks into LaTeX envs and HTML divs

;; Copyright (C) 2009 Chris Gray

;; Author: Chris Gray <chrismgray@gmail.com>

;; This file is not currently part of GNU Emacs.

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program ; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:
;;

;; This package generalizes the #+begin_foo and #+end_foo tokens.

;; To use, put the following in your init file:
;;
;; (require 'org-special-blocks)

;; The tokens #+begin_center, #+begin_verse, etc. existed previously.
;; This package generalizes them (at least for the LaTeX and html
;; exporters).  When a #+begin_foo token is encountered by the LaTeX
;; exporter, it is expanded into \begin{foo}.  The text inside the
;; environment is not protected, as text inside environments generally
;; is.  When #+begin_foo is encountered by the html exporter, a div
;; with class foo is inserted into the HTML file.  It is up to the
;; user to add this class to his or her stylesheet if this div is to
;; mean anything.

(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.")

(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 htmlp latexp)
    (goto-char (point-min))
    (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(.*\\)$" nil t)
      (unless (string-match 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-\\(.*\\)-\\(START\\|END\\)$" nil t)
    (replace-match
     (if (equal (match-string 2) "START")
	 (concat "\\begin{" (match-string 1) "}")
       (concat "\\end{" (match-string 1) "}"))
     t t)))

(add-hook 'org-export-latex-after-blockquotes-hook
	  'org-special-blocks-convert-latex-special-cookies)

(defun org-special-blocks-convert-html-special-cookies ()
  "Converts the special cookies into div blocks."
  ;; Uses the dynamically-bound variable `line'.
  (when (string-match "^ORG-\\(.*\\)-\\(START\\|END\\)$" line)
;    (org-close-par-maybe)
    (message "%s" (match-string 1))
    (if (equal (match-string 2 line) "START")
	(insert "<div class=\"" (match-string 1 line) "\">\n")
      (insert "</div>\n"))
    (throw 'nextline nil)))

(add-hook 'org-export-html-after-blockquotes-hook
	  'org-special-blocks-convert-html-special-cookies)

(provide 'org-special-blocks)

;;; org-special-blocks.el ends here

debug log:

solving 4a2bc3c ...
found 4a2bc3c in https://yhetil.org/orgmode/1275433846-10077-1-git-send-email-bernt@norang.ca/
found af50b30 in https://git.savannah.gnu.org/cgit/emacs/org-mode.git
preparing index
index prepared:
100644 af50b3092db088b26b2fcf7f50c65e6d36d23640	contrib/lisp/org-special-blocks.el

applying [1/1] https://yhetil.org/orgmode/1275433846-10077-1-git-send-email-bernt@norang.ca/
diff --git a/contrib/lisp/org-special-blocks.el b/contrib/lisp/org-special-blocks.el
index af50b30..4a2bc3c 100644

Checking patch contrib/lisp/org-special-blocks.el...
Applied patch contrib/lisp/org-special-blocks.el cleanly.

index at:
100644 4a2bc3c78183ea69f6a60e3489456ed93916abee	contrib/lisp/org-special-blocks.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).