anchor.diff:  (in-package #:cl-markdown)
   
   #|
  +To do:
  +
  +- allow footnotes to appear on a completely separate page
  +- do footnotes as a popup window with mouse over
  +- handle footnotes 'out of band' a la links
  +
   Footnotes
   {note foo}
   {note "This is a note"}
   {note "Foo"}
   {note This is a note}
  -
  - [foo]> This is the note that goes with foo
  -
  -That is what he thought.{footnote foo}
  -
  - [foo]> "This is a longer note with 
  -linefeeds, *mark-up*, and \\\"escaped\\\" quotes.
  -I'll be wicked surprised if it works out of the 
  -box."
   
   (markdown
    "That is what he thought.{footnote foo}
  
positive.code: 
  OK? ok!\"")
  		      
  
  |#
negative.code: 4. add footnote text at bottom of document / separate page
  5. add link back to anchor in footnote
  
  Our footnote HTML is so heavily influenced by DF that you might think
  we just copied it all.
  |#
  
  (defclass* footnote-info ()
    ((id nil ia)
     (text nil ia)
     (reference-name nil ia)
     (name nil ia)))
  
  (defun footnote (phase args result)
    ;; {documentation text}
    (let ((footnotes 
  	 (or (document-property :footnote)
  	     (setf (document-property :footnote)
  		   (make-instance 'vector-container)))))
      (cond ((eq phase :parse)
  	   (let* ((text (format nil "~{~a ~}" args)))
  	     (when text
  	       (bind ((id (size footnotes))
  		      (fn-basename 
  		       (format nil "~d-~a"
  			       id
  			       (format-date "%Y-%m-%d" 
  					    (document-property 
  					     :date-modified
  					     (get-universal-time)))))
  		      (fn-name (format nil "fn~a" fn-basename))
  		      (ref-name (format nil "fnr~a" fn-basename)))
  		 (insert-item footnotes
  			      (make-instance
  			       'footnote-info
  			       :id id
  			       :name fn-name
  			       :reference-name ref-name
  			       :text text))
  		 (values id)))))
  	((eq phase :render)
  	 (let ((footnote (item-at footnotes (first result))))
  	   (format *output-stream*
  		   "<sup id=~s><a href=\"#~a\">~d</a></sup>"
  		   (reference-name footnote)
  		   (name footnote)
  		   (1+ (id footnote))))))))
      
  (defun footnotes (phase args result)
    (ecase phase
      (:parse)
      (:render
       (format *output-stream* "~&<div class=\"footnotes\">")
       (format *output-stream* "~&<ol>")
       (iterate-elements
        (document-property :footnote)
        (lambda (footnote)
  	(format *output-stream* "~&<li id=\"~a\">"
  		(name footnote))
  	(markdown (text footnote)
  		  :stream *output-stream*
  		  :format *current-format*
  		  :properties '((:omit-final-paragraph . t)
  				(:omit-initial-paragraph . t)))
  	(format *output-stream* "<a href=\"#~a\" class=\"footnoteBacklink\""
  		(reference-name footnote))
  	(format *output-stream* " title=\"Jump back to footnote ~d in the text\""
  		(1+ (id footnote)))
  	(format *output-stream* ">&#8617;</a></li>")))
       (format *output-stream*
  	     "~&</ol>~&</div>"))))
  
  ;; not yet
  #|
  