From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?Fran=C3=A7ois_Pinard?= Subject: Publishing Org to Org? Date: Sun, 03 Jun 2012 21:58:45 -0400 Message-ID: <86ipf7ald6.fsf@mercure.progiciels-bpi.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:49178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbMZH-0005yb-5U for emacs-orgmode@gnu.org; Sun, 03 Jun 2012 21:58:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbMZE-0005Do-T7 for emacs-orgmode@gnu.org; Sun, 03 Jun 2012 21:58:50 -0400 Received: from 206-248-137-202.dsl.teksavvy.com ([206.248.137.202]:50860 helo=mercure.progiciels-bpi.ca) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbMZE-0005Dc-Mj for emacs-orgmode@gnu.org; Sun, 03 Jun 2012 21:58:48 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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=C3=A7ois --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 =3D ('^(\\*+) ' '(\\[#[ABC]\\] )?' '(TODO |NEXT |DONE |WAIT )?' '(\\*)?') # 1 =3D stars, 2 =3D priority, 3 =3D keyword, 4 =3D once # 5 =3D text followed by spaces, 6 =3D tags header_regexp =3D header_prefix_regexp + '(.*?)((:[a-z]+)+:)?$' class Main: def main(self, *arguments): import getopt options, arguments =3D 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 =3D None for line in lines: match =3D re.match(header_regexp, line) if match is not None: level =3D len(match.group(1)) if noexport is not None and level <=3D noexport: noexport =3D None tags =3D match.group(6) if noexport is None and tags and ':noexport:' in tags: noexport =3D level if noexport is None: if (not line.startswith('#') or line.startswith('#+') or line.startswith('# <<')): write(line) run =3D Main() main =3D run.main if __name__ =3D=3D '__main__': main(*sys.argv[1:]) --8<---------------cut here---------------end--------------->8---