emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Publishing Org to Org?
@ 2012-06-04  1:58 François Pinard
  2012-06-04  9:47 ` suvayu ali
  0 siblings, 1 reply; 3+ messages in thread
From: François Pinard @ 2012-06-04  1:58 UTC (permalink / raw)
  To: emacs-orgmode

Hi, Org people!

GitHub renders a README.md file right at the end of the project page,
using bigger fonts for titles, producing clickable links, and such
things.  As I did not feel like maintaining the same information both in
Org and Markdown format, I used the Org -> [org-publish] -> HTML ->
[Pandoc] -> Md route.  I do not make the Org file directly available, as
there are not wholly meant for publication.  It works well because the
non-exportable and other private bits are stripped before the HTML is
produced.  However, Org tables do not nicely survive this route.

Now, GitHub allows for README.org files, and renders them.  The
rendering job is far from perfect, but still, it might be acceptable if
one limits himself to those Org features which GitHub processes
correctly.  One good thing is that we get better tables this way.  I may
not directly publish the original Org file because of its private parts.
So I quickly wrote a small Org copier, tied to my own habits and not
trying to be generic.  I provide it below, in case someone is curious.

My feeling is that ideally, Org should itself provide a standard Org
exporter, as generic as it should be.  One tiny problem, among all
others, is to decide which file extension to use for the result, as .org
is already used for the input file.  Just a thought :-).

François

--8<---------------cut here---------------start------------->8---
#!/usr/bin/env python3

"""\
Trim the private parts of an Org file.

Usage: trim-org [ORG_FILE]

Results go to standard output.
"""

import re, sys

header_prefix_regexp = ('^(\\*+) '
                        '(\\[#[ABC]\\] )?'
                        '(TODO |NEXT |DONE |WAIT )?'
                        '(\\*)?')
# 1 = stars, 2 = priority, 3 = keyword, 4 = once
# 5 = text followed by spaces, 6 = tags
header_regexp = header_prefix_regexp + '(.*?)((:[a-z]+)+:)?$'

class Main:

    def main(self, *arguments):
        import getopt
        options, arguments = getopt.getopt(arguments, '')
        for option, value in options:
            pass
        if arguments:
            for argument in arguments:
                self.trim_file(open(argument), sys.stdout.write)
        else:
            self.trim_file(sys.stdin, sys.stdout.write)

    def trim_file(self, lines, write):
        noexport = None
        for line in lines:
            match = re.match(header_regexp, line)
            if match is not None:
                level = len(match.group(1))
                if noexport is not None and level <= noexport:
                    noexport = None
                tags = match.group(6)
                if noexport is None and tags and ':noexport:' in tags:
                    noexport = level
            if noexport is None:
                if (not line.startswith('#')
                        or line.startswith('#+')
                        or line.startswith('# <<')):
                    write(line)

run = Main()
main = run.main

if __name__ == '__main__':
    main(*sys.argv[1:])
--8<---------------cut here---------------end--------------->8---

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Publishing Org to Org?
  2012-06-04  1:58 Publishing Org to Org? François Pinard
@ 2012-06-04  9:47 ` suvayu ali
  2012-06-04 15:59   ` François Pinard
  0 siblings, 1 reply; 3+ messages in thread
From: suvayu ali @ 2012-06-04  9:47 UTC (permalink / raw)
  To: François Pinard; +Cc: emacs-orgmode

On Mon, Jun 4, 2012 at 3:58 AM, François Pinard <pinard@iro.umontreal.ca> wrote:
> My feeling is that ideally, Org should itself provide a standard Org
> exporter, as generic as it should be.

C-h f org-export-as-org [RET]

-- 
Suvayu

Open source is the future. It sets us free.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Publishing Org to Org?
  2012-06-04  9:47 ` suvayu ali
@ 2012-06-04 15:59   ` François Pinard
  0 siblings, 0 replies; 3+ messages in thread
From: François Pinard @ 2012-06-04 15:59 UTC (permalink / raw)
  To: suvayu ali; +Cc: emacs-orgmode

suvayu ali <fatkasuvayu+linux@gmail.com> writes:

> On Mon, Jun 4, 2012 at 3:58 AM, François Pinard <pinard@iro.umontreal.ca> wrote:

>> My feeling is that ideally, Org should itself provide a standard Org
>> exporter, as generic as it should be.

> C-h f org-export-as-org [RET]

Wow!  Thanks! :-)

François

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-04 15:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-04  1:58 Publishing Org to Org? François Pinard
2012-06-04  9:47 ` suvayu ali
2012-06-04 15:59   ` François Pinard

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