 	 (table-cell . nil)
 	 (table-row . nil)
 	 (target . nil)
-	 (template . nil)
+	 (template . org-trec-template)
 	 (timestamp . org-trec-export-raw)
 	 (underline . org-trec-export-raw)
 	 (verbatim . org-trec-export-value)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Org mode export to TREC format ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; boring, undecorated stuff
(defun org-trec-export-raw (element contents info)
  contents)
(defun org-trec-export-value (element contents info)
  (org-element-property :value element))

(defun org-trec-link (link desc info)
  desc)
(defun org-trec-plain-text (text info)
  text)
;; i don't often use it in this context...
(defun org-trec-subscript (element contents info)
  (concat "_" contents))

;; other stuff
(defun org-trec-headline (headline contents info)
 ;;(with-output-to-string (princ (org-element-property :title headline)))
  (concat (org-export-data (org-element-property :title headline) info) "\n" contents
		  ;;(with-output-to-string (princ (org-element-contents headline)))
		  )
)

(defun org-trec-planning (planning contents info)

	(if deadline
		(concat "Deadline: " (org-timestamp-to-date-string deadline))
	  (if scheduled
		  (concat "Scheduled: " (org-timestamp-to-date-string scheduled))
		(if closed
			(concat "Closed: " (org-timestamp-to-date-string closed)))))))

(defun org-trec-section (section contents info)
  ;; TODO this is a bit limiting, it implies all docs have a beginning
  ;; "section" to set the title
  (if (= 1 (org-element-property :begin section))
	  (concat "<TITLE>" contents "</TITLE>\n<TEXT>\n")
	contents))

(defun org-timestamp-to-date-string (timestamp)
  "Convert an Org mode timestamp object to a string with time if given. e.g. 2013-01-01 10:13"
