emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nitin Agarwal <nitinagarwal3006@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>, emacs-orgmode@gnu.org
Cc: Venkatesh Choppella <choppell@gmail.com>
Subject: Re: [ANN] Editable HTML export of Org-mode files
Date: Tue, 30 Oct 2012 14:37:14 +0500	[thread overview]
Message-ID: <CAHZt45EGGX4Ox+k4N==UaXx47eBQ_Ld8srNoQrEEVeVNxTMxww@mail.gmail.com> (raw)
In-Reply-To: <CAHZt45EU73OG3=F_12bLY27-2-vdrNBd9V2Lbdbzbp_fkm1h1Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 9979 bytes --]

Hi,
Somehow we have to edit the org-ehtml-server.el and the org-ehtml-client.el
file in order to the edit the orgmode file as editable web page where we
can edit the headings
or subheadings.

functions defined in the org-ehtml-server.el file

(defun org-ehtml-handler (httpcon)
  (elnode-log-access "org-ehtml" httpcon)
  (elnode-method httpcon
    (GET  (org-ehtml-file-handler httpcon))
    (POST (org-ehtml-edit-handler httpcon))))

(defun org-ehtml-file-handler (httpcon)
  (let ((elnode-docroot-for-no-404 t) (elnode-docroot-for-no-cache t))
    (elnode-docroot-for org-ehtml-docroot :with file :on httpcon :do
      (org-ehtml-serve-file file httpcon))))

(defun org-ehtml-serve-file (file httpcon)
  (cond
   ;; normal files (including index.org or index.html if they exist)
   ((or (not (file-directory-p file))
        (let ((i-org  (expand-file-name "index.org" file))
              (i-html (expand-file-name "index.html" file)))
          (or (and (file-exists-p i-org)  (setq file i-org))
              (and (file-exists-p i-html) (setq file i-html)))))
    (elnode-send-file httpcon
      (if (member (file-name-extension file) '("org" "html"))
          (org-ehtml-client-cached file) file)))
   ;; directory listing
   ((file-directory-p file)
    (let ((pt (elnode-http-pathinfo httpcon)))
      (elnode-http-start httpcon 200 '("Content-type" . "text/html"))
      (elnode-http-return httpcon
        (elnode--webserver-index
         org-ehtml-docroot file pt org-ehtml-dir-match))))
   ;; none of the above -> missing file
   (t (elnode-send-404 httpcon))))

(defun org-ehtml-edit-handler (httpcon)
  (let* ((params (elnode-http-params httpcon))
         (path       (substring (cdr (assoc "path" params)) 1))
         (beg (string-to-number (cdr (assoc "beg"  params))))
         (end (string-to-number (cdr (assoc "end"  params))))
         (org                   (cdr (assoc "org"  params))))
    (when (string= (file-name-nondirectory path) "")
      (setq path (concat path "index.org")))
    (when (string= (file-name-extension path) "html")
      (setq path (concat (file-name-sans-extension path) ".org")))
    (org-babel-with-temp-filebuffer (expand-file-name path
org-ehtml-docroot)
      (let ((orig (buffer-string)))
        (replace-region beg end org)
        (if (run-hook-with-args-until-failure 'org-ehtml-before-save-hook)
            (save-buffer)
          (replace-region (point-min) (point-max) orig)
          (elnode-send-500 httpcon "edit failed
`org-ehtml-before-save-hook'")))
      (run-hooks 'org-ehtml-after-save-hook))
    (elnode-http-start httpcon "200" '("Content-type" . "text/html"))
    (elnode-http-return httpcon
      (org-export-string org 'html org-ehtml-docroot))))

(provide 'org-ehtml-server)
This provides the org-ehtml-server function on the backend side to export
the org-ehtml file as editable web page and make the changes to the
org-file on the server side to the org file.

functions identified in the org-ehtml-client.el file

(defvar org-ehtml-everything-editable nil
  "Set to a true value to everything exported by org-ehtml editable.")

(defvar org-ehtml-editable-types
  '(paragraph plain-list table verbatim quote-block verse-block)
  "Types of elements whose children should not be editable.")

(defun org-ehtml-client-editable-p (element info)
  (let ((parent (org-export-get-parent element)))
    (cond ((eq (car parent) 'headline)
           (or org-ehtml-everything-editable
               (member "EDITABLE" (org-export-get-tags parent info))))
          ((eq (car parent) 'org-data)
           (or org-ehtml-everything-editable
               (some
                (lambda (keyword)
                  (let ((key (plist-get (cadr keyword) :key))
                        (val (plist-get (cadr keyword) :value)))
                    (and (string= "PROPERTY" key)
                         (string-match "editable \\(.+\\)" val)
                         (car (read-from-string (match-string 1 val))))))
                (cddr (caddr parent)))))
          ((member (car parent) org-ehtml-editable-types) nil)
          (t (org-ehtml-client-editable-p parent info)))))

(defmacro def-ehtml-wrap (e-html-function)
  "Defines and returns an ehtml-wrapped version of E-HTML-FUNCTION."
  (let ((fname (intern (concat "org-ehtml-client"
                               (substring (symbol-name e-html-function)
10)))))
    `(defun ,fname (element contents info)
       ,(format "ehtml wrapper around `%s'." e-html-function)
       (let* ((original-contents (copy-seq contents))
              (original-info     (copy-seq info))
              (html-text (,e-html-function element contents info))
              (org-text  (or (org-element-interpret-data element)
                             original-contents
                             (error "no org-text found for %s" (car
element)))))
         (if (org-ehtml-client-editable-p element info)
             (org-fill-template org-ehtml-client-wrap-template
              `(("html-text" . ,html-text)
                ("org-text"  . ,org-text)
                ("begin"     . ,(number-to-string
                                 (plist-get (cadr element) :begin)))
                ("end"       . ,(number-to-string
                                 (plist-get (cadr element) :end)))))
           html-text)))))

(eval `(org-export-define-derived-backend ehtml e-html
         :translate-alist
         ((paragraph   . ,(def-ehtml-wrap org-e-html-paragraph))
          (plain-list  . ,(def-ehtml-wrap org-e-html-plain-list))
          (table       . ,(def-ehtml-wrap org-e-html-table))
          (verbatim    . ,(def-ehtml-wrap org-e-html-verbatim))
          (quote-block . ,(def-ehtml-wrap org-e-html-quote-block))
          ;; (src-block   . ,(def-ehtml-wrap org-e-html-src-block))
          (verse-block . ,(def-ehtml-wrap org-e-html-verse-block)))))

(defun org-ehtml-client-export-to-html
  (&optional subtreep visible-only body-only ext-plist pub-dir)
  "Export current buffer to an editable HTML file."
  (interactive)
  (let* ((extension (concat "." org-e-html-extension))
     (file (org-export-output-file-name extension subtreep pub-dir))
     (org-export-coding-system org-e-html-coding-system)
         ;; custom headers
         (org-e-html-style-extra (concat org-e-html-style-extra "\n"
                                         org-ehtml-client-style))
         (org-e-html-scripts (concat org-e-html-scripts "\n"
                                     (org-ehtml-client-scripts))))
    (org-export-to-file 'ehtml file subtreep visible-only body-only
ext-plist)))

(defun org-ehtml-client-export-file (file)
  "Export FILE's contents to editable HTML."
  (save-window-excursion
    (find-file file)
    (org-ehtml-client-export-to-html)))

(defun org-ehtml-client-cached (file)
  "Export FILE to editable HTML if no previous export exists.
If a previous HTML export of FILE exists but is older than FILE
re-export."
  (flet ((age (f)
              (float-time
               (time-subtract (current-time)
                              (nth 5 (or (file-attributes (file-truename f))
                                         (file-attributes f)))))))
    (let* ((base (file-name-sans-extension file))
           (html (concat base ".html"))
           (org (concat base ".org")))
      (if (and (file-exists-p org)
               (or (not (file-exists-p html)) (> (age html) (age org))))
          (org-ehtml-client-export-file org)
        html))))

(provide 'org-ehtml-client)

this provides the org-ehtml-client where the client can make the changes to
the org-file viewed as an editable web page and editable function (defun
org-ehtml-client-editable-p (element info).

If anyone comes with some solution to make the org-file exported as an
editable web page where one can edit the parent headings and subheadings of
the content , kindly reply back.

Thanks
Nitin Agarwal



On Mon, Oct 29, 2012 at 1:29 PM, Nitin Agarwal
<nitinagarwal3006@gmail.com>wrote:

> The edit option comes only for the content of the headings. We can't edit
> the headings and the subheadings of the headings.
> So the source code has to be modified to make the org-mode document
> editable as HTML where we can edit the Headings and subheadings.
> The edit button appears only for the content of the subheadings or
> headings of the document.
> So we have to modify the org-ehtml to inculcate this feature.
>
> thanks
> Nitin Agarwal
>
>
>
> On Sun, Oct 28, 2012 at 8:35 PM, Simon Thum <simon.thum@gmx.de> wrote:
>
>> On 10/28/2012 04:19 PM, Eric Schulte wrote:
>>
>>> Yes, the content of the edit boxes does come from the exported html.
>>> For each portion of the Org-mode document (as delimited by
>>> org-elements), both the raw Org-mode text and the HTML are exported
>>> side-by-side, then the raw Org-mode text is hidden and the HTML is
>>> displayed, until the [edit] button is pushed at which point JavaScript
>>> is used to hide the HTML and to expose the raw Org-mode text in an edit
>>> box.  When edits are committed they are committed one portion (edit-box)
>>> at a time.
>>>
>>> Does this make sense?
>>>
>>> Why would something need to change for "this" to be reliable?
>>>
>> No, that sounds correct in principle. But my whitespace got eaten
>> nonetheless ;(
>>
>> I'll be investigating further.
>>
>> Cheers,
>>
>> Simon
>>
>>
>>
>
>
> --
> *Nitin Agarwal*
> Computer Science and Engineering Student
> International Institute of Information Technology
> Gachibowli, Hyderabad 500 032
> Andhra Pradesh, India
> Phone : +91-9573572831
> E-mail: nitinagarwal3006@gmail.com <nitinagarwal1992@gmail.com>
>            *nitin.agarwal@students.iiit.ac.in*
>



-- 
*Nitin Agarwal*
Computer Science and Engineering Student
International Institute of Information Technology
Gachibowli, Hyderabad 500 032
Andhra Pradesh, India
Phone : +91-9573572831
E-mail: nitinagarwal3006@gmail.com <nitinagarwal1992@gmail.com>
           *nitin.agarwal@students.iiit.ac.in*

[-- Attachment #2: Type: text/html, Size: 12305 bytes --]

  reply	other threads:[~2012-10-30  9:37 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-13 22:28 [ANN] Editable HTML export of Org-mode files Eric Schulte
2012-08-14  7:44 ` Bastien
2012-08-14  9:40 ` Rasmus
2012-08-14 10:01   ` Bastien
2012-08-14 12:56     ` Eric Schulte
2012-08-14 21:45       ` Bastien
2012-08-15 15:31         ` Eric Schulte
2012-08-15  3:25 ` Eric Abrahamsen
2012-08-15 15:17   ` Eric Schulte
2012-08-15 23:51     ` Eric Schulte
2012-08-16  5:08       ` Eric Abrahamsen
2012-08-16  6:45         ` Eric Schulte
2012-08-16  7:27           ` Eric Abrahamsen
2012-08-16 13:36             ` Eric Schulte
2012-08-16 14:41               ` Eric Abrahamsen
2012-08-16 15:08                 ` Eric Schulte
2012-08-16  2:06 ` Ista Zahn
2012-08-16  6:31   ` Eric Schulte
2012-08-16 15:58     ` Ista Zahn
2012-08-16 16:36       ` Eric Schulte
2012-08-16 17:44         ` Achim Gratz
2012-08-16 20:05           ` Eric Schulte
2012-08-16 19:43         ` Ista Zahn
2012-08-16 20:11           ` Eric Schulte
2012-08-16 20:50             ` Ista Zahn
2012-10-02  5:23 ` Eric S Fraga
2012-10-05  3:23   ` Eric Schulte
2012-10-21 18:27 ` Simon Thum
2012-10-22 20:38   ` Eric Schulte
2012-10-24 19:19     ` Simon Thum
2012-10-28 15:19       ` Eric Schulte
2012-10-28 15:35         ` Simon Thum
2012-10-29  8:29           ` Nitin Agarwal
2012-10-30  9:37             ` Nitin Agarwal [this message]
2012-10-30 16:56             ` Eric Schulte

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='CAHZt45EGGX4Ox+k4N==UaXx47eBQ_Ld8srNoQrEEVeVNxTMxww@mail.gmail.com' \
    --to=nitinagarwal3006@gmail.com \
    --cc=choppell@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@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).