emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Samuel Wales <samologist@gmail.com>
To: Tamas K Papp <tkpapp@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: exporting HTML - content only
Date: Mon, 27 Jun 2011 11:56:45 -0700	[thread overview]
Message-ID: <BANLkTi=fapy=eMOREX22xzEf+DMbtZAj5w@mail.gmail.com> (raw)
In-Reply-To: <iua3ff$kap$1@dough.gmane.org>

Hi Tamas,

As a partial solution for you, here is the latest complete solution
for me.  Perhaps you can tailor it to your needs.

I also include a pretty fast exact word count command.


(defconst alpha-org-blog-html-buffer "alpha-org-blog.html")
(defun alpha-org-blog-subtree ()
  "Copy the subtree, converted to HTML, for pasting into Blogger
as a blog post.

If there is an active region, use that instead.

No other software needs to be installed.  No temporary file is

For an example of this code in action, see
http://thekafkapandemic.blogspot.com/ .


You have to turn off Blogger's conversion of newline to br tags
in two places in settings.  This requires the new Blogger post

The HTML code is left in a buffer.  To display it in a browser,
use M-x browse-url-of-buffer or similar.

mail2blogger is a very intriguing option here and I'd like to do
that.  Avoids the web entirely.  See comments.


The top level headline is not interpreted with Blogger title
semantics.  By default it is not exported at all, because Blogger
already has a title.  For both posts and pages, Blogger's title
field forms the URL and is therefore manually entered.



You can export the top level headline with :title:.  For pasting
into Blogger, I don't do this, because it shows up with what
looks like two titles.  In the future, we can make it work with
backends like mail2blogger.  Then it will have title
semantics (the top level will become the title).

In Blogger, pages are different from posts.  They are accessed by
tabs like About, Contribute, Contact.

:title: is also useful if you want to try a different strategy.
I did this for my first blog post.  You can change whether to
include title fields in Blogger settings.  You can only do this
for posts.  Turning off titles has one convenience: you don't
have to enter them manually.  It also has two
drawbacks: (1) people who link to your post by copying that link
cannot do so (they can get it from other places, including the
URL bar and Archives in the sidebar) and (2) the URL gets formed
a litle funnily.


I use Blogger.com for hosted blogging instead of Wordpress.com
because Google has a better attitude toward accessibility.

;;; todo list
;;; === mail2blogger ===
;;; I tried using mail2blogger, but the HTML got posted.  There might
;;; be a way to fix this.  How do you do an HTML email in a format
;;; that gets recognized as HTML?
;;; We want to use raw programmatic email, such as sent using msmtp
;;; or the built-in Emacs client.  The ability to do so will obviate
;;; the need to use Google's command line client or to run Emacs 23.
;;; Patch welcome.
;;; ===
;;; Another good thing to try would be to automate grabbing the source from
;;; the page automatically to compare what you just created with ediff or
;;; git diff --color-words.  This is for edits.
;;; Also, export whole blog before each post for git.  Requires post
;;; method maybe.  How to do that?
;;; Also, check for fixmes.  (Or org could check for fixmes before
;;; all export.  Is there a hook?)
;;; Also, remind you to extract big chunks of comments for possible ohter
;;; blog entries.
;;; /Also, remind you to make sure all links work and review formatting/.
;;; ===
;;; Is there HTML for a title?  I will guess not.

  ;;say about to publish editing or about to publish post.  with
  ;;mail2blogger or weblogger.el or atom, we can automate this and assume
  ;;technically, this should be later in case you kill something inside the
  ;;note.  for some reason org adds this to the post command hook instead of
  ;;just doing it at the time.  need to get this to just do it.  maybe
  ;;call-interactively will work?  no, that does not fix it.
  ;;(let ((k kill-ring))
  ;;(let ((c (car kill-ring)))


      ;;i have an issue with "--", which is perfect for emdash in ascii, but
      ;;gets converted to endash in html.  i'd like it to be emdash in html.
      ;;is there an option for that?

      ;;org converts headlines to html h numbers according to the level in
      ;;the org file, not the level in the region.  i prefer the latter.
      ;;here we kludge it to do it my way.
      ;;top 1 means that the very top level in org is h1 (even if you don't
      ;;export it because you manually enter a title).  it is large.  the
      ;;second level in org is h2.
      ;;blogger does not format h2 bold on firefox in the watermark
      ;;template.  so h3 looks bigger than h2.  removing the h2 css in edit
      ;;html seems to fix things.  so all you have to do is make sure level
      ;;2 in org is a bit smaller than title.  you can do that by making org
      ;;level 2 start with h3 or lower level to make org level 2 smaller.
      ;;therefore, we start with h3.  if we used the top level headline
      ;;(using the :title: tag), we could start with top 3.  = h3.
      ;;but usually we don't use the top level headline, so we use top 2 =
      ;;h2 (the one that doesn't work).  thus the second level in org = h3
      ;;which is just right.  so, after all, we don't really need to fix h2
      ;;in the template.  (but fixing h2 in the template is possibly a good
      ;;idea because it seems to affect h3 somehow.)
      ;;fixme test top semantics with title
      (let ((top 2))
        (unless (org-region-active-p)
        (unless (member "title" (org-get-tags))
          ;;remove title
          (forward-line 1)
          ;;might be nice to add hr here
          ;;we will start with the first headilne's title
          ;;(decf top))
         (let ((org-export-html-toplevel-hlevel
                (+ top -1 (- org-export-html-toplevel-hlevel
                             (org-reduced-level (org-current-level)))))
                (+ top -1 (- org-export-headline-levels
                             (org-reduced-level (org-current-level)))))
               ;;note: priority must be after todo kw for export
               ;;already nil org-export-with-priority
           (org-export-region-as-html (region-beginning)
                                      ;;seems to erase, which we want
                                       ;;this should work if it is a
                                       ;;*buffer* but some might prefer html
                                       ;;mode.  this does not save to a file
                                       ;;unless you do.

         ;;one drawback is it leaves spaces around text.  like "tag> text".
         ;;(hoka-unfill-region-special (point-min) (point-max))
         ;;(goto-char (point-min))
         ;;this does not work because it will join lines with no space
in between;
         ;;we have to actually fill paragraphs.
;;;   (while (search-forward "\n" nil t)
;;;     (replace-match ""))
;;;   (insert "\n")
         ;;unnec if blogger knows to treat whitespace as insignificant
;;;   (goto-char (point-min))
;;;   (delete-matching-lines "^$")
         (kill-ring-save (point-min) (point-max))))
      (setq header-line-format "html output")
      ;;return this for programmatic use
  ;;(setq deactivate-mark t)

(defun alpha-org-wc ()
  "Run wc(1) on the formatted subtree or active region.  Because it is
formatted using w3m, the word count is exact.

Currently this will save in the kill ring also."
      ;;need to make this not save in kill ring
      (switch-to-buffer (alpha-org-blog-subtree))
      (w3m-region 1 (buffer-size))
      (setq header-line-format "temporary formatted output for wc (not html)")
      ;;(call-interactively 'browse-url-of-buffer)
      (shell-command-on-region (point-min) (point-max) "wc")
      ;;now return the value itself
      (switch-to-buffer "*Shell Command Output*")
      (goto-char (point-min))
      (forward-word 1)
      ;;string-to-number (buffer-substring (region-beginning ...
      ;;(prog1 ... (bury-buffer)
      (read (current-buffer)))))

The Kafka Pandemic: http://thekafkapandemic.blogspot.com
I support the Whittemore-Peterson Institute (WPI)
Bigotry against people with serious diseases is still bigotry.

      parent reply	other threads:[~2011-06-27 18:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-27 14:18 exporting HTML - content only Tamas K Papp
2011-06-27 15:40 ` Ian Barton
2011-06-27 16:00   ` Pierre de Buyl
2011-06-27 16:54 ` Christian Moe
2011-06-27 18:56 ` Samuel Wales [this message]

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:

  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='BANLkTi=fapy=eMOREX22xzEf+DMbtZAj5w@mail.gmail.com' \
    --to=samologist@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tkpapp@gmail.com \


* 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


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).