Bläddra i källkod

ox.el (org-export-replace-region-by): New function

* ox.el (org-export-replace-region-by): New function.
* ox-texinfo.el (org-texinfo-convert-region-to-texinfo):
* ox-md.el (org-md-convert-region-to-md):
* ox-latex.el (org-latex-convert-region-to-latex):
* ox-html.el (org-html-convert-region-to-html): New functions
to replace the active region by its export into various
backends.
Bastien Guerry 12 år sedan
förälder
incheckning
1e496cc8f9
5 ändrade filer med 48 tillägg och 0 borttagningar
  1. 9 0
      lisp/ox-html.el
  2. 9 0
      lisp/ox-latex.el
  3. 9 0
      lisp/ox-md.el
  4. 9 0
      lisp/ox-texinfo.el
  5. 12 0
      lisp/ox.el

+ 9 - 0
lisp/ox-html.el

@@ -3193,6 +3193,15 @@ is non-nil."
       (when org-export-show-temporary-export-buffer
 	(switch-to-buffer-other-window outbuf)))))
 
+;;;###autoload
+(defun org-html-convert-region-to-html ()
+  "Assume the current region has org-mode syntax, and convert it to HTML.
+This can be used in any buffer.  For example, you can write an
+itemized list in org-mode syntax in an HTML buffer and use this
+command to convert it."
+  (interactive)
+  (org-export-replace-region-by 'html))
+
 ;;;###autoload
 (defun org-html-export-to-html
   (&optional async subtreep visible-only body-only ext-plist)

+ 9 - 0
lisp/ox-latex.el

@@ -2821,6 +2821,15 @@ is non-nil."
       (when org-export-show-temporary-export-buffer
 	(switch-to-buffer-other-window outbuf)))))
 
+;;;###autoload
+(defun org-latex-convert-region-to-latex ()
+  "Assume the current region has org-mode syntax, and convert it to LaTeX.
+This can be used in any buffer.  For example, you can write an
+itemized list in org-mode syntax in an LaTeX buffer and use this
+command to convert it."
+  (interactive)
+  (org-export-replace-region-by 'latex))
+
 ;;;###autoload
 (defun org-latex-export-to-latex
   (&optional async subtreep visible-only body-only ext-plist)

+ 9 - 0
lisp/ox-md.el

@@ -455,6 +455,15 @@ non-nil."
       (when org-export-show-temporary-export-buffer
 	(switch-to-buffer-other-window outbuf)))))
 
+;;;###autoload
+(defun org-md-convert-region-to-md ()
+  "Assume the current region has org-mode syntax, and convert it to Markdown.
+This can be used in any buffer.  For example, you can write an
+itemized list in org-mode syntax in a Markdown buffer and use
+this command to convert it."
+  (interactive)
+  (org-export-replace-region-by 'md))
+
 
 ;;;###autoload
 (defun org-md-export-to-markdown (&optional async subtreep visible-only)

+ 9 - 0
lisp/ox-texinfo.el

@@ -1779,6 +1779,15 @@ publishing directory.
 Return output file name."
   (org-publish-org-to 'texinfo filename ".texi" plist pub-dir))
 
+;;;###autoload
+(defun org-texinfo-convert-region-to-texinfo ()
+  "Assume the current region has org-mode syntax, and convert it to Texinfo.
+This can be used in any buffer.  For example, you can write an
+itemized list in org-mode syntax in an Texinfo buffer and use
+this command to convert it."
+  (interactive)
+  (org-export-replace-region-by 'texinfo))
+
 (defun org-texinfo-compile (file)
   "Compile a texinfo file.
 

+ 12 - 0
lisp/ox.el

@@ -3056,6 +3056,18 @@ Return code as a string."
     (org-mode)
     (org-export-as backend nil nil body-only ext-plist)))
 
+;;;###autoload
+(defun org-export-replace-region-by (backend)
+  "Replace the active region by its export to BACKEND."
+  (if (not (org-region-active-p))
+      (user-error "No active region to replace")
+    (let* ((beg (region-beginning))
+	   (end (region-end))
+	   (str (buffer-substring beg end)) rpl)
+      (setq rpl (org-export-string-as str backend t))
+      (delete-region beg end)
+      (insert rpl))))
+
 ;;;###autoload
 (defun org-export-insert-default-template (&optional backend subtreep)
   "Insert all export keywords with default values at beginning of line.