From b65725e039b97748a6386192025ace8b5ee8d510 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Fri, 2 Mar 2012 13:10:12 +0530 Subject: [PATCH] org-e-html/org-e-odt: Support for code numbering --- EXPERIMENTAL/org-e-html.el | 72 ++++++++++++++++++++++------------------- EXPERIMENTAL/org-e-odt.el | 80 +++++++++++++++++++++++++--------------------- 2 files changed, 83 insertions(+), 69 deletions(-) diff --git a/EXPERIMENTAL/org-e-html.el b/EXPERIMENTAL/org-e-html.el index 4849db2b6..02ba2ef04 100644 --- a/EXPERIMENTAL/org-e-html.el +++ b/EXPERIMENTAL/org-e-html.el @@ -1855,35 +1855,33 @@ contextual information." ;; (defun org-odt-format-source-code-or-example-colored ;; (lines lang caption textareap cols rows num cont rpllbl fmt)) +(defun org-e-html-format-source-line-with-line-number-and-label (line) + (let ((ref (org-find-text-property-in-string 'org-coderef line)) + (num (org-find-text-property-in-string 'org-loc line))) + (when num + (setq line (format "%d: %s (%s)" + num line ref))) + (when ref + (setq line + (format + "%s (%s)" + ref line ref))) + line)) + (defun org-e-html-format-source-code-or-example-plain (lines lang caption textareap cols rows num cont rpllbl fmt) - (setq lines - (concat - "
\n"
-	 (cond
-	  (textareap
-	   (concat
-	    (format "

\n\n

\n")) - (t - (with-temp-buffer - (insert lines) - (goto-char (point-min)) - (while (re-search-forward "[<>&]" nil t) - (replace-match (cdr (assq (char-before) - '((?&."&")(?<."<")(?>.">")))) - t t)) - (buffer-string)))) - "
\n")) - - (unless textareap - (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt))) - - ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines) - ;; (setq lines (replace-match "\\1" t nil lines))) - - lines) + (format + "\n
\n%s\n
" + (cond + (textareap + (format "

\n\n

\n" + cols rows lines)) + (t (mapconcat + (lambda (line) + (org-e-html-format-source-line-with-line-number-and-label + (org-e-html-encode-plain-text line))) + (org-split-string lines "\n") + "\n"))))) (defun org-e-html-format-source-code-or-example-colored (lines lang caption textareap cols rows num cont rpllbl fmt) @@ -1925,7 +1923,11 @@ contextual information." lines ""))) (unless textareap - (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt))) + (setq lines + (mapconcat + (lambda (line) + (org-e-html-format-source-line-with-line-number-and-label line)) + (org-split-string lines "\n") "\n"))) ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines) ;; (setq lines (replace-match "\\1" t nil lines))) @@ -2008,7 +2010,7 @@ INDENT was the original indentation of the block." "Transcode a EXAMPLE-BLOCK element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (let* ((options (or (org-element-property :options example-block) "")) - (value (org-export-handle-code example-block info))) + (value (org-export-handle-code example-block info nil nil t))) ;; (org-e-html--wrap-label ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value)) (org-e-html--wrap-label @@ -2590,8 +2592,14 @@ INFO is a plist holding contextual information. See ;; Coderef: replace link with the reference name or the ;; equivalent line number. ((string= type "coderef") - (format (org-export-get-coderef-format path (or desc "")) - (org-export-resolve-coderef path info))) + (let ((fragment (concat "coderef-" path))) + (format "%s" fragment + (format (concat "class=\"coderef\"" + " onmouseover=\"CodeHighlightOn(this, '%s');\"" + " onmouseout=\"CodeHighlightOff(this, '%s');\"") + fragment fragment) + (format (org-export-get-coderef-format path (or desc "%s")) + (org-export-resolve-coderef path info))))) ;; Link type is handled by a special function. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols)))) (funcall protocol (org-link-unescape path) desc 'html)) @@ -2808,7 +2816,7 @@ holding contextual information." CONTENTS holds the contents of the item. INFO is a plist holding contextual information." (let* ((lang (org-element-property :language src-block)) - (code (org-export-handle-code src-block info)) + (code (org-export-handle-code src-block info nil nil t)) (caption (org-element-property :caption src-block)) (label (org-element-property :name src-block))) ;; FIXME: Handle caption diff --git a/EXPERIMENTAL/org-e-odt.el b/EXPERIMENTAL/org-e-odt.el index fc768781b..9cbf9299e 100644 --- a/EXPERIMENTAL/org-e-odt.el +++ b/EXPERIMENTAL/org-e-odt.el @@ -566,7 +566,7 @@ styles congruent with the ODF-1.2 specification." (let ((xref-format "text")) (when (numberp desc) (setq desc (format "%d" desc) xref-format "number")) - (org-e-odt-format-tags + (org-e-odt-format-tags-simple '("" . "") desc xref-format href))) @@ -575,7 +575,7 @@ styles congruent with the ODF-1.2 specification." '("" . "") desc href (or attr ""))) (t - (org-e-odt-format-tags + (org-e-odt-format-tags-simple '("" . "") desc href (or attr ""))))) @@ -625,17 +625,18 @@ styles congruent with the ODF-1.2 specification." (defun org-e-odt-format-source-line-with-line-number-and-label - (line rpllbl num fontifier par-style) - - (let ((keep-label (not (numberp rpllbl))) - (ref (org-find-text-property-in-string 'org-coderef line))) - (setq line (concat line (and keep-label ref (format "(%s)" ref)))) + (line fontifier par-style) + (let (;; (keep-label (not (numberp rpllbl))) + (ref (org-find-text-property-in-string 'org-coderef line)) + (num (org-find-text-property-in-string 'org-loc line))) + (setq line (concat line (and ref (format "(%s)" ref)))) (setq line (funcall fontifier line)) (when ref (setq line (org-e-odt-format-target line (concat "coderef-" ref)))) (setq line (org-e-odt-format-stylized-paragraph par-style line)) (if (not num) line - (org-e-odt-format-tags '("" . "") line)))) + (org-e-odt-format-tags + '("" . "") line)))) (defun org-e-odt-format-source-code-or-example-plain (lines lang caption textareap cols rows num cont rpllbl fmt) @@ -649,7 +650,7 @@ off." (lambda (line) (incf i) (org-e-odt-format-source-line-with-line-number-and-label - line rpllbl num 'org-e-odt-encode-plain-text + line 'org-e-odt-encode-plain-text (if (= i line-count) "OrgFixedWidthBlockLastLine" "OrgFixedWidthBlock"))) lines "\n"))) @@ -701,8 +702,7 @@ Update styles.xml with styles that were collected as part of (goto-char (match-beginning 0)) (insert "\n\n" styles "\n"))))) -(defun org-e-odt-format-source-code-or-example-colored - (lines lang caption textareap cols rows num cont rpllbl fmt) +(defun org-e-odt-format-source-code-or-example-colored (lines lang caption) "Format source or example blocks using `htmlfontify-string'. Use this routine when `org-export-e-odt-fontify-srcblocks' option is turned on." @@ -740,37 +740,37 @@ is turned on." (lambda (line) (incf i) (org-e-odt-format-source-line-with-line-number-and-label - line rpllbl num 'htmlfontify-string + line 'htmlfontify-string (if (= i line-count) "OrgSrcBlockLastLine" "OrgSrcBlock"))) lines "\n"))))) (defun org-e-odt-format-source-code-or-example (lines lang - &optional - caption textareap - cols rows num cont - rpllbl fmt) + &optional caption ; FIXME + ) "Format source or example blocks for export. Use `org-e-odt-format-source-code-or-example-plain' or `org-e-odt-format-source-code-or-example-colored' depending on the value of `org-export-e-odt-fontify-srcblocks." (setq ;; lines (org-export-number-lines - ;; lines 0 0 num cont rpllbl fmt 'preprocess) FIXME - lines (funcall - (or (and org-export-e-odt-fontify-srcblocks - (or (featurep 'htmlfontify) - ;; htmlfontify.el was introduced in Emacs 23.2 - ;; So load it with some caution - (require 'htmlfontify nil t)) - (fboundp 'htmlfontify-string) - 'org-e-odt-format-source-code-or-example-colored) - 'org-e-odt-format-source-code-or-example-plain) - lines lang caption textareap cols rows num cont rpllbl fmt)) - (if (not num) lines - (let ((extra (format " text:continue-numbering=\"%s\"" - (if cont "true" "false")))) - (org-e-odt-format-tags - '("" - . "") lines extra)))) + ;; lines 0 0 num cont rpllbl fmt 'preprocess) FIXME + lines (funcall + (or (and org-export-e-odt-fontify-srcblocks + (or (featurep 'htmlfontify) + ;; htmlfontify.el was introduced in Emacs 23.2 + ;; So load it with some caution + (require 'htmlfontify nil t)) + (fboundp 'htmlfontify-string) + 'org-e-odt-format-source-code-or-example-colored) + 'org-e-odt-format-source-code-or-example-plain) + lines lang caption)) + (let ((num (org-find-text-property-in-string 'org-loc lines))) + (if (not num) lines + (let* ((cont (not (equal num 1))) + (extra (format " text:continue-numbering=\"%s\"" + (if cont "true" "false")))) + (org-e-odt-format-tags + '("" + . "") lines extra))))) (defun org-e-odt-remap-stylenames (style-name) (or @@ -1341,6 +1341,9 @@ ATTR is a string of other attributes of the a element." (defun org-e-odt-format-tags (tag text &rest args) (apply 'org-e-odt-format-tags-1 tag text "\n" "\n" args)) +(defun org-e-odt-format-tags-simple (tag text &rest args) + (apply 'org-e-odt-format-tags-1 tag text nil nil args)) + (defun org-e-odt-init-outfile () (unless (executable-find "zip") ;; Not at all OSes ship with zip by default @@ -3440,7 +3443,7 @@ contextual information." "Transcode a EXAMPLE-BLOCK element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (let* ((options (or (org-element-property :options example-block) "")) - (value (org-export-handle-code example-block info))) + (value (org-export-handle-code example-block info nil nil t))) (org-e-odt--wrap-label example-block (org-e-odt-format-source-code-or-example value nil)))) @@ -3989,8 +3992,11 @@ INFO is a plist holding contextual information. See ;; Coderef: replace link with the reference name or the ;; equivalent line number. ((string= type "coderef") - (format (org-export-get-coderef-format path (or desc "")) - (org-export-resolve-coderef path info))) + (let* ((fmt (org-export-get-coderef-format path (or desc "%s"))) + (res (org-export-resolve-coderef path info)) + (org-e-odt-suppress-xref nil) + (href (org-xml-format-href (concat "#coderef-" path)))) + (format fmt (org-e-odt-format-link res href)))) ;; Link type is handled by a special function. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols)))) (funcall protocol (org-link-unescape path) desc 'html)) @@ -4178,7 +4184,7 @@ holding contextual information." CONTENTS holds the contents of the item. INFO is a plist holding contextual information." (let* ((lang (org-element-property :language src-block)) - (code (org-export-handle-code src-block info)) + (code (org-export-handle-code src-block info nil nil t)) (caption (org-element-property :caption src-block)) (label (org-element-property :name src-block))) ;; FIXME: Handle caption -- 2.11.4.GIT