[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[emacs-wiki-discuss] Re: xhtml-valid note id attributes
From: |
Zak B. Elep |
Subject: |
[emacs-wiki-discuss] Re: xhtml-valid note id attributes |
Date: |
Fri, 29 Jul 2005 22:37:15 +0800 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) |
The latest Gnus update borked my MIME, so resending as unsigned mail...
address@hidden (Zak B. Elep) writes:
> I've tried my hand on recreating your hack by redefining some functions:
Here's an updated version of my code that would work even if I use the
<contents> tag:
; I want note IDs preceded by a "note-" so markup validates under xhtml.
(defun planner-markup-note ()
"Replace note with marked-up span."
(replace-match
(format "#note-%s\n\n** " (match-string 1))))
(defun zakame/emacs-wiki-insert-anchor (anchor)
"Insert an anchor, either around the word at point, or within a tag."
(skip-chars-forward emacs-wiki-regexp-space)
(if (looking-at "<\\([^ />]+\\)>")
(let ((tag (match-string 1)))
(goto-char (match-end 0))
(insert "<a id=\"note-" anchor "\">")
(when emacs-wiki-anchor-on-word
(or (and (search-forward (format "</%s>" tag)
(emacs-wiki-line-end-position) t)
(goto-char (match-beginning 0)))
(forward-word 1)))
(insert "</a>"))
(insert "<a id=\"" anchor "\">")
(when emacs-wiki-anchor-on-word
(forward-word 1))
(insert "</a>")))
(defun zakame/emacs-wiki-link-url (wiki-link)
"Resolve the given WIKI-LINK into its ultimate URL form."
(let ((link (emacs-wiki-wiki-link-target wiki-link)))
(save-match-data
(cond
((emacs-wiki-wiki-url-p link)
(emacs-wiki-escape-url link))
((or (string-match emacs-wiki-image-regexp link)
(string-match emacs-wiki-file-regexp link))
link)
((assoc (emacs-wiki-wiki-base link)
(emacs-wiki-file-alist))
(if (string-match "#" link)
(concat
(emacs-wiki-escape-url
(emacs-wiki-published-name
(substring link 0 (match-beginning 0))
(emacs-wiki-page-name)))
"#note-"
(substring link (match-end 0)))
(emacs-wiki-escape-url
(emacs-wiki-published-name
link (emacs-wiki-page-name)))))))))
(defalias 'emacs-wiki-insert-anchor 'zakame/emacs-wiki-insert-anchor)
(defalias 'emacs-wiki-link-url 'zakame/emacs-wiki-link-url)
; I want <contents> anchors to be prepended with "sec-"
(defun zakame/emacs-wiki-contents-tag (beg end attrs)
(let ((max-depth (let ((depth (cdr (assoc "depth" attrs))))
(or (and depth (string-to-number depth)) 2)))
(index 1)
base contents l)
(save-excursion
(save-match-data
(catch 'done
(while (re-search-forward "^\\(\\*+\\)\\s-+\\(.+\\)" nil t)
(setq l (length (match-string 1)))
(if (null base)
(setq base l)
(if (< l base)
(throw 'done t)))
(when (<= l max-depth)
(setq contents
(cons (cons l (emacs-wiki-wiki-visible-name
(emacs-wiki-match-string-no-properties 2)))
contents))
(goto-char (match-beginning 2))
(emacs-wiki-insert-anchor
(concat "sec-" (int-to-string index)))
(setq index (1+ index)))))))
(setq index 1 contents (reverse contents))
(let ((depth 1) (sub-open 0) (p (point)))
(insert "<dl class=\"contents\">\n")
(while contents
(insert "<dt class=\"contents\">\n")
(insert "<a href=\"#sec-" (int-to-string index) "\">"
(cdar contents)
"</a>\n")
(setq index (1+ index))
(insert "</dt>\n")
(setq depth (caar contents)
contents (cdr contents))
(if contents
(cond
((< (caar contents) depth)
(let ((idx (caar contents)))
(while (< idx depth)
(insert "</dl>\n</dd>\n")
(setq sub-open (1- sub-open)
idx (1+ idx)))))
;; can't jump more than one ahead
((> (caar contents) depth)
(insert "<dd>\n<dl class=\"contents\">\n")
(setq sub-open (1+ sub-open))))))
(while (> sub-open 0)
(insert "</dl>\n</dd>\n")
(setq sub-open (1- sub-open)))
(insert "</dl>\n")
(put-text-property p (point) 'read-only t))))
(defalias 'emacs-wiki-contents-tag 'zakame/emacs-wiki-contents-tag)
My only gripe is that planner-rss doesn't output the right anchor
links---it still outputs "page#number" instead of "page#note-number".
Hmmm...
--
ZAK B. ELEP <address@hidden> -- <http://zakame.spunge.org>
1024D/FA53851D 1486 7957 454D E529 E4F1 F75E 5787 B1FD FA53 851D
-- Running Debian GNU+Linux testing/unstable. GnuPG signed mail preferred.