hyperbole-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Koutliner export to HTML


From: Robert Weiner
Subject: Re: Koutliner export to HTML
Date: Sat, 7 Nov 2020 10:22:07 -0500

Good ideas.  We will look at them.

The existing kview:map-tree and related kview:map-* functions allow you to apply arbitrary programmatic transformations to kcells by walking through each cell within a specified set (may be the whole outline) in depth-first order.  So you can take existing code that formats a kcell for HTML export and modify it however you like and then just apply it to whatever set of cells you need to suit your Hyperscope database.

On Sat, Nov 7, 2020 at 2:23 AM Jean Louis <bugs@gnu.support> wrote:
I would propose to rework the Koutliner's function: `kexport:html':

- not to enclose it into HTML headers/closures, unless maybe prefix
  C-u have been used.

- I am not sure here if I can programmatically export as that would be
  useful. My files are not files but database entries. When database
  entry is automatically pulled out of the database, some temporary
  buffer must be created to export Koutliner structure. I hope you
  understand this concept. I am doing same with Org mode and with
  Markdown types of files. There is no limit what type of "file" with
  file mode I can store into database. They are expanded and
  published. I think this function allows programatic exporting.

- there are many types of HTML files, I refer to HTML specifications
  like 4 or 5 and this type here is old. It uses upper case letters
  which are invalid in many new HTML specifications.

- header is built in, as I said there whould be &optional argument
  `with-header' if T to include header. But anyway header has to be
  improved to conform to some standards used today.

This below is I guess HTML 5 template. Maybe best would be if
parameter template can be included with standard template being
defined in Koutliner. Then Koutliner expands into such template. Then
user can define template before calling the function.

<!doctype html>
<html lang="en">
<head>
        <meta charset="utf-8">
        <title>{$page_title}</title>
</head>

<body>
{$koutliner}
</body>

</html>

- reason I am looking into Koutliner is that some documents I wish to
  have with finely grained HTML #names to be able to reference such
  cells in similar way as here:
  https://www.dougengelbart.org/content/view/154/86/#0

  Org mode does not have specific #name for each paragraph, not that I
  know.

On the other hand if document is modified, like if cells are deleted
or added, specific #names they can all get messed up including in
Koutliner.

When using database for collective IQ, those references do not get
messed up on export, as each database backed ID remains same for the
cell, regardless how cells are moved, reordered, or other cells
included or deleted.

I wish to use hyperscope database backed cell editing that can export
to Koutliner for collaboration or futher editing or sending Koutliner
file to remote staff members or public.

Then again Koutliner file should become part of larger database by
simply importing it.

This may all sound abstract and complex. I am already using it with
Markdown and Org mode and currently expanding information into
thousands of web pages. On my side is very practical.


;;;###autoload
(defun kexport:html (export-from output-to &optional soft-newlines-flag)
  "Export a koutline buffer or file in EXPORT-FROM to html format in OUTPUT-TO.
By default, this retains newlines within cells as they are.  With optional prefix arg, SOFT-NEWLINES-FLAG,
hard newlines are not used.  Also converts Urls and Klinks into Html hyperlinks.
STILL TODO:
  Make delimited pathnames into file links (but not if within klinks).
  Copy attributes stored in cell 0 and attributes from each cell."
  (interactive "fKoutline buffer/file to export: \nFHTML buffer/file to save to: \nP")
  (let* ((export-buf-name
          (cond ((or (bufferp export-from)
                     (get-buffer export-from))
                 (buffer-name (get-buffer export-from)))
                ((get-file-buffer export-from)
                 (buffer-name (get-file-buffer export-from)))
                ((stringp export-from)
                 (buffer-name (find-file-noselect export-from)))
                (t (error
                    "(kexport:html): `%s' is an invalid `export-from' argument" export-from))))
         (font-lock-auto-fontify) ;; Prevent syntax highlighting
         (font-lock-mode-disable-list '(html-mode))
         (font-lock-mode-enable-list)
         (html-mode-hook)
         (hm--html-mode-hook)
         (psgml-mode-hook)
         (output-to-buf-name
          (cond ((or (bufferp output-to)
                     (get-buffer output-to))
                 (buffer-name (get-buffer output-to)))
                ((get-file-buffer output-to)
                 (buffer-name (get-file-buffer output-to)))
                ((stringp output-to)
                 (buffer-name (find-file-noselect output-to)))
                (t (error
                    "(kexport:html): `%s' is an invalid `output-to' argument" output-to))))
         (standard-output (get-buffer output-to-buf-name))
         title)

    (set-buffer standard-output)
    (setq buffer-read-only nil
          kexport:output-filename buffer-file-name)
    (erase-buffer)
    (set-buffer export-buf-name)
    (setq kexport:input-filename buffer-file-name)

    ;; Use the first line of the first cell as the default HTML document title.
    (setq title (save-excursion
                  (kotl-mode:beginning-of-buffer)
                  (kcell-view:contents)))
    (if (string-match "\n" title)
        (setq title (substring title 0 (match-beginning 0))))

    ;; If called interactively, prompt user for the title to use.
    (if (called-interactively-p 'interactive)
        (setq title (read-string (format "Title for %s: " output-to-buf-name)
                                 title)))

    (princ "<HTML><HEAD>\n\n")
    (princ "<A ID=\"top\"></A><A ID=\"k0\"></A>\n")
    (princ (format "<TITLE>%s</TITLE>\n" title))
    (if kexport:html-description
        (princ (format "<META ID=\"description\" CONTENT=\"%s\">\n"
                       kexport:html-description)))
    (if kexport:html-keywords
        (princ (format "<META ID=\"keywords\" CONTENT=\"%s\">\n"
                       kexport:html-keywords)))
    (princ "</HEAD>\n\n")
    (princ (format "<BODY %s>\n\n" kexport:html-body-attributes))
    (princ (format "<CENTER><H1>%s</H1></CENTER>\n\n" title))
    (let* ((separator
            (hypb:replace-match-string
             ">" (hypb:replace-match-string
                  "<" (kview:label-separator kview) "&lt;")
             "&gt;"))
           i level label contents)
      (kview:map-tree
       (lambda (kview)
         (setq level (kcell-view:level)
               i level)
         (while (> i 1)
           (princ "<UL>")
           (setq i (1- i)))
         (princ "<TABLE><TR>\n")
         (setq label (kcell-view:label))
         (princ (format "<A ID=\"k%s\"></A>" label))
         (princ (format "<A ID=\"k%s\"></A>\n" (kcell-view:idstamp)))
         (princ "<TD WIDTH=2% VALIGN=top><PRE>\n")
         (princ (format
                 "<FONT %s>%s%s</FONT></PRE></TD>\n"
                 kexport:label-html-font-attributes
                 label separator))
         (princ "<TD>")
         (setq contents (kcell-view:contents))
         (if (string-match "\\`\\([-_$%#@~^&*=+|/A-Za-z0-9 ]+\\):.*\\S-"
                           contents)
             (princ (format "<A ID=\"%s\"></A>"
                            (substring contents 0 (match-end 1)))))
         (setq contents (kexport:html-markup contents))
         (if soft-newlines-flag
             (princ contents)
           (princ "<PRE>") (princ contents) (princ "</PRE>"))
         (princ "</TD>\n")
         (princ "</TR></TABLE>")
         (setq i level)
         (while (> i 1)
           (princ "</UL>")
           (setq i (1- i)))
         (terpri) (terpri))
       kview t t))
    (princ "</BODY></HTML>\n")
    (set-buffer standard-output)
    (save-buffer)))


I use:  Editor:      GNU Emacs 28.0.50 (build 26, x86_64-pc-linux-gnu, X toolkit, cairo version 1.14.8, Xaw3d scroll bars)

        Hyperbole:   7.1.3
        Sys Type:    x86_64-pc-linux-gnu
        OS Type:     gnu/linux
        Window Sys:  x
        News Reader: Gnus v5.13

--
Thanks,
Jean Louis
⎔ λ 🄯 𝍄 𝌡 𝌚


reply via email to

[Prev in Thread] Current Thread [Next in Thread]