[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] HTML/images zipped?
From: |
John Kitchin |
Subject: |
Re: [O] HTML/images zipped? |
Date: |
Fri, 26 Jun 2015 19:34:02 -0400 |
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 <address@hidden> 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
Re: [O] HTML/images zipped?, Phillip Lord, 2015/06/26
Re: [O] HTML/images zipped?, Robert Klein, 2015/06/29
Re: [O] HTML/images zipped?, Vaidheeswaran C, 2015/06/30