1

org-mode からエクスポートされたデフォルトの HTML テーブルには、次のスタイルがあります。

<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Tom</td>
<td>Cruise</td>
</tr>

<tr>
<td>2</td>
<td>Arnold</td>
<td>Schwarzenegger</td>
</tr>

<tr>
<td>3</td>
<td>Sylvester</td>
<td>Stallone</td>
</tr>
</tbody>
</table>

次のようにコンパクトにする方法はありますか?

<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
</tr>
</thead>
<tbody>
<tr><td>1</td><td>Tom</td><td>Cruise</td></tr>
<tr><td>2</td><td>Arnold</td><td>Schwarzenegger</td></tr>
<tr><td>3</td><td>Sylvester</td><td>Stallone</td></tr>
</tbody>
</table>

テーブルのサイズが非常に大きいため、org-mode によってエクスポートされた html ファイルは一番下まで長すぎます。

4

2 に答える 2

1

HTML バッファで単純な正規表現置換を行うと、次のようになります。

(defun compactify-html-table ()
  (interactive)
  (goto-char (point-min))
  (while (re-search-forward "<\\(/?t[rd]\\)>\n<\\(/?t[rd]\\)>" nil t)
    (replace-match "<\\1><\\2>"))
  (goto-char (point-min))
  (while (re-search-forward "\n\n" nil t)
    (replace-match "\n")))

UPD:開いているすべてのhtmlバッファに適用する方法:

(defun compactify-all-html-buffers ()
  (interactive)
  (mapc
   (lambda(b)
     (with-current-buffer b
       (when (eq major-mode 'html-mode)
         (compactify-html-table))))
   (buffer-list)))
于 2013-11-01T13:18:01.933 に答える