From 1e53a35cadcdd209fc779da0c26563938bc8a1ad Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 26 Jan 2014 14:19:22 +0100 Subject: [PATCH 2/4] ox: Handle quote sections internally To: n.goaziou@gmail.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.8.5.3" This is a multi-part message in MIME format. --------------1.8.5.3 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit * lisp/ox.el (org-export--remove-uninterpreted-data-1): Handle quote sections. (org-export-filter-quote-section-functions): Remove variable. * testing/lisp/test-ox.el (test-org-export/uninterpreted): Add test. --- lisp/ox.el | 30 +++++++++++++++++++----------- testing/lisp/test-ox.el | 11 +++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) --------------1.8.5.3 Content-Type: text/x-patch; name="0002-ox-Handle-quote-sections-internally.patch" Content-Transfer-Encoding: 8bit Content-Disposition: inline; filename="0002-ox-Handle-quote-sections-internally.patch" diff --git a/lisp/ox.el b/lisp/ox.el index 28aed70..ad2780b 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -221,7 +221,6 @@ way they are handled must be hard-coded into (:filter-planning . org-export-filter-planning-functions) (:filter-property-drawer . org-export-filter-property-drawer-functions) (:filter-quote-block . org-export-filter-quote-block-functions) - (:filter-quote-section . org-export-filter-quote-section-functions) (:filter-radio-target . org-export-filter-radio-target-functions) (:filter-section . org-export-filter-section-functions) (:filter-special-block . org-export-filter-special-block-functions) @@ -2314,8 +2313,8 @@ DATA is a parse tree or a secondary string. INFO is a plist containing export options. It is modified by side effect and returned by the function." (org-element-map data - '(entity bold italic latex-environment latex-fragment strike-through - subscript superscript underline) + '(entity bold italic latex-environment latex-fragment section + strike-through subscript superscript underline) #'(lambda (blob) (let ((new (case (org-element-type blob) @@ -2348,6 +2347,11 @@ returned by the function." ((latex-environment latex-fragment) (and (eq (plist-get info :with-latex) 'verbatim) (list (org-export-expand blob nil)))) + ;; ... quote sections... + (section + (and (org-element-property :quotedp + (org-export-get-parent blob)) + 'section)) ;; ... sub/superscripts... ((subscript superscript) (let ((sub/super-p (plist-get info :with-sub-superscript)) @@ -2367,10 +2371,20 @@ returned by the function." (make-string (org-element-property :post-blank blob) ?\s))))))))))) - (when new + (cond + ((eq new 'section) + ;; Treat quote sections specially: replace their contents + ;; with a single example block. + (let ((example (list 'example-block nil))) + (org-element-put-property example :parent blob) + (org-element-put-property + example :value + (org-element-interpret-data (org-element-contents blob))) + (org-element-set-contents blob example))) + (new ;; Splice NEW at BLOB location in parse tree. (dolist (e new) (org-element-insert-before e blob)) - (org-element-extract-element blob)))) + (org-element-extract-element blob))))) info) ;; Return modified parse tree. data) @@ -2654,12 +2668,6 @@ data, as a string, the back-end, as a symbol, and the communication channel, as a plist. It must return a string or nil.") -(defvar org-export-filter-quote-section-functions nil - "List of functions applied to a transcoded quote-section. -Each filter is called with three arguments: the transcoded data, -as a string, the back-end, as a symbol, and the communication -channel, as a plist. It must return a string or nil.") - (defvar org-export-filter-section-functions nil "List of functions applied to a transcoded section. Each filter is called with three arguments: the transcoded data, diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 78347af..168dc24 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -642,6 +642,17 @@ Paragraph <2012-03-29 Thu>[2012-03-29 Thu]" (paragraph . (lambda (p c i) c)) (section . (lambda (s c i) c)))) nil nil nil '(:with-latex verbatim))))) + ;; Quote sections. + (should + (equal "Success!\n" + (org-test-with-temp-text "* QUOTE Headline\na *b* c" + (org-export-as + (org-export-create-backend + :transcoders '((bold . (lambda (b c i) "Failure.")) + (headline . (lambda (h c i) c)) + (paragraph . (lambda (p c i) c)) + (section . (lambda (s c i) c)) + (example-block . (lambda (e c i) "Success!")))))))) ;; Sub/superscript. (should (equal "adummy\n" --------------1.8.5.3--