From 0ed0c40d87fdec45e71222aaf84161fc6cf18cc3 Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Sun, 3 Jun 2007 03:20:25 +0000 Subject: [PATCH] Support table.el-style tables * NEWS: Mention support for table.el-style tables. * lisp/muse-publish.el (muse-publish-markup-regexps): Move normal table rule to 2350. Rule 2300 is now a regexp that matches table.el-style tables. (muse-publish-markup-functions): Add table-el entry. (muse-publish-table-el-table): New function that given a variant, publishes a table.el-style table using the table in the matched region. (muse-publish-markup-table-el): New function that determines whether the table.el-style table can be published, and what variant to use. * lisp/muse-regexps.el (muse-tag-regexp): New regexp that matches the borders of table.el-style tables. * lisp/muse-xml-common.el (muse-xml-markup-table): Make sure that the table has sufficient whitespace in front of it. git-archimport-id: mwolson@gnu.org--2006/muse--main--1.0--patch-333 --- ChangeLog | 18 +++++++++++++++++- NEWS | 7 +++++++ lisp/muse-publish.el | 41 ++++++++++++++++++++++++++++++++++++++++- lisp/muse-regexps.el | 7 +++++++ lisp/muse-xml-common.el | 2 ++ 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b45cf9..84a5ba3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2007-06-02 Michael Olson - * NEWS: Update for non-inlined image change. + * NEWS: Update for non-inlined image change and support for + table.el style tables. * examples/Makefile (clean): Clean backup files. @@ -30,6 +31,21 @@ beginning of a string. This is used to remove URL: from the link description. * texi/muse.texi (Markup Strings): Clarify the meanings of image-link, link, and link-and-anchor. + (muse-publish-markup-regexps): Move normal table rule to 2350. + Rule 2300 is now a regexp that matches table.el-style tables. + (muse-publish-markup-functions): Add table-el entry. + (muse-publish-table-el-table): New function that given a variant, + publishes a table.el-style table using the table in the matched + region. + (muse-publish-markup-table-el): New function that determines + whether the table.el-style table can be published, and what + variant to use. + + * lisp/muse-regexps.el (muse-tag-regexp): New regexp that matches + the borders of table.el-style tables. + + * lisp/muse-xml-common.el (muse-xml-markup-table): Make sure that + the table has sufficient whitespace in front of it. * texi/muse.texi (Images): Update for new non-inlined image ability and provide example. diff --git a/NEWS b/NEWS index d4c383c..ec2c127 100644 --- a/NEWS +++ b/NEWS @@ -392,6 +392,13 @@ customize `muse-html-table-attributes' to: in order to get a similar kind of output. +**** Support table.el-style tables. +If you have table.el somewhere in your load-path, Muse will publish +tables that are in the format used by table.el. + +Currently, table.el tables can only be published for publishing styles +based on HTML, LaTeX, or DocBook. + **** Allow empty elements in tables. **** Allow initial and trailing whitespace in tables, but strip it diff --git a/lisp/muse-publish.el b/lisp/muse-publish.el index fe85599..3145ca6 100644 --- a/lisp/muse-publish.el +++ b/lisp/muse-publish.el @@ -151,10 +151,17 @@ If non-nil, publish comments using the markup of the current style." (2200 ,(format muse-list-item-regexp (concat "[" muse-regexp-blank "]*")) 0 list) + ;; support table.el style tables + (2300 ,(concat muse-table-el-border-regexp "\n" + "\\(\\(" muse-table-line-regexp "\n\\)+" + "\\(" muse-table-el-border-regexp "\\)" + "\\(\n\\|\\'\\)\\)+") + 0 table-el) + ;; simple table markup is supported, nothing fancy. use | to ;; separate cells, || to separate header cells, and ||| for footer ;; cells - (2300 ,(concat "\\(\\([" muse-regexp-blank "]*\n\\)?" + (2350 ,(concat "\\(\\([" muse-regexp-blank "]*\n\\)?" "\\(\\(?:" muse-table-line-regexp "\\|" muse-table-hline-regexp "\\)\\(?:\n\\|\\'\\)\\)\\)+") 0 table) @@ -233,6 +240,7 @@ while processing the markup rules." (quote . muse-publish-markup-quote) (verse . muse-publish-markup-verse) (table . muse-publish-markup-table) + (table-el . muse-publish-markup-table-el) (email . muse-publish-markup-email) (link . muse-publish-markup-link) (url . muse-publish-markup-url)) @@ -1420,6 +1428,37 @@ The existing region will be removed, except for initial blank lines." (defun muse-publish-markup-table () "Style does not support tables.") +(defun muse-publish-table-el-table (variant) + "Publish table.el-style tables in the format given by VARIANT." + (when (condition-case nil + (progn (require 'table) + t) + (error nil)) + (let ((muse-buf (current-buffer))) + (save-restriction + (narrow-to-region (match-beginning 0) (match-end 0)) + (goto-char (point-min)) + (forward-line 1) + (search-forward "|" nil t) + (with-temp-buffer + (let ((temp-buf (current-buffer))) + (with-current-buffer muse-buf + (table-generate-source variant temp-buf)) + (with-current-buffer muse-buf + (delete-region (point-min) (point-max)) + (insert-buffer-substring temp-buf) + (muse-publish-mark-read-only (point-min) (point-max))))))))) + +(defun muse-publish-markup-table-el () + "Mark up table.el-style tables." + (cond ((muse-style-derived-p 'html) + (muse-publish-table-el-table 'html)) + ((muse-style-derived-p 'latex) + (muse-publish-table-el-table 'latex)) + ((muse-style-derived-p 'docbook) + (muse-publish-table-el-table 'cals)) + (t "Style does not support table.el tables."))) + (defun muse-publish-escape-specials-in-string (string &optional context) "Escape specials in STRING using style-specific :specials. CONTEXT is used to figure out what kind of specials to escape. diff --git a/lisp/muse-regexps.el b/lisp/muse-regexps.el index 2910862..d2b5cdb 100644 --- a/lisp/muse-regexps.el +++ b/lisp/muse-regexps.el @@ -179,6 +179,13 @@ The first match string must contain the term." :type 'regexp :group 'muse-regexp) +(defcustom muse-table-el-border-regexp (concat "^[" muse-regexp-blank "]*" + "\\+\\(-*\\+\\)+" + "[" muse-regexp-blank "]*") + "Regexp used to match the beginning and end of a table.el-style table." + :type 'regexp + :group 'muse-regexp) + (defcustom muse-tag-regexp (concat "<\\([^/" muse-regexp-blank "\n][^" muse-regexp-blank "\n]*\\)\\(\\s-+[^<>\n]+[^\n]\\)?\\(/\\)?>") diff --git a/lisp/muse-xml-common.el b/lisp/muse-xml-common.el index 170d934..0a0d9e3 100644 --- a/lisp/muse-xml-common.el +++ b/lisp/muse-xml-common.el @@ -151,6 +151,8 @@ If a string ATTRIBUTES is given, pass it to the markup string begin-table." (field-list (muse-xml-sort-table (cdr table-info))) last-part) (when table-info + (let ((beg (point))) + (muse-publish-ensure-block beg)) (muse-insert-markup (muse-markup-text 'begin-table (or attributes ""))) (muse-insert-markup (muse-markup-text 'begin-table-group row-len)) (dolist (fields field-list) -- 2.11.4.GIT