@findex table-generate-source
@kbd{M-x table-generate-source} generates a table formatted for a
specific markup language. It asks for a language (which must be one
-of @code{html}, @code{latex}, or @code{cals}), a destination buffer in
-which to put the result, and a table caption, and then inserts the
-generated table into the specified buffer. The default destination
-buffer is @code{table.@var{lang}}, where @var{lang} is the language
-you specified.
+of @code{html}, @code{latex}, @code{cals}, @code{wiki} or
+@code{mediawiki}), a destination buffer in which to put the result,
+and a table caption, and then inserts the generated table into the
+specified buffer. The default destination buffer is
+@code{table.@var{lang}}, where @var{lang} is the language you
+specified.
@node Two-Column
@section Two-Column Editing
(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.")
(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)
"Generate and insert source epilogue into DEST-BUFFER."
(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)
"Generate and insert source rows into DEST-BUFFER."
(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
(cond
(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))))
(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
(cond
(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))
))))
(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"