;;; ox-slimhtml.el --- an HTML org export backend for the USWDS -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Marius Peter
;; Author: Marius Peter (rot13 "?znevhf.crgre@ghgnabgn.pbz")
;; Created: March 2021
;; Package-Version: 0.1
;; Keywords: org export publish html
;; Homepage: http://www.smart-documents.org
;; This file is not part of GNU Emacs.
;;; License:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this file. If not, see headline text
;; :attr_html: :class headline #
content
;; content ;; #+END_EXAMPLE (defun ox-html-uswds-paragraph (paragraph contents info) "Transcode a PARAGRAPH element from Org to HTML. CONTENTS is the contents of the paragraph. INFO is a plist holding contextual information." (when contents (if (or (ox-html-uswds--immediate-child-of-p paragraph 'item) (ox-html-uswds--immediate-child-of-p paragraph 'special-block)) contents (if (ox-html-uswds--has-immediate-child-of-p paragraph 'link) (format "%s
" contents) (format "%s
" (ox-html-uswds--attr paragraph) contents))))) ;; examples ;; #+BEGIN_EXAMPLE ;; ,#+BEGIN_EXAMPLE # content ;; content ;; ,#+END_EXAMPLE ;; #+END_EXAMPLE (defun ox-html-uswds-example-block (example-block contents info) "Transcode an EXAMPLE-BLOCK element from Org to HTML. CONTENTS is nil. INFO is a plist holding contextual information." (let ((code (org-html-format-code example-block info))) (when code (format "%s
"
(or (org-element-property :language example-block) "example")
code))))
;; raw html
;; #+BEGIN_EXAMPLE
;; ,#+BEGIN_EXPORT html # export block
;; export block
;; ,#+END_EXPORT
;; ,#+BEGIN_EXPORT javascript #
;; console.log()
;; ,#+END_EXPORT
;; ,#+BEGIN_EXPORT css #
;; span {}
;; ,#+END_EXPORT
;; #+END_EXAMPLE
(defun ox-html-uswds-export-block (export-block contents info)
"Transcode an EXPORT-BLOCK element from Org to HTML.
CONTENTS is nil. INFO is a plist holding contextual information."
(let ((contents (org-element-property :value export-block))
(language (org-element-property :type export-block)))
(when contents
(cond ((string= "JAVASCRIPT" language)
(format "" contents))
((string= "CSS" language)
(format "" contents))
(t
(org-remove-indentation contents))))))
;; snippet
;; #+BEGIN_EXAMPLE
;; @@html:snippet@@ # snippet
;; #+END_EXAMPLE
(defun ox-html-uswds-export-snippet (export-snippet contents info)
"Transcode a EXPORT-SNIPPET object from Org to HTML.
CONTENTS is nil. INFO is a plist holding contextual information."
(let ((contents (org-element-property :value export-snippet)))
(when contents contents)))
;; special block
;; #+BEGIN_EXAMPLE
;; ,#+attr_html: :type text/css #
;; ,#+END_STYLE
;; #+END_EXAMPLE
(load-file "./ox-html-uswds-components.el")
(defun ox-html-uswds-special-block (special-block contents info)
"Transcode SPECIAL-BLOCK from Org to HTML.
CONTENTS is the text within the #+BEGIN_ and #+END_ markers.
INFO is a plist holding contextual information."
(when contents
(let ((block-type (downcase (org-element-property :type special-block))))
(cond ((string= "accordion" block-type)(uswds-component-accordion contents))
((string= "alert-info" block-type) (uswds-component-alert-info contents))
((string= "alert-warning" block-type) (uswds-component-alert-warning contents))
((string= "alert-error" block-type) (uswds-component-alert-error contents))
((string= "alert-success" block-type) (uswds-component-alert-success contents))
((string= "alert-slim" block-type) (uswds-component-alert-slim contents))
((string= "alert-no-icon" block-type) (uswds-component-alert-no-icon contents))
((string= "banner" block-type) (uswds-component-banner contents))
((string= "breadcrumb" block-type) (uswds-component-breadcrumb contents))
((string= "button" block-type) (uswds-component-button contents))
((string= "button-group" block-type) (uswds-component-button-group contents))
((string= "card" block-type) (uswds-component-card contents))
((string= "collection" block-type) (uswds-component-collection contents))
((string= "footer" block-type) (uswds-component-footer contents))
;; TODO form controls and templates
((string= "grid" block-type) (uswds-component-grid contents))
((string= "header" block-type) (uswds-component-header contents))
;; TODO icons
((string= "identifier" block-type) (uswds-component-identifier contents))
((string= "process-list" block-type) (uswds-component-process contents))
((string= "search" block-type) (uswds-component-search contents))
((string= "side-navigation" block-type) (uswds-component-side contents))
((string= "site-alert" block-type) (uswds-component-site-alert contents))
((string= "step-indicator" block-type) (uswds-component-step-indicator contents))
((string= "summary-box" block-type) (uswds-component-summary-box contents))
;; TODO table?
((string= "tag" block-type) (uswds-component-tag contents))
((string= "tooltip" block-type) (uswds-component-tooltip contents))
(t (format "
;; code # code
;; ,#+END_SRC #
;; #+END_EXAMPLE
(defun ox-html-uswds-src-block (src-block contents info)
"Transcode SRC-BLOCK from Org to HTML.
CONTENTS is the text of a #+BEGIN_SRC...#+END_SRC block.
INFO is a plist holding contextual information."
(let ((code (org-html-format-code src-block info))
(language (org-element-property :language src-block)))
(when code
(format "%s
"
language (ox-html-uswds--attr src-block) code))))
;; body
;; #+BEGIN_EXAMPLE
;; ,#+HTML_PREAMBLE: preamble {{{macro}}} # preamble
;; content # content
;; ,#+HTML_POSTAMBLE: postamble {{{macro}}} # postamble
;; #+END_EXAMPLE
(defun ox-html-uswds-inner-template (contents info)
"Return body of document string after HTML conversion.
CONTENTS is the transcoded contents string.
INFO is a plist holding export options."
(when (and contents (not (string= "" contents)))
(let ((container (plist-get info :html-container)))
(concat
(when (and container (not (string= "" container))) (format "<%s>" container))
(or (ox-html-uswds--expand-macros (plist-get info :html-preamble) info) "")
contents
(or (ox-html-uswds--expand-macros (plist-get info :html-postamble) info) "")
(when (and container (not (string= "" container)))
(format "%s>" (cl-subseq container 0 (cl-search " " container))))))))
;; html page
;; #+BEGIN_EXAMPLE
;; ,#+HTML_DOCTYPE: || org-html-doctype # ; html5
;; ,#+HTML_HEAD: || org-html-head # ; when language is set
;; ,#+HTML_TITLE: %t #
;; ,#+HTML_HEAD_EXTRA: || org-html-head-extra # head
;; ,#+HTML_BODY_ATTR: id="test" #