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

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

[emacs-wiki-discuss] Re: bad HTML publish


From: Richard Klinda
Subject: [emacs-wiki-discuss] Re: bad HTML publish
Date: Mon, 20 Mar 2006 17:16:59 +0100
User-agent: Gnus/5.110003 (No Gnus v0.3) XEmacs/21.4 (Jumbo Shrimp, linux)

>>>>> Regarding 'Re: bad HTML publish'; Michael Olson adds:


  > Richard Klinda <address@hidden> writes:
  >> Hello, since ~2006 march 6 HTML publishing doesn't work properly
  >> for me.  emacs-version => "21.4 (patch 17) \"Jumbo Shrimp\" XEmacs
  >> Lucid"

  >> <foo>bar<baz> generates into: &ltfoo&gt;bar&ltbaz&gt; instead of
  >> "<foo>bar<baz>".  Any ideas?

  >> I'm currently using todays muse snapshot.  Thanks.

  > If you want the HTML tags to not be escaped, surround the region
  > with <literal>.  Example follows.

  > <literal><foo>bar</foo></literal>

  > This behavior happens because the latest development version of Muse
  > does whole-document escaping.  This is desirable if you use more
  > than just the HTML publisher.

Hello, I like this change!:) But literal isn't enough for me so I
implemented a solution for myself (extremely hackish etc but it works,
extensively tested), maybe someone finds it useful.

Unfortunately it redefines a muse function:
MUSE-PUBLISH-ESCAPE-SPECIALS.

With the code below the following text:

,----
|   <center> **foo** <bar> <table> </center>
`----

publishes to HTML roughly as:

,----
|   <center> <strong>foo</strong> &lt;bar&gt; <table> </center>
`----

IOW, commands defined in RK-MUSE-HTML-COMMANDS don't get escaped.

;;; ----------------------------------------------------------------------
;; html generation

(defvar rk-muse-html-commands '("td" "tr" "center" "table" "pre" "br" "strong"
                                "font" "a" "img" "div"))

(dolist (ele rk-muse-html-commands)
  (let ((sym (car (read-from-string (format "rk-publish-html-markup-%s" ele)))))
    (unless (member* ele muse-publish-markup-tags :key 'car :test 'equalp)
      (setq muse-publish-markup-tags (cons
                                      (list ele t t sym)
                                      muse-publish-markup-tags)))))

(defun rk-publish-html-markup-table (beg end o)
  (rk-muse-insert-html-command "table"))
(defun rk-publish-html-markup-td (beg end o)
  (rk-muse-insert-html-command "td"))
(defun rk-publish-html-markup-tr (beg end o)
  (rk-muse-insert-html-command "tr"))
(defun rk-publish-html-markup-center (beg end o)
  (rk-muse-insert-html-command "center"))
(defun rk-publish-html-markup-pre (beg end o)
  (rk-muse-insert-html-command "pre"))
(defun rk-publish-html-markup-br (beg end o)
  (rk-muse-insert-html-command "br"))
(defun rk-publish-html-markup-strong (beg end o)
  (rk-muse-insert-html-command "strong"))
(defun rk-publish-html-markup-font (beg end o)
  (rk-muse-insert-html-command "font"))
(defun rk-publish-html-markup-a (beg end o)
  (rk-muse-insert-html-command "a"))
(defun rk-publish-html-markup-div (beg end o)
  (rk-muse-insert-html-command "div"))

(defun rk-muse-insert-html-command (ele)
  ;;(muse-publish-escape-specials beg end)
  (goto-char beg)
  (let ((attr (apply 'concat (loop for e in (group-list o 2)
                                   collect (format "%s=%s " (car (nth 0 e))
                                                   (car (nth 1 e)))))))
    (insert "<" ele " " attr ">")
    (let ((p (point)))
      (goto-char end)
      (insert "</" ele ">")
      ;;(muse-publish-mark-read-only beg (point))
      (goto-char p))
    ))


;; img gets special treatment
(defun rk-publish-html-markup-img (beg end o)
  (muse-publish-escape-specials beg end)
  (goto-char beg)
  (insert "<" ele ">")
  (goto-char end))

(setq muse-publish-markup-tags (cons
                                (list "img" t nil 'rk-publish-html-markup-img)
                                muse-publish-markup-tags))

;; we dont want to escape <html> anchors
(defun muse-publish-escape-specials (beg end &optional ignore-read-only context)
  "Escape specials from BEG to END using style-specific :specials.
If IGNORE-READ-ONLY is non-nil, ignore the read-only property.
CONTEXT is used to figure out what kind of specials to escape.

The following contexts exist in Muse.
'underline  _underlined text_
'literal    =monospaced text= or <code>region</code> (monospaced, escaped)
'emphasis   *emphasized text*
'email      address@hidden
'url        http://example.com
'url-desc   [[...][description of an extended link]]
'example    <example>region</example> (monospaced, block context, escaped)
'verbatim   <verbatim>region</verbatim> (escaped)
'document   normal text"
  (let ((specials (muse-style-element :specials nil t)))
    (cond ((functionp specials)
           (setq specials (funcall specials context)))
          ((symbolp specials)
           (setq specials (symbol-value specials))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
        (goto-char (point-min))
        (while (< (point) (point-max))
          (if (and (not ignore-read-only)
                   (get-text-property (point) 'read-only))
              (goto-char (or (next-single-property-change (point) 'read-only)
                             (point-max)))
            (let ((repl (or (assoc (char-after) specials)
                            (assoc (char-after)
                                   muse-publish-markup-specials))))
              (if (null repl)
                  (forward-char 1)
                  ;; v- modified part!
                  (let ((char (char-after))
                        html-p)
                    (when (eq char ?<)
                      (dolist (ele rk-muse-html-commands)
                        (save-excursion
                          (forward-char 1)
                          (when (or (looking-at (concat ele "[ >]"))
                                    (looking-at (concat "/" ele "[ >]"))
                                    )
                            (setq html-p t)
                            (setq prev-html-p t)
                            ))))

                    (when (eq char ?<)
                      (unless html-p
                        (setq prev-html-p nil)))

                    (when (and (eq char ?>)
                               prev-html-p)
                      (setq html-p t)
                      (setq prev-html-p nil))

                    (when (eq char ?&)
                      (save-excursion
                        (forward-char 1)
                        (when (looking-at "gt;\\|lt;")
                          (setq html-p t))))

                    (if html-p
                        (forward-char 1)
                        (progn
                          (delete-char 1)
                          (insert-before-markers (cdr repl)))))))))))))



-- 
...sutongi tti olleh
                                             A coward dies a thousand deaths.




reply via email to

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