;; is not a good macro since color in bgcolor would be
;; replaced!
;;
;; -----------------------------------------------------------
;; Usage of above macros in example:
;;
;; abc
;;
;; ...
;; Tjohoo!
;;
;; -----------------------------------------------------------
;; Filename extensions for Jaq Html: .jhtml
;; These functions save the resulting file as .html
;;
;; -----------------------------------------------------------
;; The name of the macro and the arguments of or to the macro
;; may contains the following characters: a-z A-Z 0-9 _ " # -
;; But no actual strings, no tabs and no spaces or linefeeds.
;; TODO:
;; match-beginning funkar dven p} search-forward. Anv{nd!!!!!.
;; match the regexp chars in the info above. Perhaps .+ is enogh?
(defun jaq-html-to-html (filename)
(if (not (string-match ".jhtml\\'" filename))
(error "Not an .jhtml file!"))
(find-file filename)
;; Search for
(while (search-forward ""))
(arglist)
(replacement)
(start-replace-from)
(rep-start)
(rep-arg)
(rep-end)
(actual-arglist)
(next-macro))
(goto-char start-args)
;; Find arguments include name of new macro.
(while (search-forward-regexp "[a-zA-Z0-9~@\.:_/\"#\-]+" end-macro t)
(setq arglist (append arglist (list (buffer-substring
(match-beginning 0)
(match-end 0))))))
(search-forward "")
(setq replacement (buffer-substring end-macro (- (point) 8)))
(delete-region start-macro (point)) ; Remove ...
(setq next-macro (point))
;;; Replacing.
(setq start-replace-from (point))
(while (search-forward (concat "<" (car arglist)) (point-max) t)
(setq rep-start (match-beginning 0))
(setq rep-arg (point))
(setq rep-end (search-forward ">"))
(goto-char rep-arg)
(setq actual-arglist nil)
;;; Find actual arguments.
(while (search-forward-regexp "[a-zA-Z0-9~@\.:_/\"#\-]+" rep-end t)
(setq actual-arglist
(append actual-arglist (list (buffer-substring
(match-beginning 0)
(match-end 0))))))
;; Replace macro.
(delete-region rep-start rep-end)
(insert replacement)
;; Replace arguments of macro.
(setq rep-end (point-marker))
(goto-char start-replace-from)
(jaq-html-replace-args (cdr arglist) actual-arglist
start-replace-from rep-end)
(goto-char rep-end)
(setq start-replace-from (point)) ;; Where to continue from.
(move-marker rep-end nil) )
(goto-char next-macro) ))
;; Save buffer with new name.
(write-file (concat
(substring filename 0 (string-match ".jhtml\\'" filename))
".html"))
)
(defun jaq-html-replace-args (arglist1 arglist2 start bookmark-stop)
(cond ((null arglist1)
nil)
((null arglist2)
nil)
(t
(goto-char start)
(while (search-forward (car arglist1) bookmark-stop t)
(replace-match (car arglist2)))
(jaq-html-replace-args
(cdr arglist1) (cdr arglist2) start bookmark-stop))))
|