1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-28 10:56:57 +00:00

Export: Better handling of colon examples.

Lines preceded by a colon are treated as fixed-width examples.
This commit improves the moment when the protection of these lines
happens during preprocessing.  And it enforces that a space must
follow the colon for the line to be treated in this way.
This commit is contained in:
Carsten Dominik 2009-01-09 08:28:43 +01:00
parent 907d548353
commit b3d6d903bc
6 changed files with 61 additions and 21 deletions

View File

@ -15,6 +15,17 @@
:VISIBILITY: content
:END:
** Incompatible changes
*** Short examples must have a space after the colon
Short literal examples can be created by preceeding lines
with a colon. Such lines must now have a space after the
colon. I believe this is already general practice, but now
it must be like this. The only exception are lines what are
empty except for the colon.
** Details
*** The relative timer can be paused

View File

@ -1,3 +1,8 @@
2009-01-09 Carsten Dominik <carsten.dominik@gmail.com>
* org.texi (Literal examples): Document that a space must follow
the colon in short examples.
2009-01-08 Carsten Dominik <carsten.dominik@gmail.com>
* org.texi (Relative timer): Document `org-timer-stop'.

View File

@ -7376,10 +7376,12 @@ Some example from a text file.
@end example
For simplicity when using small examples, you can also start the example
lines with a colon:
lines with a colon followed by a space. There may also be additional
whitespace before the colon:
@example
: Some example from a text file.
Here is an example
: Some example from a text file.
@end example
@cindex formatting source code, markup rules

View File

@ -1,3 +1,18 @@
2009-01-09 Carsten Dominik <carsten.dominik@gmail.com>
* org-export-latex.el (org-export-latex-fixed-width): Enforce the
space after the colon in short examples.
* org-exp.el (org-export-protect-colon-examples): Rewritten, to
enforce a space after the colon. However, we also allow lines
that are *only* a colon.
(org-export-as-html): Enforce the space after the colon in short
examples.
(org-export-preprocess-string): Do the colon example protection
earlier.
(org-export-remove-timestamps): Do not check for protection at the
end of the line.
2009-01-08 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-format-latex-options): Add new matcher for single

View File

@ -1527,6 +1527,9 @@ on this string to produce the exported version."
;; Handle source code snippets
(org-export-replace-src-segments-and-examples backend)
;; Protect short examples marked by a leading colon
(org-export-protect-colon-examples)
;; Normalize footnotes
(when (plist-get parameters :footnotes)
(org-footnote-normalize nil t))
@ -1552,19 +1555,12 @@ on this string to produce the exported version."
;; Remove todo-keywords before exporting, if the user has requested so
(org-export-remove-headline-metadata parameters)
;; Remove timestamps, if the user has requested so
(org-export-remove-clock-lines)
(unless (plist-get parameters :timestamps)
(org-export-remove-timestamps))
;; Find targets in comments and move them out of comments,
;; but mark them as targets that should be invisible
(setq target-alist (org-export-handle-invisible-targets target-alist))
;; Protect short examples
(org-export-protect-colon-examples)
;; Protect backend specific stuff, throw away the others.
;; Select and protect backend specific stuff, throw away stuff
;; that is specific for other backends
(org-export-select-backend-specific-text backend)
;; Protect quoted subtrees
@ -1576,6 +1572,11 @@ on this string to produce the exported version."
;; Blockquotes and verse
(org-export-mark-blockquote-and-verse)
;; Remove timestamps, if the user has requested so
(org-export-remove-clock-lines)
(unless (plist-get parameters :timestamps)
(org-export-remove-timestamps))
;; Attach captions to the correct object
(setq target-alist (org-export-attach-captions-and-attributes
backend target-alist))
@ -1606,16 +1607,16 @@ on this string to produce the exported version."
;; Another hook
(run-hooks 'org-export-preprocess-before-backend-specifics-hook)
;; Specific LaTeX stuff
;; LaTeX-specific preprocessing
(when latexp
(require 'org-export-latex nil)
(org-export-latex-preprocess))
;; Specific ASCII stuff
;; ASCII-specific preprocessing
(when asciip
(org-export-ascii-preprocess))
;; Specific HTML stuff
;; HTML-specific preprocessing
(when htmlp
(org-export-html-preprocess parameters))
@ -1887,9 +1888,15 @@ from the buffer."
(defun org-export-protect-colon-examples ()
"Protect lines starting with a colon."
(goto-char (point-min))
(while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t)
(add-text-properties (match-beginning 0) (match-end 0)
'(org-protected t))))
(let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg end)
(while (re-search-forward re nil t)
(beginning-of-line 1)
(setq beg (point))
(while (looking-at re)
(end-of-line 1)
(or (eobp) (forward-char 1)))
(add-text-properties beg (if (bolp) (1- (point)) (point))
'(org-protected t)))))
(defun org-export-select-backend-specific-text (backend)
(let ((formatters
@ -3440,7 +3447,7 @@ lang=\"%s\" xml:lang=\"%s\">
;; Fixed-width, verbatim lines (examples)
(when (and org-export-with-fixed-width
(string-match "^[ \t]*:\\(.*\\)" line))
(string-match "^[ \t]*:\\(\\([ \t]\\|$\\).*\\)" line))
(when (not infixed)
(setq infixed t)
(org-close-par-maybe)

View File

@ -1022,17 +1022,17 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
(defun org-export-latex-fixed-width (opt)
"When OPT is non-nil convert fixed-width sections to LaTeX."
(goto-char (point-min))
(while (re-search-forward "^[ \t]*:" nil t)
(while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
(if opt
(progn (goto-char (match-beginning 0))
(insert "\\begin{verbatim}\n")
(while (looking-at "^\\([ \t]*\\):\\(.*\\)$")
(while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
(replace-match (concat (match-string 1)
(match-string 2)) t t)
(forward-line))
(insert "\\end{verbatim}\n\n"))
(progn (goto-char (match-beginning 0))
(while (looking-at "^\\([ \t]*\\):\\(.*\\)$")
(while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
(replace-match (concat "%" (match-string 1)
(match-string 2)) t t)
(forward-line))))))