all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Aaron S. Hawley" <aaron.s.hawley@gmail.com>
To: 13287@debbugs.gnu.org
Subject: bug#13287: [PATCH] table.el: Wiki export
Date: Thu, 27 Dec 2012 12:01:52 -0500	[thread overview]
Message-ID: <CAFw1JJ54+ZX6RMA-6D1Yt2=MoEHvnxO=X55ob9tCwQX9aihjEQ@mail.gmail.com> (raw)

[-- 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"

             reply	other threads:[~2012-12-27 17:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-27 17:01 Aaron S. Hawley [this message]
2016-02-24  5:56 ` bug#13287: [PATCH] table.el: Wiki export Lars Ingebrigtsen
2016-02-24  6:09   ` Aaron S. Hawley
2016-02-24  6:12     ` Lars Ingebrigtsen
2019-06-27 11:55       ` Lars Ingebrigtsen

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

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

  git send-email \
    --in-reply-to='CAFw1JJ54+ZX6RMA-6D1Yt2=MoEHvnxO=X55ob9tCwQX9aihjEQ@mail.gmail.com' \
    --to=aaron.s.hawley@gmail.com \
    --cc=13287@debbugs.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.