emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Nick Dokos <ndokos@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: HTML/images zipped?
Date: Fri, 26 Jun 2015 19:34:02 -0400	[thread overview]
Message-ID: <m2oak2hwnp.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <87si9e6suh.fsf@alphaville.usersys.redhat.com>

hm... maybe it has been a while since I ran that ;) I pushed some
changes that seem to have it working on a small test file.

This code is somewhat on the border of a filter/custom export. There are
probably links that will now work with it, I have not tested it super
thoroughly.

Notably, it does not preserve relative paths, but rather renames files
and images and replaces the links in the org-file with the new
names. It was too hard to figure out how to preserve the paths when I
wrote this originally.

Nick Dokos writes:

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> I did something like this for org-files:
>> https://github.com/jkitchin/jmax/blob/master/ox-archive.el
>>
>
> I tried this on some arbitrary org file (not containing any references) and I got an error:
>
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>   file-name-directory(nil)
>   (let* ((temporary-file-directory (file-name-directory (buffer-file-name))) (tempname (make-temp-file "extract-bib")) (contents (buffer-string)) (cb (current-buffer)) basename texfile bibfile results) (find-file tempname) (insert contents) (setq basename (file-name-sans-extension (file-name-nondirectory buffer-file-name)) texfile (concat tempname ".tex") bibfile (concat tempname ".bib")) (save-excursion (goto-char (point-min)) (if (re-search-forward "^bibliography:" (point-max) (quote end)) nil (insert (format "\nbibliography:%s" (mapconcat (quote identity) reftex-default-bibliography ","))))) (save-buffer) (org-latex-export-to-latex) (find-file texfile) (reftex-parse-all) (reftex-create-bibtex-file bibfile) (save-buffer) (setq results (buffer-string)) (kill-buffer (concat basename ".bib")) (kill-buffer (concat basename ".tex")) (kill-buffer basename) (delete-file bibfile) (delete-file texfile) (delete-file tempname) (switch-to-buffer cb) (if (not (string= "" results)) (progn (save-excursion (goto-char (point-max)) (insert "\n\n") (org-insert-heading) (insert (format " Bibtex entries\n\n#+BEGIN_SRC text :tangle %s\n%s\n#+END_SRC" (concat (file-name-sans-extension ...) ".bib") results))))))
>   org-ref-extract-bibtex-entries()
>   (let* ((org-file (buffer-name)) (org-file-abs-path (buffer-file-name)) (base-name (file-name-sans-extension org-file)) (org-archive (if (string= zip-base-name "") (concat base-name "-" (format-time-string "%Y-%m-%d" (current-time))) zip-base-name)) (org-archive-zip (concat org-archive ".zip")) link-list) (if (file-exists-p org-archive-zip) (progn (delete-file org-archive-zip))) (if (file-exists-p org-archive) (progn (delete-directory org-archive t))) (make-directory org-archive t) (setq link-list (let ((parsetree (org-element-parse-buffer)) (counter 0)) (org-element-map parsetree (quote link) (function (lambda (link) (let* (... ... ... ... ... ... ... ...) (message ...) (cond ... ... ...))))))) (message (format "\n\nlink-list: %s\n\n" link-list)) (let ((counter 0)) (defalias (quote ox-mrkup-filter-link) (function (lambda (text back-end info) (message "handing link %s: %s\n" counter text) (let ((link ...)) (message "  %s replacement is %s\n" counter link) (if (not ...) (progn ... ...) (setq output ...)) (setq counter (+ counter 1)) output)))) (let ((org-export-filter-link-functions (quote (ox-mrkup-filter-link)))) (org-org-export-as-org))) (switch-to-buffer "*Org ORG Export*") (insert (format "# archived from %s on %s\n" org-file-abs-path (format-time-string "%Y-%m-%d" (current-time)))) (org-ref-extract-bibtex-entries) (write-file (expand-file-name org-file org-archive)) (shell-command (concat "zip -v -r " org-archive-zip " *")) (rename-file org-archive-zip (concat "../" org-archive ".zip")) (switch-to-buffer org-file) (delete-directory org-archive t) org-archive-zip)
>   ox-archive-create-zip("foo")
> ...
>
> I think there is a bug in ox-archive-create-zip:
>
> --8<---------------cut here---------------start------------->8---
>     ...
>     (switch-to-buffer "*Org ORG Export*")
>     (insert (format "# archived from %s on %s\n"
>                   org-file-abs-path
>                   (format-time-string "%Y-%m-%d" (current-time))))
>
>     ;; add bibliography references if they exist.
>     (org-ref-extract-bibtex-entries)
>     ...
> --8<---------------cut here---------------end--------------->8---
>
> because the first thing that org-ref-extract-bibtex-entries does is
>
> --8<---------------cut here---------------start------------->8---
>   (let* ((temporary-file-directory (file-name-directory (buffer-file-name)))
> --8<---------------cut here---------------end--------------->8---
>
> and (buffer-file-name) returns nil on the *Org ORG Export* buffer.
> But since you obviously use this code successfully, I wonder why
> you don't hit this.
>
> Thanks for any help,
> Nick

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

  reply	other threads:[~2015-06-26 23:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26 13:10 HTML/images zipped? Peter Davis
2015-06-26 13:15 ` Rasmus
2015-06-26 14:05   ` Peter Davis
2015-06-26 14:24   ` John Kitchin
2015-06-26 14:35     ` Peter Davis
2015-06-26 17:22     ` Peter Davis
2015-06-26 18:09       ` John Kitchin
2015-06-26 19:28         ` Peter Davis
2015-06-26 21:51     ` Nick Dokos
2015-06-26 23:34       ` John Kitchin [this message]
2015-06-27  4:52         ` Nick Dokos
2015-06-26 13:44 ` Phillip Lord
2015-06-26 14:08   ` Peter Davis
2015-06-26 14:30     ` John Kitchin
2015-06-29  8:47 ` Robert Klein
2015-06-29 11:13   ` Rasmus
2015-06-30 20:05     ` Robert Klein
2015-06-30  5:38 ` Vaidheeswaran C

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2oak2hwnp.fsf@andrew.cmu.edu \
    --to=jkitchin@andrew.cmu.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=ndokos@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).