Skip to content

Instantly share code, notes, and snippets.

@CestDiego
Created May 30, 2015 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CestDiego/5c19b499daf535db5ed5 to your computer and use it in GitHub Desktop.
Save CestDiego/5c19b499daf535db5ed5 to your computer and use it in GitHub Desktop.
  • This guys use this
         (ht ("show-meta" (plist-get config :show-meta))
             ("title" (or (op/read-org-option "TITLE") "Untitled"))
             ("date" (format-time-string "%b %d, %Y"
                                         (date-to-time
                                          (or (op/read-org-option "DATE")
                                              (format-time-string "%Y-%m-%d")))))
             ("content" (cl-flet ((org-html-fontify-code
                                   (code lang)
                                   (when code (org-html-encode-plain-text code))))
                          (org-export-as 'html nil nil t nil))))

for title which then checking out the op/read-org-option we have:

(defun op/read-org-option (option)
  "Read option value of org file opened in current buffer.
e.g:
#+TITLE: this is title
will return \"this is title\" if OPTION is \"TITLE\""
  (let ((match-regexp (org-make-options-regexp `(,option))))
    (save-excursion
      (goto-char (point-min))
      (when (re-search-forward match-regexp nil t)
        (match-string-no-properties 2 nil)))))

According to it's doc: It will only return the RAW string... WDF M8!

  • So Diego spends 1 hour researching how to export only the title ;_; he can't. He finds org-export-string-as though:
(defun org-export-string-as (string backend &optional body-only ext-plist)
  "Transcode STRING into BACKEND code.

BACKEND is either an export back-end, as returned by, e.g.,
`org-export-create-backend', or a symbol referring to
a registered back-end.
...

TADAAAA!

(org-export-string-as "#+TITLE: asf =sda= asfasf " 'html)

Gives:

</head>
<body>
<div id=\"content\">
<h1 class=\"title\">asf <code>sda</code> asfasf</h1>
</div>
<div id=\"postamble\" class=\"status\">
<p class=\"author\">Author: Diego Berrocal</p>
<p class=\"date\">Created: 2015-05-30 Sat 02:35</p>
<p class=\"creator\"><a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> 24.5.1 (<a href=\"http://orgmode.org\">Org</a> mode 8.2.10)</p>
<p class=\"validation\"><a href=\"http://validator.w3.org/check?uri=referer\">Validate</a></p>
</div>
</body>
</html>"

Oh sweet baby GeeZeus... ;_; let's parse that shit

(let ((export-content (org-export-string-as "#+TITLE: asf =sda= asfasf " 'html)))
  (when (string-match "<h1 class=\\\"title\\\">\\(.*\\)</h1>" export-content)
    (message (match-string 1 export-content))))

OOHH YEAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHhhh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment