From e92ffb49a8c58a3eea3498dc8b669ac06ea3e3cd Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Sun, 26 Jun 2011 18:40:39 +0530 Subject: [PATCH] Genericize org-export-html-* variables and other misc changes. * lisp/org-html.el (org-html-should-inline-p): Removed. Re-implemented as org-lparse-should-inline-p. (org-export-html-format-href): Use org-xml-format-href. (org-export-html-format-desc): Use org-xml-format-desc (org-export-html-get-tag-class-name): Removed. (org-export-html-get-todo-kwd-class-name): Removed. (org-html-get): Added following new per-backend settings 1. INLINE-IMAGES for org-export-html-inline-images 2. INLINE-IMAGE-EXTENSIONS for org-export-html-inline-image-extensions 3. PLAIN-TEXT-MAP for org-export-html-protect-char-alist 4. TABLE-FIRST-COLUMN-AS-LABELS for org-export-html-table-use-header-tags-for-first-column 5. TODO-KWD-CLASS-PREFIX for org-export-html-todo-kwd-class-prefix 6. TAG-CLASS-PREFIX for org-export-html-tag-class-prefix * lisp/org-lparse.el (org-lparse-should-inline-p): New. (org-lparse-format-org-link): Use INLINE-IMAGE-EXTENSIONS (org-xml-encode-plain-text): Use PLAIN-TEXT-MAP (org-lparse-do-format-table-table): Misc change (org-xml-fix-class-name): New. Extracted from org-export-html-get-todo-kwd-class-name (org-lparse-format-todo): Use org-xml-fix-class-name and TODO-KWD-CLASS-PREFIX. (org-lparse-format-org-tags): Use org-xml-fix-class-name and TAG-CLASS-PREFIX. (org-xml-format-href): Renamed from org-export-html-format-href (org-xml-format-desc): Renamed form org-export-html-format-desc * lisp/org-odt.el (org-odt-format-table-cell): Use TABLE-FIRST-COLUMN-AS-LABELS. (org-odt-format-inline-image): Use org-xml-format-href. (org-odt-format-org-link): Use org-lparse-should-inline-p and org-xml-format-href, org-xml-format-desc. (org-export-odt-format-image): Use org-xml-format-desc. (org-odt-get): Provide default values for INLINE-IMAGES, INLINE-IMAGE-EXTENSIONS, PLAIN-TEXT-MAP, TABLE-FIRST-COLUMN-AS-LABELS. --- lisp/org-html.el | 67 +++++++++++++++--------------------------------------- lisp/org-lparse.el | 63 ++++++++++++++++++++++++++++++++++++++++++-------- lisp/org-odt.el | 20 +++++++++------- 3 files changed, 84 insertions(+), 66 deletions(-) diff --git a/lisp/org-html.el b/lisp/org-html.el index 257991318..157029f9e 100644 --- a/lisp/org-html.el +++ b/lisp/org-html.el @@ -673,21 +673,6 @@ See variable `org-export-html-link-org-files-as-html'" "." (plist-get opt-plist :html-extension))))))) -;;; org-html-should-inline-p -(defun org-html-should-inline-p (filename descp) - "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'." - (declare (special - org-export-html-inline-images - org-export-html-inline-image-extensions)) - (and (or (eq t org-export-html-inline-images) - (and org-export-html-inline-images (not descp))) - (org-file-image-p - filename org-export-html-inline-image-extensions))) - ;;; org-html-format-org-link (defun org-html-format-org-link (opt-plist type-1 path fragment desc attr descp) @@ -707,7 +692,7 @@ MAY-INLINE-P allows inlining it as an image." (save-match-data (let* ((may-inline-p (and (member type-1 '("http" "https" "file")) - (org-html-should-inline-p path descp) + (org-lparse-should-inline-p path descp) (not fragment))) (type (if (equal type-1 "id") "file" type-1)) (filename path) @@ -757,7 +742,7 @@ MAY-INLINE-P allows inlining it as an image." ;;Final URL-build, for all types. (setq thefile (let - ((str (org-export-html-format-href thefile))) + ((str (org-xml-format-href thefile))) (if (and type (not (or (string= "file" type) (string= "coderef" type)))) (concat type ":" str) @@ -766,7 +751,7 @@ MAY-INLINE-P allows inlining it as an image." (if may-inline-p (org-export-html-format-image thefile) (org-lparse-format - 'LINK (org-export-html-format-desc desc) thefile attr))))) + 'LINK (org-xml-format-desc desc) thefile attr))))) (defun org-html-format-inline-image (desc) ;; FIXME: alt text missing here? @@ -774,22 +759,6 @@ MAY-INLINE-P allows inlining it as an image." (defvar org-lparse-link-description-is-image) -(defun org-export-html-format-href (s) - "Make sure the S is valid as a href reference in an XHTML document." - (save-match-data - (let ((start 0)) - (while (string-match "&" s start) - (setq start (+ (match-beginning 0) 3) - s (replace-match "&" t t s))))) - s) - -(defun org-export-html-format-desc (s) - "Make sure the S is valid as a description in a link." - (if (and s (not (get-text-property 1 'org-protected s))) - (save-match-data - (org-xml-encode-org-text s)) - s)) - (defun org-export-html-format-image (src) "Create image tag with source and attributes." (save-match-data @@ -956,21 +925,6 @@ that uses these same face definitions." (goto-char (point-min))) (defvar body-only) ; dynamically scoped into this. -(defun org-export-html-get-tag-class-name (tag) - "Turn tag into a valid class name. -Replaces invalid characters with \"_\" and then prepends a prefix." - (save-match-data - (while (string-match "[^a-zA-Z0-9_]" tag) - (setq tag (replace-match "_" t t tag)))) - (concat org-export-html-tag-class-prefix tag)) - -(defun org-export-html-get-todo-kwd-class-name (kwd) - "Turn todo keyword into a valid class name. -Replaces invalid characters with \"_\" and then prepends a prefix." - (save-match-data - (while (string-match "[^a-zA-Z0-9_]" kwd) - (setq kwd (replace-match "_" t t kwd)))) - (concat org-export-html-todo-kwd-class-prefix kwd)) ;; Following variable is let bound when `org-do-lparse' is in ;; progress. See org-lparse.el. @@ -1677,6 +1631,13 @@ lang=\"%s\" xml:lang=\"%s\"> (SPECIAL-STRING-REGEXPS org-export-html-special-string-regexps) (CODING-SYSTEM-FOR-WRITE org-export-html-coding-system) (CODING-SYSTEM-FOR-SAVE org-export-html-coding-system) + (INLINE-IMAGES org-export-html-inline-images) + (INLINE-IMAGE-EXTENSIONS org-export-html-inline-image-extensions) + (PLAIN-TEXT-MAP org-export-html-protect-char-alist) + (TABLE-FIRST-COLUMN-AS-LABELS + org-export-html-table-use-header-tags-for-first-column) + (TODO-KWD-CLASS-PREFIX org-export-html-todo-kwd-class-prefix) + (TAG-CLASS-PREFIX org-export-html-tag-class-prefix) (t (error "Unknown property: %s" what)))) (defun org-html-get-coding-system-for-write () @@ -1809,6 +1770,14 @@ lang=\"%s\" xml:lang=\"%s\"> "A simple wrapper around `org-xml-encode-org-text'." (org-xml-encode-org-text s)) +(defun org-export-html-format-href (s) + "A simple wrapper around `org-xml-format-href'." + (org-xml-format-href s)) + +(defun org-export-html-format-desc (s) + "A simple wrapper around `org-xml-format-desc'." + (org-xml-format-desc s)) + (provide 'org-html) ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1 diff --git a/lisp/org-lparse.el b/lisp/org-lparse.el index bb5ad6562..2b0e3d0d5 100755 --- a/lisp/org-lparse.el +++ b/lisp/org-lparse.el @@ -30,6 +30,7 @@ ;;; Code: (require 'org-exp) +(require 'org-list) ;;;###autoload (defun org-lparse-and-open (target-backend native-backend arg) @@ -139,6 +140,18 @@ in a window. A non-interactive call will only return the buffer." (defvar org-lparse-par-open nil) +(defun org-lparse-should-inline-p (filename descp) + "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)))) + (defun org-lparse-format-org-link (line opt-plist) "Return LINE with markup of Org mode links. OPT-PLIST is the export options list." @@ -170,7 +183,7 @@ OPT-PLIST is the export options list." desc (or desc1 desc2)) ;; Make an image out of the description if that is so wanted (when (and descp (org-file-image-p - desc org-export-html-inline-image-extensions)) + desc (org-lparse-get 'INLINE-IMAGE-EXTENSIONS))) (setq org-lparse-link-description-is-image t) (save-match-data (if (string-match "^file:" desc) @@ -1068,13 +1081,16 @@ tables." (defvar org-lparse-table-style) (defvar org-lparse-table-ncols) (defvar org-lparse-table-rownum) - (defvar org-lparse-table-is-styled) (defvar org-lparse-table-begin-marker) (defvar org-lparse-table-num-numeric-items-per-column) (defvar org-lparse-table-colalign-info) (defvar org-lparse-table-colalign-vector) -(defvar org-table-number-fraction) ; defined in org-table.el + +;; Following variables are defined in org-table.el +(defvar org-table-number-fraction) +(defvar org-table-number-regexp) + (defun org-lparse-do-format-org-table (lines &optional splice) "Format a org-type table into backend-specific code. LINES is a list of lines. Optional argument SPLICE means, do not @@ -1162,7 +1178,8 @@ But it has the disadvantage, that no cell- or row-spanning is allowed." ((string-match "^[ \t]*\\+-" line) (when field-buffer (let ((org-export-table-row-tags '("" . "")) - (org-export-html-table-use-header-tags-for-first-column nil)) + ;; (org-export-html-table-use-header-tags-for-first-column nil) + ) (insert (org-lparse-format-table-row field-buffer empty))) (setq org-lparse-table-cur-rowgrp-is-hdr nil) (setq field-buffer nil))) @@ -1261,7 +1278,7 @@ for further information." (defun org-xml-encode-plain-text (s) "Convert plain text characters to HTML equivalent. Possible conversions are set in `org-export-html-protect-char-alist'." - (let ((cl org-export-html-protect-char-alist) c) + (let ((cl (org-lparse-get 'PLAIN-TEXT-MAP)) c) (while (setq c (pop cl)) (let ((start 0)) (while (string-match (car c) s start) @@ -1821,12 +1838,21 @@ When TITLE is nil, just close all open levels." ((stringp tag) ; singleton tag (concat prefix (apply 'format tag args) text)))) +(defun org-xml-fix-class-name (kwd) ; audit callers of this function + "Turn todo keyword into a valid class name. +Replaces invalid characters with \"_\"." + (save-match-data + (while (string-match "[^a-zA-Z0-9_]" kwd) + (setq kwd (replace-match "_" t t kwd)))) + kwd) (defun org-lparse-format-todo (todo) (org-lparse-format 'FONTIFY - (org-export-html-get-todo-kwd-class-name todo) - (list (if (member todo org-done-keywords) "done" "todo") - todo))) + (concat + (ignore-errors (org-lparse-get 'TODO-KWD-CLASS-PREFIX)) + (org-xml-fix-class-name todo)) + (list (if (member todo org-done-keywords) "done" "todo") + todo))) (defun org-lparse-format-extra-targets (extra-targets) (if (not extra-targets) "" @@ -1842,7 +1868,10 @@ When TITLE is nil, just close all open levels." 'FONTIFY (mapconcat (lambda (x) (org-lparse-format - 'FONTIFY x (org-export-html-get-tag-class-name x))) + 'FONTIFY x + (concat + (ignore-errors (org-lparse-get 'TAG-CLASS-PREFIX)) + (org-xml-fix-class-name x)))) (org-split-string tags ":") (org-lparse-format 'SPACES 1)) "tag"))) @@ -1856,6 +1885,22 @@ When TITLE is nil, just close all open levels." (message msg) (sleep-for 3)) +(defun org-xml-format-href (s) + "Make sure the S is valid as a href reference in an XHTML document." + (save-match-data + (let ((start 0)) + (while (string-match "&" s start) + (setq start (+ (match-beginning 0) 3) + s (replace-match "&" t t s))))) + s) + +(defun org-xml-format-desc (s) + "Make sure the S is valid as a description in a link." + (if (and s (not (get-text-property 1 'org-protected s))) + (save-match-data + (org-xml-encode-org-text s)) + s)) + (provide 'org-lparse) ;;; org-lparse.el ends here diff --git a/lisp/org-odt.el b/lisp/org-odt.el index 199a9076b..58fd3d5f0 100644 --- a/lisp/org-odt.el +++ b/lisp/org-odt.el @@ -640,7 +640,7 @@ PUB-DIR is set, use this as the publishing directory." (org-odt-format-stylized-paragraph (cond (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading") - ((and (= c 0) org-export-html-table-use-header-tags-for-first-column) + ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS)) "OrgTableHeading") (t "OrgTableContents")) data)) @@ -650,7 +650,7 @@ PUB-DIR is set, use this as the publishing directory." (concat (cond (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading") - ((and (= c 0) org-export-html-table-use-header-tags-for-first-column) + ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS)) "OrgTableHeading") (t "OrgTableContents")) (format "@@table-cell:p@@%03d@@%03d@@" r c)))) @@ -834,7 +834,7 @@ PUB-DIR is set, use this as the publishing directory." (defun org-odt-format-inline-image (thefile) (let* ((thelink (if (file-name-absolute-p thefile) thefile - (org-export-html-format-href + (org-xml-format-href (org-odt-relocate-relative-path thefile org-current-export-file)))) (href @@ -859,7 +859,7 @@ MAY-INLINE-P allows inlining it as an image." (save-match-data (let* ((may-inline-p (and (member type-1 '("http" "https" "file")) - (org-html-should-inline-p path descp) + (org-lparse-should-inline-p path descp) (not fragment))) (type (if (equal type-1 "id") "file" type-1)) (filename path) @@ -876,7 +876,7 @@ MAY-INLINE-P allows inlining it as an image." ;; (when (and (string= type "file") (file-name-absolute-p path)) ;; (setq thefile (concat "file://" (expand-file-name path)))) - ;; (setq thefile (org-export-html-format-href thefile)) + ;; (setq thefile (org-xml-format-href thefile)) ;; (org-export-html-format-image thefile) (org-odt-format-inline-image thefile)) (t @@ -892,14 +892,14 @@ MAY-INLINE-P allows inlining it as an image." fragment) (setq thefile (concat thefile "#" fragment))) - (setq thefile (org-export-html-format-href thefile)) + (setq thefile (org-xml-format-href thefile)) (when (not (member type '("" "file" "coderef"))) (setq thefile (concat type ":" thefile))) (let ((org-odt-suppress-xref (string= type "coderef"))) (org-odt-format-link - (org-export-html-format-desc desc) thefile attr))))))) + (org-xml-format-desc desc) thefile attr))))))) (defun org-odt-format-heading (text level &optional id) (let* ((text (if id (org-odt-format-target text id) text))) @@ -993,7 +993,7 @@ MAY-INLINE-P allows inlining it as an image." (t (setq caption (org-find-text-property-in-string 'org-caption src) - caption (and caption (org-export-html-format-desc caption)) + caption (and caption (org-xml-format-desc caption)) attr (org-find-text-property-in-string 'org-attributes src) label (org-find-text-property-in-string 'org-label src) embed-as 'paragraph))) @@ -1369,6 +1369,10 @@ MAY-INLINE-P allows inlining it as an image." (CONVERT-METHOD org-export-convert-process) (TOPLEVEL-HLEVEL 1) (SPECIAL-STRING-REGEXPS org-export-odt-special-string-regexps) + (INLINE-IMAGES 'maybe) + (INLINE-IMAGE-EXTENSIONS '("png" "jpeg" "jpg" "gif" "svg")) + (PLAIN-TEXT-MAP '(("&" . "&") ("<" . "<") (">" . ">"))) + (TABLE-FIRST-COLUMN-AS-LABELS nil) (t (error "Unknown property: %s" what)))) (defun org-odt-parse-label (label) -- 2.11.4.GIT