Skip to content

Instantly share code, notes, and snippets.

@Kungsgeten
Created June 23, 2019 17:57
Show Gist options
  • Save Kungsgeten/f689e767541936d84f3ce0228ceb2bd2 to your computer and use it in GitHub Desktop.
Save Kungsgeten/f689e767541936d84f3ce0228ceb2bd2 to your computer and use it in GitHub Desktop.
org-brain HTML export
.org-brain-entry {
border-radius: 25px;
background: #73ad21;
padding: 20px;
padding-top: 7px;
margin: 10px;
}
.org-brain-entry h1 {
margin: 0;
padding: 0;
}
.org-brain-parents h2,
.org-brain-children h2,
.org-brain-friends h2 {
font-size: 110%;
display: inline;
}
.org-brain-parent,
.org-brain-child,
.org-brain-friend {
display: inline;
padding: 10px;
}
(defun org-brain-html-link-tag (entry)
"Generate an HTML link <a> to ENTRY."
(format "<a href=\"#%s\">%s</a>"
(org-brain-entry-identifier entry)
(org-brain-title entry)))
(defun org-brain-html (entry)
"Get ENTRY as HTML."
;; ID, Parents, Children, Friends, Resources, Text
(format "<div class=\"org-brain-entry\" id=\"%s\"><h1>%s</h1>%s%s%s%s%s</div>"
;; ID
(org-brain-entry-identifier entry)
;; Title
(org-brain-title entry)
;; Parents
(if (org-brain-parents entry)
(format "<div class=\"org-brain-parents\"><h2>Parents</h2>%s</div>"
(mapconcat (lambda (parent)
(format "<div class=\"org-brain-parent\">%s</div>"
(org-brain-html-link-tag parent)))
(org-brain-parents entry) "\n"))
"")
;; Children
(if (org-brain-children entry)
(format "<div class=\"org-brain-children\"><h2>Children</h2>%s</div>"
(mapconcat (lambda (child)
(format "<div class=\"org-brain-child\">%s</div>"
(org-brain-html-link-tag child)))
(org-brain-children entry) "\n"))
"")
;; Friends
(if (org-brain-friends entry)
(format "<div class=\"org-brain-friends\"><h2>Friends</h2>%s</div>"
(mapconcat (lambda (friend)
(format "<div class=\"org-brain-friend\">%s</div>"
(org-brain-html-link-tag friend)))
(org-brain-friends entry) "\n"))
"")
;; Resources
(if (org-brain-resources entry)
(format "<div class=\"org-brain-resources\"><h2>Resources</h2>%s</div>"
(mapconcat (lambda (resource)
(format "<div class=\"org-brain-resource\">%s</div>"
(org-export-string-as
(org-make-link-string (car resource) (cdr resource))
'html t)))
(org-brain-resources entry t) "\n"))
"")
;; Text
(org-export-string-as (org-brain-text entry) 'html t)))
(defun org-brain-export ()
"Export your org-brain to HTML."
(interactive)
(with-temp-file (expand-file-name "brain.html" org-brain-path)
(insert (format "<html>\n<head><link rel=\"stylesheet\" href=\"brain.css\">\n</head>\n<body>\n%s\n</body>\n</html>"
(mapconcat #'org-brain-html (append (org-brain-files t)
(org-brain-headline-entries)) "\n\n")))))
(org-brain-export)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment