emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Achim Gratz <Stromeko@nexgo.de>
To: emacs-orgmode@gnu.org
Subject: Re: #+INCLUDE: myfile.html html does not include /literally/; Org processes
Date: Sat, 07 Jun 2014 12:11:28 +0200	[thread overview]
Message-ID: <87bnu5t4fj.fsf@Rainer.invalid> (raw)
In-Reply-To: 87egz5pw4g.fsf@gmail.com

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

Nicolas Goaziou writes:
> On second thought, we shouldn't bother too much about it, let the user
> provide any keyword, and turn it into a block of the same name.
>
> So, for example, both
>
>   #+include: "file.html" html
>
> and
>
>   #+include: "file.html" center
>
> are valid, even though the second one makes little sense.
>
> It is close to your initial approach, minus the "wrap" keyword, which
> seems unnecessary. If you agree with this suggestion, do you volunteer
> to finalize it, along with the required documentation?

Here's the patch for this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-implement-additional-INCLUDE-markup.patch --]
[-- Type: text/x-patch, Size: 6852 bytes --]

From 3fe089c11b1ca149bbd0f80ee9389a1d7c14e5ed Mon Sep 17 00:00:00 2001
From: Achim Gratz <Stromeko@Stromeko.DE>
Date: Sat, 7 Jun 2014 11:54:02 +0200
Subject: [PATCH] ox: implement additional #+INCLUDE markup

* lisp/ox.el (org-export-expand-include-keyword): Change parsing so
  that arbitrary blocks around the included content can be used.
  Content is not code-escaped unless it is a literal block, this
  applies to "src" and "example".
* doc/org.texi (Include files): Document the additional markup.
* testing/lisp/test-ox.el (test-org-export/expand-include): Add test
  for an #+INCLUDE with "html" and "center" markup.
* testing/examples/include.html: New file, used for testing
  "#+INCLUDE html".
---
 doc/org.texi                  | 25 +++++++++++++++----------
 lisp/ox.el                    | 29 ++++++++++++++++++-----------
 testing/examples/include.html |  1 +
 testing/lisp/test-ox.el       | 16 ++++++++++++++++
 4 files changed, 50 insertions(+), 21 deletions(-)
 create mode 100644 testing/examples/include.html

diff --git a/doc/org.texi b/doc/org.texi
index 4548eda..0484ef1 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -9963,13 +9963,18 @@ @section Include files
 @end example
 
 @noindent
-The optional second and third parameter are the markup (i.e., @samp{example}
-or @samp{src}), and, if the markup is @samp{src}, the language for formatting
-the contents.
-
-If no markup is given, the text will be assumed to be in Org mode format and
-will be processed normally.  However, footnote labels (@pxref{Footnotes}) in
-the file will be made local to that file.
+The first parameter names the the file to include.  The optional second and
+third parameter specify the markup (i.e., @samp{example} or @samp{src}), and,
+if the markup is @samp{src}, the language for formatting the contents.
+
+If markup is requested, the included content will be placed within an
+appropriate block@footnote{While you can request paragraphs (@samp{verse},
+@samp{quote}, @samp{center}), there are no checks ensure the result is valid
+Org syntax.}.  For markup @samp{example} and @samp{src}, which is requesting
+a literal example, the content will be code-escaped before inclusion.  In all
+other cases, the text will be assumed to be in Org mode format and will be
+processed normally.  However, footnote labels (@pxref{Footnotes}) in the file
+will be made local to that file.
 
 Contents of the included file will belong to the same structure (headline,
 item) containing the @code{INCLUDE} keyword.  In particular, headlines within
@@ -9984,9 +9989,9 @@ @section Include files
 @end example
 
 You can also include a portion of a file by specifying a lines range using
-the @code{:lines} parameter.  The line at the upper end of the range will not
-be included.  The start and/or the end of the range may be omitted to use the
-obvious defaults.
+the @code{:lines} keyword parameter.  The line at the upper end of the range
+will not be included.  The start and/or the end of the range may be omitted
+to use the obvious defaults.
 
 @example
 #+INCLUDE: "~/.emacs" :lines "5-10"   @r{Include lines 5 to 10, 10 excluded}
diff --git a/lisp/ox.el b/lisp/ox.el
index 584037b..fab4960 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3313,9 +3313,10 @@ (defun org-export-expand-include-keyword (&optional included dir)
 			value)
 		       (prog1 (match-string 1 value)
 			 (setq value (replace-match "" nil nil value)))))
-		 (env (cond ((string-match "\\<example\\>" value) 'example)
+		 (env (cond ((string-match "\\<example\\>" value)
+			     'literal)
 			    ((string-match "\\<src\\(?: +\\(.*\\)\\)?" value)
-			     (match-string 1 value))))
+			     'literal)))
 		 ;; Minimal level of included file defaults to the child
 		 ;; level of the current headline, if any, or one.  It
 		 ;; only applies is the file is meant to be included as
@@ -3326,7 +3327,11 @@ (defun org-export-expand-include-keyword (&optional included dir)
 			   (prog1 (string-to-number (match-string 1 value))
 			     (setq value (replace-match "" nil nil value)))
 			 (let ((cur (org-current-level)))
-			   (if cur (1+ (org-reduced-level cur)) 1))))))
+			   (if cur (1+ (org-reduced-level cur)) 1)))))
+		 (src-args (when (eq env 'literal)
+			     (match-string 1 value)))
+		 (block (when (string-match "\\<\\([a-zA-Z]+\\)\\>" value)
+			  (upcase (match-string 1 value)))))
 	    ;; Remove keyword.
 	    (delete-region (point) (progn (forward-line) (point)))
 	    (cond
@@ -3340,22 +3345,24 @@ (defun org-export-expand-include-keyword (&optional included dir)
 	      (error "Recursive file inclusion: %s" file))
 	     (t
 	      (cond
-	       ((eq env 'example)
+	       ((eq env 'literal)
 		(insert
 		 (let ((ind-str (make-string ind ? ))
+		       (arg-str (if (stringp src-args)
+				  (format " %s" src-args)
+				""))
 		       (contents
 			(org-escape-code-in-string
 			 (org-export--prepare-file-contents file lines))))
-		   (format "%s#+BEGIN_EXAMPLE\n%s%s#+END_EXAMPLE\n"
-			   ind-str contents ind-str))))
-	       ((stringp env)
+		   (format "%s#+BEGIN_%s%s\n%s%s#+END_%s\n"
+			   ind-str block arg-str contents ind-str block))))
+	       ((stringp block)
 		(insert
 		 (let ((ind-str (make-string ind ? ))
 		       (contents
-			(org-escape-code-in-string
-			 (org-export--prepare-file-contents file lines))))
-		   (format "%s#+BEGIN_SRC %s\n%s%s#+END_SRC\n"
-			   ind-str env contents ind-str))))
+			 (org-export--prepare-file-contents file lines)))
+		   (format "%s#+BEGIN_%s\n%s%s#+END_%s\n"
+			   ind-str block contents ind-str block))))
 	       (t
 		(insert
 		 (with-temp-buffer
diff --git a/testing/examples/include.html b/testing/examples/include.html
new file mode 100644
index 0000000..c9986d3
--- /dev/null
+++ b/testing/examples/include.html
@@ -0,0 +1 @@
+<p>HTML!</p>
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 858d38c..e2af5a3 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -851,6 +851,22 @@ (defmacro org-test-with-parsed-data (data &rest body)
     (org-export-expand-include-keyword)
     (should (equal (buffer-string)
 		   "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n")))
+  ;; Inclusion within an html export-block.
+  (org-test-with-temp-text
+      (format
+       "#+INCLUDE: \"%s/examples/include.html\" html"
+       org-test-dir)
+    (org-export-expand-include-keyword)
+    (should (equal (buffer-string)
+		   "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n")))
+  ;; Inclusion within an center paragraph
+  (org-test-with-temp-text
+      (format
+       "#+INCLUDE: \"%s/examples/include2.org\" center"
+       org-test-dir)
+    (org-export-expand-include-keyword)
+    (should (equal (buffer-string)
+		   "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n")))
   ;; Footnotes labels are local to each included file.
   (should
    (= 6
-- 
1.9.3


[-- Attachment #3: Type: text/plain, Size: 208 bytes --]



Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

  parent reply	other threads:[~2014-06-07 10:11 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-01  4:06 #+INCLUDE: myfile.html html does not include /literally/; Org processes Omid
2014-06-01  4:42 ` Nick Dokos
2014-06-01  4:51   ` Omid
2014-06-01  6:18     ` Nick Dokos
2014-06-01  5:05   ` Omid
2014-06-01  7:53 ` Achim Gratz
2014-06-01  8:31   ` Nicolas Goaziou
2014-06-01  9:26     ` Achim Gratz
2014-06-01 10:01       ` Nicolas Goaziou
2014-06-01 10:23         ` Achim Gratz
2014-06-01 11:30           ` Nicolas Goaziou
2014-06-01 13:02             ` Achim Gratz
2014-06-01 14:00               ` Nicolas Goaziou
2014-06-01 14:27                 ` Achim Gratz
2014-06-03 20:37                   ` Nicolas Goaziou
2014-06-04 21:50                     ` Achim Gratz
2014-06-05  9:28                       ` Nicolas Goaziou
2014-06-07 10:11                     ` Achim Gratz [this message]
2014-06-07 13:53                       ` Nicolas Goaziou
2014-06-01 10:01       ` Omid
2014-06-01 11:24         ` Nicolas Goaziou
  -- strict thread matches above, loose matches on Subject: below --
2014-09-25 22:36 Omid
2014-09-26  9:07 ` Nicolas Goaziou
2014-09-26 18:53 ` Achim Gratz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bnu5t4fj.fsf@Rainer.invalid \
    --to=stromeko@nexgo.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).