((file-exists-p file-or-buf) file-or-buf)
(t (error "org-lparse-and-open: This shouldn't happen"))))
(message "Opening file %s" f)
- (org-open-file f)
+ (org-open-file f 'system)
(when org-export-kill-product-buffer-when-displayed
(kill-buffer (current-buffer))))))
No file is created. The prefix ARG is passed through to
`org-lparse'."
(let ((tempbuf (format "*Org %s Export*" (upcase backend))))
- (org-lparse backend backend arg nil nil tempbuf)
- (when org-export-show-temporary-export-buffer
- (switch-to-buffer-other-window tempbuf))))
+ (org-lparse backend backend arg nil nil tempbuf)
+ (when org-export-show-temporary-export-buffer
+ (switch-to-buffer-other-window tempbuf))))
;;;###autoload
(defun org-replace-region-by (backend beg end)
this command to convert it."
(let (reg backend-string buf pop-up-frames)
(save-window-excursion
- (if (eq major-mode 'org-mode)
+ (if (derived-mode-p 'org-mode)
(setq backend-string (org-lparse-region backend beg end t 'string))
(setq reg (buffer-substring beg end)
buf (get-buffer-create "*Org tmp*"))
(defvar org-lparse-par-open nil)
(defun org-lparse-should-inline-p (filename descp)
- "Return non-nil if link FILENAME should be inlined.
+ "Return non-nil if link FILENAME should be inlined.
The decision to inline the FILENAME link is based on the current
settings. DESCP is the boolean of whether there was a link
description. See variables `org-export-html-inline-images' and
`org-export-html-inline-image-extensions'."
- (let ((inline-images (org-lparse-get 'INLINE-IMAGES))
- (inline-image-extensions
- (org-lparse-get 'INLINE-IMAGE-EXTENSIONS)))
- (and (or (eq t inline-images) (and inline-images (not descp)))
- (org-file-image-p filename inline-image-extensions))))
+ (let ((inline-images (org-lparse-get 'INLINE-IMAGES))
+ (inline-image-extensions
+ (org-lparse-get 'INLINE-IMAGE-EXTENSIONS)))
+ (and (or (eq t inline-images) (and inline-images (not descp)))
+ (org-file-image-p filename inline-image-extensions))))
(defun org-lparse-format-org-link (line opt-plist)
"Return LINE with markup of Org mode links.
(org-lparse-reachable-p native-backend target-backend))
(error "Don't know how to export to backend %s %s" target-backend
(format "via %s" native-backend)))
- (run-hooks 'org-export-first-hook)
(org-do-lparse arg hidden ext-plist to-buffer body-only pub-dir)))
(defcustom org-lparse-use-flashy-warning nil
(error "Cannot convert from %s format to %s format?"
in-fmt out-fmt)))
(convert-process (car how))
- (program (car convert-process))
- (dummy (and (or program (error "Converter not configured"))
- (or (executable-find program)
- (error "Cannot find converter %s" program))))
(out-file (concat (file-name-sans-extension in-file) "."
(nth 1 (or (cdr how) out-fmt))))
+ (extra-options (or (nth 2 (cdr how)) ""))
(out-dir (file-name-directory in-file))
- (arglist (mapcar (lambda (arg)
- (format-spec
- arg `((?i . ,in-file)
- (?I . ,(browse-url-file-url in-file))
- (?f . ,out-fmt)
- (?o . ,out-file)
- (?O . ,(browse-url-file-url out-file))
- (?d . ,out-dir)
- (?D . ,(browse-url-file-url out-dir)))))
- (cdr convert-process))))
+ (cmd (format-spec convert-process
+ `((?i . ,(shell-quote-argument in-file))
+ (?I . ,(browse-url-file-url in-file))
+ (?f . ,out-fmt)
+ (?o . ,out-file)
+ (?O . ,(browse-url-file-url out-file))
+ (?d . , (shell-quote-argument out-dir))
+ (?D . ,(browse-url-file-url out-dir))
+ (?x . ,extra-options)))))
(when (file-exists-p out-file)
(delete-file out-file))
- (message "Executing %s %s" program (mapconcat 'identity arglist " "))
- (apply 'call-process program nil nil nil arglist)
+ (message "Executing %s" cmd)
+ (let ((cmd-output (shell-command-to-string cmd)))
+ (message "%s" cmd-output))
+
(cond
((file-exists-p out-file)
- (message "Exported to %s using %s" out-file program)
+ (message "Exported to %s" out-file)
(when prefix-arg
(message "Opening %s..." out-file)
- (org-open-file out-file))
- out-file
- ;; (set-buffer (find-file-noselect out-file))
- )
+ (org-open-file out-file 'system))
+ out-file)
(t
(message "Export to %s failed" out-file)
nil))))
(defun org-do-lparse (arg &optional hidden ext-plist
to-buffer body-only pub-dir)
"Export the outline to various formats.
-See `org-lparse' for more information. This function is a
+See `org-lparse' for more information. This function is a
html-agnostic version of the `org-export-as-html' function in 7.5
version."
;; Make sure we have a file name when we need it.
(setq-default org-deadline-line-regexp org-deadline-line-regexp)
(setq-default org-done-keywords org-done-keywords)
(setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
+
+ ;; Run first hook.
+ (run-hooks 'org-export-first-hook)
+
+ ;; Add pre-process hooks.
+ (add-hook 'org-export-preprocess-hook
+ 'org-lparse-strip-experimental-blocks-maybe)
+ (add-hook 'org-export-preprocess-after-blockquote-hook
+ 'org-lparse-preprocess-after-blockquote)
+
(let* (hfy-user-sheet-assoc ; let `htmlfontify' know that
; we are interested in
; collecting styles
(org-lparse-par-open-stashed 0)
;; list related vars
- (org-lparse-list-level 0) ; list level starts at 1. A
- ; value of 0 implies we are
- ; outside of any list
- (org-lparse-list-item-count 0)
- org-lparse-list-stack
+ (org-lparse-list-stack '())
;; list-table related vars
org-lparse-list-table-p
;; collection
org-lparse-collect-buffer
(org-lparse-collect-count 0) ; things will get haywire if
- ; collections are chained. Use
+ ; collections are chained. Use
; this variable to assert this
; pre-requisite
org-lparse-toc
href
)
+ ;; Remove pre-process hooks.
+ (remove-hook 'org-export-preprocess-hook
+ 'org-lparse-strip-experimental-blocks-maybe)
+ (remove-hook 'org-export-preprocess-after-blockquote-hook
+ 'org-lparse-preprocess-after-blockquote)
(let ((inhibit-read-only t))
(org-unmodified
(setq umax-toc (if (integerp org-export-with-toc)
(min org-export-with-toc umax)
umax))
+ (setq org-lparse-opt-plist
+ (plist-put org-lparse-opt-plist :headline-levels umax))
(when (and org-export-with-toc (not body-only))
(setq lines (org-lparse-prepare-toc
(org-lparse-end-environment 'fixedwidth))
(throw 'nextline nil))
- ;; Notes: The baseline version of org-html.el (git commit
- ;; 3d802e), while encountering a *line-long* protected text,
- ;; does one of the following two things based on the state
- ;; of the export buffer.
-
- ;; 1. If a paragraph element has just been opened and
- ;; contains only whitespace as content, insert the
- ;; protected text as part of the previous paragraph.
-
- ;; 2. If the paragraph element has already been opened and
- ;; contains some valid content insert the protected text
- ;; as part of the current paragraph.
-
- ;; I think --->
-
- ;; Scenario 1 mentioned above kicks in when a block of
- ;; protected text has to be inserted en bloc. For example,
- ;; this happens, when inserting an source or example block
- ;; or preformatted content enclosed in #+backend,
- ;; #+begin_backend ... #+end_backend)
-
- ;; Scenario 2 mentioned above kicks in when the protected
- ;; text is part of a running sentence. For example this
- ;; happens in the case of an *multiline* LaTeX equation that
- ;; needs to be inserted verbatim.
-
- ;; org-html.el in the master branch seems to do some
- ;; jugglery by moving paragraphs around. Inorder to make
- ;; these changes backend-agnostic introduce a new text
- ;; property org-native-text and impose the added semantics
- ;; that these protected blocks appear outside of a
- ;; conventional paragraph element.
- ;;
- ;; Extra Note: Check whether org-example and org-native-text
- ;; are entirely equivalent.
-
- ;; Fixes bug reported by Christian Moe concerning verbatim
- ;; LaTeX fragments.
- ;; on git commit 533ba3f90250a1f25f494c390d639ea6274f235c
- ;; http://repo.or.cz/w/org-mode/org-jambu.git/shortlog/refs/heads/staging
- ;; See http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01379.html
-
;; Native Text
(when (and (get-text-property 0 'org-native-text line)
;; Make sure it is the entire line that is protected
(funcall f style env-options-plist)
(throw 'nextline nil))))
- (run-hooks 'org-export-html-after-blockquotes-hook)
(when (org-lparse-current-environment-p 'verse)
(let ((i (org-get-string-indentation line)))
(if (> i 0)
table-buffer (nreverse table-buffer)
table-orig-buffer (nreverse table-orig-buffer))
(org-lparse-end-paragraph)
+ (when org-lparse-list-table-p
+ (error "Regular tables are not allowed in a list-table block"))
(org-lparse-insert 'TABLE table-buffer table-orig-buffer)))
;; Normal lines
-
(t
;; This line either is list item or end a list.
(when (get-text-property 0 'list-item line)
(unless body-only
(org-lparse-end 'DOCUMENT-CONTENT))
- (unless (plist-get opt-plist :buffer-will-be-killed)
- (set-auto-mode t))
-
(org-lparse-end 'EXPORT)
;; kill collection buffer
(defun org-lparse-table-get-colalign-info (lines)
(let ((col-cookies (org-find-text-property-in-string
- 'org-col-cookies (car lines))))
+ 'org-col-cookies (car lines))))
(when (and col-cookies org-table-clean-did-remove-column)
(setq col-cookies
(mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies)))
;; column and the special lines
(setq lines (org-table-clean-before-export lines)))
(let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
+ (short-caption (or (org-find-text-property-in-string
+ 'org-caption-shortn (car lines)) caption))
(caption (and caption (org-xml-encode-org-text caption)))
+ (short-caption (and short-caption
+ (org-xml-encode-plain-text short-caption)))
(label (org-find-text-property-in-string 'org-label (car lines)))
(org-lparse-table-colalign-info (org-lparse-table-get-colalign-info lines))
(attributes (org-find-text-property-in-string 'org-attributes
(cdr lines))))))
(setq lines (org-lparse-org-table-to-list-table lines splice))
(org-lparse-insert-list-table
- lines splice caption label attributes head org-lparse-table-colalign-info)))
+ lines splice caption label attributes head org-lparse-table-colalign-info
+ short-caption)))
(defun org-lparse-insert-list-table (lines &optional splice
- caption label attributes head
- org-lparse-table-colalign-info)
+ caption label attributes head
+ org-lparse-table-colalign-info
+ short-caption)
(or (featurep 'org-table) ; required for
(require 'org-table)) ; `org-table-number-regexp'
(let* ((org-lparse-table-rownum -1) org-lparse-table-ncols i (cnt 0)
(insert (org-lparse-format-table-row line) "\n")))
(t
(setq org-lparse-table-is-styled t)
- (org-lparse-begin 'TABLE caption label attributes)
+ (org-lparse-begin 'TABLE caption label attributes short-caption)
(setq org-lparse-table-begin-marker (point))
(org-lparse-begin-table-rowgroup head)
(while (setq line (pop lines))
(org-lparse-table-cur-rowgrp-is-hdr
org-export-highlight-first-table-line)
(caption nil)
+ (short-caption nil)
(attributes nil)
(label nil)
(org-lparse-table-style 'table-table)
(org-lparse-table-is-styled nil)
fields org-lparse-table-ncols i (org-lparse-table-rownum -1)
(empty (org-lparse-format 'SPACES 1)))
- (org-lparse-begin 'TABLE caption label attributes)
+ (org-lparse-begin 'TABLE caption label attributes short-caption)
(while (setq line (pop lines))
(cond
((string-match "^[ \t]*\\+-" line)
(defvar table-source-languages) ; defined in table.el
(defun org-lparse-format-table-table-using-table-generate-source (backend
- lines
- &optional
- spanned-only)
+ lines
+ &optional
+ spanned-only)
"Format a table into BACKEND, using `table-generate-source' from table.el.
Use SPANNED-ONLY to suppress exporting of simple table.el tables.
(set-buffer " org-tmp2 ")
(buffer-substring (point-min) (point-max)))
(t
- ;; table.el doesn't support the given backend. Currently this
+ ;; table.el doesn't support the given backend. Currently this
;; happens in case of odt export. Strip the table from the
- ;; generated document. A better alternative would be to embed
+ ;; generated document. A better alternative would be to embed
;; the table as ascii text in the output document.
(org-lparse-warn
(concat
(org-lparse-end-paragraph)
(org-lparse-end-list-item (or type "u")))
-(defun org-lparse-preprocess-after-blockquote-hook ()
+(define-obsolete-function-alias
+ 'org-lparse-preprocess-after-blockquote-hook
+ 'org-lparse-preprocess-after-blockquote
+ "24.3")
+
+(defun org-lparse-preprocess-after-blockquote ()
"Treat `org-lparse-special-blocks' specially."
(goto-char (point-min))
(while (re-search-forward
(format "ORG-%s-END %s" (upcase (match-string 2))
(match-string 3))) t t))))
-(add-hook 'org-export-preprocess-after-blockquote-hook
- 'org-lparse-preprocess-after-blockquote-hook)
+(define-obsolete-function-alias
+ 'org-lparse-strip-experimental-blocks-maybe-hook
+ 'org-lparse-strip-experimental-blocks-maybe
+ "24.3")
-(defun org-lparse-strip-experimental-blocks-maybe-hook ()
+(defun org-lparse-strip-experimental-blocks-maybe ()
"Strip \"list-table\" and \"annotation\" blocks.
Stripping happens only when the exported backend is not one of
\"odt\" or \"xhtml\"."
(when (member (match-string 1) org-lparse-special-blocks)
(replace-match "" t t))))))
-(add-hook 'org-export-preprocess-hook
- 'org-lparse-strip-experimental-blocks-maybe-hook)
-
(defvar org-lparse-list-table-p nil
"Non-nil if `org-do-lparse' is within a list-table.")
(org-lparse-end 'FOOTNOTE-DEFINITION n)
(setq org-lparse-insert-tag-with-newlines 'both)
(let ((footnote-def (org-lparse-end-collect)))
+ ;; Cleanup newlines in footnote definition. This ensures that a
+ ;; transcoded line is never (wrongly) broken in to multiple lines.
+ (let ((pos 0))
+ (while (string-match "[\r\n]+" footnote-def pos)
+ (setq pos (1+ (match-beginning 0)))
+ (setq footnote-def (replace-match " " t t footnote-def))))
(push (cons n footnote-def) org-lparse-footnote-definitions)))
(defvar org-lparse-collect-buffer nil
(replace-match
(let ((org-lparse-encode-pending t))
(org-lparse-format 'FONTIFY
- (match-string 1 line) "target"))
+ (match-string 1 line) "target"))
t t line)))
(when (string-match
(org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
(cond
((string= align "l") "left")
((string= align "r") "right")
- ((string= align "c") "center")
- (t nil))))))))
+ ((string= align "c") "center"))))))))
(incf org-lparse-table-rownum)
(let ((i -1))
(org-lparse-format
(defvar org-lparse-outline-text-open)
(defun org-lparse-begin-outline-and-outline-text (level1 snumber title tags
- target extra-targets
- extra-class)
+ target extra-targets
+ extra-class)
(org-lparse-begin
'OUTLINE level1 snumber title tags target extra-targets extra-class)
(org-lparse-begin-outline-text level1 snumber extra-class))
("d" . description)))))
;; following vars are bound during `org-do-lparse'
-(defvar org-lparse-list-level)
-(defvar org-lparse-list-item-count)
(defvar org-lparse-list-stack)
(defvar org-lparse-list-table:table-row)
(defvar org-lparse-list-table:lines)
;; Note that org-tables are NOT multi-line and each line is mapped to
;; a unique row in the exported document. So if an exported table
;; needs to contain a single paragraph (with copious text) it needs to
-;; be typed up in a single line. Editing such long lines using the
+;; be typed up in a single line. Editing such long lines using the
;; table editor will be a cumbersome task. Furthermore inclusion of
;; multi-paragraph text in a table cell is well-nigh impossible.
;;
;; https://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01101.html
(defun org-lparse-begin-list (ltype)
- (incf org-lparse-list-level)
- (push org-lparse-list-item-count org-lparse-list-stack)
- (setq org-lparse-list-item-count 0)
- (cond
- ((not org-lparse-list-table-p)
- (org-lparse-begin 'LIST ltype))
- ;; process LIST-TABLE
- ((= 1 org-lparse-list-level)
- ;; begin LIST-TABLE
- (setq org-lparse-list-table:lines nil)
- (setq org-lparse-list-table:table-row nil))
- ((= 2 org-lparse-list-level)
- (ignore))
- (t
- (org-lparse-begin 'LIST ltype))))
+ (push ltype org-lparse-list-stack)
+ (let ((list-level (length org-lparse-list-stack)))
+ (cond
+ ((not org-lparse-list-table-p)
+ (org-lparse-begin 'LIST ltype))
+ ;; process LIST-TABLE
+ ((= 1 list-level)
+ ;; begin LIST-TABLE
+ (setq org-lparse-list-table:lines nil)
+ (setq org-lparse-list-table:table-row nil))
+ ((= 2 list-level)
+ (ignore))
+ (t
+ (org-lparse-begin 'LIST ltype)))))
(defun org-lparse-end-list (ltype)
- (setq org-lparse-list-item-count (pop org-lparse-list-stack))
- (decf org-lparse-list-level)
- (cond
- ((not org-lparse-list-table-p)
- (org-lparse-end 'LIST ltype))
- ;; process LIST-TABLE
- ((= 0 org-lparse-list-level)
- ;; end LIST-TABLE
- (insert (org-lparse-format-list-table
- (nreverse org-lparse-list-table:lines))))
- ((= 1 org-lparse-list-level)
- (ignore))
- (t
- (org-lparse-end 'LIST ltype))))
+ (pop org-lparse-list-stack)
+ (let ((list-level (length org-lparse-list-stack)))
+ (cond
+ ((not org-lparse-list-table-p)
+ (org-lparse-end 'LIST ltype))
+ ;; process LIST-TABLE
+ ((= 0 list-level)
+ ;; end LIST-TABLE
+ (insert (org-lparse-format-list-table
+ (nreverse org-lparse-list-table:lines))))
+ ((= 1 list-level)
+ (ignore))
+ (t
+ (org-lparse-end 'LIST ltype)))))
(defun org-lparse-begin-list-item (ltype &optional arg headline)
- (incf org-lparse-list-item-count)
- (cond
- ((not org-lparse-list-table-p)
- (org-lparse-begin 'LIST-ITEM ltype arg headline))
- ;; process LIST-TABLE
- ((and (= 1 org-lparse-list-level)
- (= 1 org-lparse-list-item-count))
- ;; begin TABLE-ROW for LIST-TABLE
- (setq org-lparse-list-table:table-row nil)
- (org-lparse-begin-list-table:table-cell))
- ((and (= 2 org-lparse-list-level)
- (= 1 org-lparse-list-item-count))
- ;; begin TABLE-CELL for LIST-TABLE
- (org-lparse-begin-list-table:table-cell))
- (t
- (org-lparse-begin 'LIST-ITEM ltype arg headline))))
+ (let ((list-level (length org-lparse-list-stack)))
+ (cond
+ ((not org-lparse-list-table-p)
+ (org-lparse-begin 'LIST-ITEM ltype arg headline))
+ ;; process LIST-TABLE
+ ((= 1 list-level)
+ ;; begin TABLE-ROW for LIST-TABLE
+ (setq org-lparse-list-table:table-row nil)
+ (org-lparse-begin-list-table:table-cell))
+ ((= 2 list-level)
+ ;; begin TABLE-CELL for LIST-TABLE
+ (org-lparse-begin-list-table:table-cell))
+ (t
+ (org-lparse-begin 'LIST-ITEM ltype arg headline)))))
(defun org-lparse-end-list-item (ltype)
- (decf org-lparse-list-item-count)
- (cond
- ((not org-lparse-list-table-p)
- (org-lparse-end 'LIST-ITEM ltype))
- ;; process LIST-TABLE
- ((and (= 1 org-lparse-list-level)
- (= 0 org-lparse-list-item-count))
- ;; end TABLE-ROW for LIST-TABLE
- (org-lparse-end-list-table:table-cell)
- (push (nreverse org-lparse-list-table:table-row)
- org-lparse-list-table:lines))
- ((= 2 org-lparse-list-level)
- ;; end TABLE-CELL for LIST-TABLE
- (org-lparse-end-list-table:table-cell))
- (t
- (org-lparse-end 'LIST-ITEM ltype))))
+ (let ((list-level (length org-lparse-list-stack)))
+ (cond
+ ((not org-lparse-list-table-p)
+ (org-lparse-end 'LIST-ITEM ltype))
+ ;; process LIST-TABLE
+ ((= 1 list-level)
+ ;; end TABLE-ROW for LIST-TABLE
+ (org-lparse-end-list-table:table-cell)
+ (push (nreverse org-lparse-list-table:table-row)
+ org-lparse-list-table:lines))
+ ((= 2 list-level)
+ ;; end TABLE-CELL for LIST-TABLE
+ (org-lparse-end-list-table:table-cell))
+ (t
+ (org-lparse-end 'LIST-ITEM ltype)))))
(defvar org-lparse-list-table:table-cell-open)
(defun org-lparse-begin-list-table:table-cell ()
(defun org-lparse-format-extra-targets (extra-targets)
(if (not extra-targets) ""
- (mapconcat (lambda (x)
- (setq x (org-solidify-link-text
- (if (org-uuidgen-p x) (concat "ID-" x) x)))
- (org-lparse-format 'ANCHOR "" x))
- extra-targets "")))
+ (mapconcat (lambda (x)
+ (setq x (org-solidify-link-text
+ (if (org-uuidgen-p x) (concat "ID-" x) x)))
+ (org-lparse-format 'ANCHOR "" x))
+ extra-targets "")))
(defun org-lparse-format-org-tags (tags)
(if (not tags) ""