emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [emacs-wiki-discuss] table formatting problem


From: Damien Elmes
Subject: Re: [emacs-wiki-discuss] table formatting problem
Date: Thu, 15 Jan 2004 14:12:23 +1100
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3.50 (gnu/linux)

Martin Stemplinger <address@hidden> writes:

> Hi all,
>
> whenever I put a table in one of my wiki files, the html-output has a
> additional blank column as the second last column.
>
> For example the output of
> col1 | col2 | col3
>
> is 
> <table class="ewiki-table" border="2" cellpadding="5">
> <tbody>
> <tr>
> <td>col1</td><td>col2</td><td></td><td>col3</td>

Apologies for the belated response.

This used to be a problem in xemacs due to differing behavior with
split-string. The problem now seems to happen in emacs as well, so I
guess the semantics of split-string changed - but that's just a
cursory analysis.

The following should fix the problem, though it's a hack - the code
really needs refactoring.

(defun emacs-wiki-markup-table ()
  (if (featurep 'table)
      (let ((leader (match-string 1))
            (begin (copy-marker (match-beginning 0)))
            table end)
        (goto-char (match-end 0))
        (setq table
              (with-current-buffer (table-generate-source 'html)
                (prog1
                    (buffer-string)
                  (kill-buffer (current-buffer)))))
        (goto-char begin)
        (if (re-search-backward "<p>[ \t\n\r]+" nil t)
            (replace-match (if (>= (string-width leader) 6)
                               "<center>\n"
                             (if (> (length leader) 0)
                                 "<blockquote>\n"
                               ""))))
        (delete-region begin (re-search-forward "-+\\+\\s-*[\r\n]+\\s-*$"
                                                nil t))
        (insert table)
        (setq end (point-marker))
        (goto-char begin)
        (while (< (point) end)
          (if (looking-at "^\\s-+")
              (replace-match ""))
          (forward-line))
        (goto-char end)
        (if (re-search-forward "[ \t\n\r]+</p>" nil t)
            (replace-match (if (>= (string-width leader) 6)
                               "\n</center>"
                             (if (> (length leader) 0)
                                 "\n</blockquote>"
                               ""))))
        (set-match-data (list begin begin begin begin))
        nil)
    (let* ((str (save-match-data
                  (if (featurep 'xemacs)
                      ;; more emacs divergence. :(
                      (replace-in-string (match-string 1) " *|+ *$" "")
                    (replace-regexp-in-string " *|+ *$" "" (match-string 1) ))))
           (fields
            (append (save-match-data
                      (split-string str "[ \t]*|+[ \t]*"))
                    (list (match-string 4))))
           (len (length (match-string 3)))
           (row (cond ((= len 1) "tbody")
                      ((= len 2) "thead")
                      ((= len 3) "tfoot")))
           (col (cond ((= len 1) "td")
                      ((= len 2) "th")
                      ((= len 3) "td"))))
      (concat "<table " emacs-wiki-table-attributes ">\n"
              "<" row ">\n" "<tr>\n<" col ">"
              (mapconcat 'identity fields (format "</%s><%s>" col col))
              "</" col ">\n" "</tr>\n" "</" row ">\n"
              "</table>\n"))))

Cheers,
-- 
Damien Elmes




reply via email to

[Prev in Thread] Current Thread [Next in Thread]