unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#13287: [PATCH] table.el: Wiki export
@ 2012-12-27 17:01 Aaron S. Hawley
  2016-02-24  5:56 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Aaron S. Hawley @ 2012-12-27 17:01 UTC (permalink / raw)
  To: 13287

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

This patch adds support for exporting Emacs tables to Wiki and
MediaWiki source.  The Wiki format is a generally accepted table
format used by various Wiki engines.

This patch is the minimal implementation for exporting these formats.
It doesn't do any quoting (of the table syntax characters) and might
not do the correct thing for multiple line cells.  Making it work in
these situations might take some rework of the exporting facilities in
table.el

Thanks for Emacs,
/a

-- 
In general, we reserve the right to have a poor
memory--the computer, however, is supposed to
remember!  Poor computer.  -- Guy Lewis Steele Jr.

[-- Attachment #2: table.el.diff --]
[-- Type: application/octet-stream, Size: 4015 bytes --]

2012-12-17  Aaron S. Hawley  <aaron.s.hawley@gmail.com>

        * table.el (table-source-languages)
        (table--generate-source-prologue)
        (table--generate-source-epilogue)
        (table--generate-source-scan-rows)
        (table--generate-source-cells-in-a-row)
        (table--generate-source-cell-contents): Add wiki and mediawiki.

--- table.el	2012-12-17 11:05:21.635770100 -0500
+++ table.el	2012-12-17 11:09:23.122916400 -0500
@@ -888,7 +888,7 @@
   (push '(table-mode-indicator (table-fixed-width-mode " Fixed-Table" " Table"))
         minor-mode-alist))
 
-(defconst table-source-languages '(html latex cals)
+(defconst table-source-languages '(html latex cals wiki mediawiki)
   "Supported source languages.")
 (defvar table-source-info-plist nil
   "General storage for temporary information used while generating source.")
@@ -3081,6 +3081,9 @@
       (table-put-source-info 'row-type (if (zerop table-cals-thead-rows) "tbody" "thead"))
       (set-marker-insertion-type (table-get-source-info 'colspec-marker) nil) ;; insert after
       (insert (format "    <%s valign=\"top\">\n" (table-get-source-info 'row-type))))
+     ((eq language 'mediawiki)
+      (insert (format "<!-- This HTML table template is generated by Emacs %s -->\n" emacs-version))
+      (insert "{|\n"))
      )))
 
 (defun table--generate-source-epilogue (dest-buffer language _col-list _row-list)
@@ -3098,6 +3101,8 @@
 	(dolist (col (sort (table-get-source-info 'colnum-list) '<))
           (insert (format "    <colspec colnum=\"%d\" colname=\"c%d\"/>\n" col col))))
       (insert (format "    </%s>\n  </tgroup>\n</table>\n" (table-get-source-info 'row-type))))
+     ((eq language 'mediawiki)
+      (insert "|}\n"))
      )))
 
 (defun table--generate-source-scan-rows (dest-buffer language _origin-cell col-list row-list)
@@ -3110,6 +3115,11 @@
 	(insert "  <tr>\n"))
        ((eq language 'cals)
 	(insert "      <row>\n"))
+       ((eq language 'wiki)
+	(insert "|"))
+       ((and (eq language 'mediawiki)
+             (> (table-get-source-info 'current-row) 1))
+	(insert "|-\n"))
        ))
     (table--generate-source-cells-in-a-row dest-buffer language col-list row-list)
     (with-current-buffer dest-buffer
@@ -3120,7 +3130,10 @@
 	(insert "      </row>\n")
 	(unless (/= (table-get-source-info 'current-row) table-cals-thead-rows)
 	  (insert (format "    </%s>\n" (table-get-source-info 'row-type)))
-	  (insert (format "    <%s valign=\"top\">\n" (table-put-source-info 'row-type "tbody")))))))
+	  (insert (format "    <%s valign=\"top\">\n" (table-put-source-info 'row-type "tbody")))))
+       ((eq language 'wiki)
+	(insert "|\n"))
+       ))
     (table-put-source-info 'current-row (1+ (table-get-source-info 'current-row)))
     (setq row-list (cdr row-list))))
 
@@ -3189,6 +3202,8 @@
 		       (not (memq valign '(top none))))
 		  (insert " valign=\"" (symbol-name valign) "\""))
 	      (insert ">\n"))
+	     ((memq language '(wiki mediawiki))
+	      (insert "|"))
 	     ))
 	  (table--generate-source-cell-contents dest-buffer language cell)
 	  (with-current-buffer dest-buffer
@@ -3197,6 +3212,10 @@
 	      (insert (format"    </%s>\n" (table-get-source-info 'cell-type))))
 	     ((eq language 'cals)
 	      (insert "        </entry>\n"))
+	     ((eq language 'wiki)
+	      (insert "|"))
+	     ((eq language 'mediawiki)
+	      (insert ?\n))
 	     ))
 	  (table-forward-cell 1 t)
 	  (table-put-source-info 'current-column (table-get-source-info 'next-column))
@@ -3236,11 +3255,12 @@
     (with-current-buffer dest-buffer
       (let ((beg (point)))
 	(insert cell-contents)
-	(indent-rigidly beg (point)
-			(cond
-			 ((eq language 'html) 6)
-			 ((eq language 'cals) 10)))
-	(insert ?\n)))))
+	(when (memq language '(html cals))
+	  (indent-rigidly beg (point)
+			  (cond
+			   ((eq language 'html) 6)
+			   ((eq language 'cals) 10)))
+	(insert ?\n))))))
 
 (defun table--cell-horizontal-char-p (c)
   "Test if character C is one of the horizontal characters"

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-27 11:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-27 17:01 bug#13287: [PATCH] table.el: Wiki export Aaron S. Hawley
2016-02-24  5:56 ` Lars Ingebrigtsen
2016-02-24  6:09   ` Aaron S. Hawley
2016-02-24  6:12     ` Lars Ingebrigtsen
2019-06-27 11:55       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).