From 7697fa4daf3ec84f85711a84035d8f0224afd4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Delafond?= Date: Sun, 13 Jul 2014 13:35:01 +0200 Subject: Imported Upstream version 7.9.2 --- contrib/scripts/.gitignore | 1 + contrib/scripts/StartOzServer.oz | 231 +++++++++++++++++++++ contrib/scripts/dir2org.zsh | 54 +++++ contrib/scripts/docco.css | 185 +++++++++++++++++ contrib/scripts/org-docco.org | 206 ++++++++++++++++++ contrib/scripts/org2hpda | 106 ++++++++++ contrib/scripts/staticmathjax/.gitignore | 1 + contrib/scripts/staticmathjax/README.org | 79 +++++++ contrib/scripts/staticmathjax/application.ini | 11 + .../scripts/staticmathjax/chrome/chrome.manifest | 1 + .../scripts/staticmathjax/chrome/content/main.js | 198 ++++++++++++++++++ .../scripts/staticmathjax/chrome/content/main.xul | 11 + .../staticmathjax/defaults/preferences/prefs.js | 1 + 13 files changed, 1085 insertions(+) create mode 100644 contrib/scripts/.gitignore create mode 100644 contrib/scripts/StartOzServer.oz create mode 100755 contrib/scripts/dir2org.zsh create mode 100644 contrib/scripts/docco.css create mode 100644 contrib/scripts/org-docco.org create mode 100755 contrib/scripts/org2hpda create mode 100644 contrib/scripts/staticmathjax/.gitignore create mode 100644 contrib/scripts/staticmathjax/README.org create mode 100644 contrib/scripts/staticmathjax/application.ini create mode 100644 contrib/scripts/staticmathjax/chrome/chrome.manifest create mode 100644 contrib/scripts/staticmathjax/chrome/content/main.js create mode 100644 contrib/scripts/staticmathjax/chrome/content/main.xul create mode 100644 contrib/scripts/staticmathjax/defaults/preferences/prefs.js (limited to 'contrib/scripts') diff --git a/contrib/scripts/.gitignore b/contrib/scripts/.gitignore new file mode 100644 index 0000000..20d5925 --- /dev/null +++ b/contrib/scripts/.gitignore @@ -0,0 +1 @@ +plantuml.jar diff --git a/contrib/scripts/StartOzServer.oz b/contrib/scripts/StartOzServer.oz new file mode 100644 index 0000000..db12dec --- /dev/null +++ b/contrib/scripts/StartOzServer.oz @@ -0,0 +1,231 @@ +%%% ************************************************************* +%%% Copyright (C) 2009-2012 Torsten Anders (www.torsten-anders.de) +%%% This program is free software; you can redistribute it and/or +%%% modify it under the terms of the GNU General Public License +%%% as published by the Free Software Foundation; either version 2 +%%% of the License, or (at your option) any later version. +%%% This program is distributed in the hope that it will be useful, +%%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%%% GNU General Public License for more details. +%%% ************************************************************* + +%% +%% This code implements the Oz-side of the Org-babel Oz interface. It +%% creates a socket server (to which org-babel-oz.el then +%% connects). Any input to this socket must be an Oz expression. The +%% input is fed to the OPI oz compiler, and the results are send back +%% via the socket. +%% + + +declare + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% +%% Accessing the OPI compiler +%% + +MyCompiler = Emacs.condSend.compiler + + +/* % testing + +%% Feed an expression (result browsed) +{MyCompiler enqueue(setSwitch(expression true))} +{Browse + {MyCompiler enqueue(feedVirtualString("1 + 2" return(result: $)))}} +{MyCompiler enqueue(setSwitch(expression false))} + +%% It is really the OPI: I can use declare! +{MyCompiler enqueue(setSwitch(expression false))} +{MyCompiler enqueue(feedVirtualString("declare X=3\n{Browse X*X}"))} + +%% Note: expressions starting with keyword declare need keyword in +{MyCompiler enqueue(setSwitch(expression true))} +{Browse + {MyCompiler enqueue(feedVirtualString("declare X=3\nin X*X" return(result: $)))}} +{MyCompiler enqueue(setSwitch(expression false))} + +%% Alternatively you use a session with multiple feeds: first declare (statement), and then feed an expression +{MyCompiler enqueue(setSwitch(expression false))} +{MyCompiler enqueue(feedVirtualString("declare X=7" return))} +{MyCompiler enqueue(setSwitch(expression true))} +{Browse + {MyCompiler enqueue(feedVirtualString("X*X" return(result: $)))}} +{MyCompiler enqueue(setSwitch(expression false))} + +%% !!?? does not work? +%% return nil in case of any error (division by 0) +{MyCompiler enqueue(setSwitch(expression true))} +{Browse + {MyCompiler enqueue(feedVirtualString( + {Accum ["try\n" +% "skip\n" % do something in any case.. + "1 div 0" % my code +% "1" % my code + "\ncatch E then {Error.printException E}\n" + "error\n" % always return nil + "end\n"] + List.append} + return(result: $)))}} +{MyCompiler enqueue(setSwitch(expression false))} + + +%% !! catching some exceptions does not work?? + +%% exception is not catched +try {Bla} catch E then {Error.printException E} {Browse nil} end + +%% exception is catched +try {Browse 1 div 0} catch E then {Error.printException E} {Browse nil} end +{Browse ok} + + +*/ + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% +%% Socket interface +%% + + +%% +%% Create socket +%% + +MyPort = 6001 + +/** %% Creates a TCP socket server. Expects a Host (e.g., 'localhost') and a PortNo and returns a server plus its corresponding client. This client is an instance of Open.socket, and is the interface for reading and writing into the socket. +%% MakeServer blocks until the server listens. However, waiting until a connection has been accepted happens in its own thread (i.e. MakeServer does only block until the server listens). +%% NB: A port can be used only once, so assign it carefully. In case this postnnumber was shortly used before, you may need to wait a bit before reusing it. +%% */ +%% !! Alternatively, let it assign automatically and output the port number.. +%% +%% NOTE: for supporting multiple connections see http://www.mozart-oz.org/documentation/op/node13.html#section.sockets.accept +proc {MakeServer Host PortNo ?MyServer ?MyClient} + proc {Accept MyClient} + thread H in % P + %% suspends until a connection has been accepted + {MyServer accept(host:H + acceptClass:Open.socket + accepted:?MyClient)} +% {Myserver accept(host:H port:P)} % suspends until a connection has been accepted + %% !!?? port number of client is usually created randomly.. + {System.showInfo "% connection accepted from host "#H} + end + %% !!??? + %% If Accept is called recursively, then server accepts multiple connections. These share the same compiler instance (e.g. variable bindings are shared). For multiple independent compiler instances call the OzServer application multiple times. + %% However, how shall the output for multiple connections be sorted?? Would using the different client sockets created with the Server accept method work? + %% NB: The number of clients accepted concurrently must be limited to the number set by {MyServer listen} + % {Accept} + end +in + MyServer = {New Open.socket init} + %% To avoid problems with portnumbers, the port could be assigned automatically and then output.. + %%{MyServer bind(port:PortNo)} + {MyServer bind(host:Host takePort:PortNo)} + {MyServer listen} + {System.showInfo "% OzServer started at host "#Host#" and port "#PortNo} + MyClient = {Accept} +end +%% +MySocket = {MakeServer localhost MyPort _/*MyServer*/} + + +%% +%% Read socket input +%% + +declare +%% Copied from OzServer/source/Socket.oz +local + proc {Aux Socket Size Stream} + In = {Socket read(list:$ + size:Size)} + in + {Wait In} + %% !! Is this the right way to stop the processing?? + %% + %% abort condition when client stream ended (i.e. nothing was sent) + if In == nil + then {System.showInfo "socket stream ended"} + Stream = nil + else Stream = In | {Aux Socket Size} + end + end +in + /** %% The socket Server returns a stream of the strings it receives. The Server always waits until someone writes something into the socket, then the input is immediately written to a stream and the Server waits again. + %% */ + proc {ReadToStream Socket Size Xs} + thread {Aux Socket Size Xs} end + end +end + +/* % test + +MyStream = {ReadToStream MySocket 1024} + +*/ + +/* % test + +%% writing +{MySocket write(vs:"this is a test")} + +*/ + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% +%% Send socket input to compiler and send results back to socket +%% + +%% NOTE: Input code must be expression +thread + {ForAll {ReadToStream MySocket 1024} + proc {$ Code} + Result + %% Catch any exception (so the will not cause blocking) and return nil in that case + FullCode = {Accum ["try\n" +% "skip\n" % do something in any case.. + Code + "\ncatch E then {Error.printException E}\n" + "error\n" % in case of an error, return 'error' + "end\n"] + List.append} + in + %% ?? Should I make setting switches etc atomic? + {MyCompiler enqueue(setSwitch(expression true))} + {MyCompiler enqueue(feedVirtualString(FullCode return(result: ?Result)))} + {MyCompiler enqueue(setSwitch(expression false))} + %% + {Wait Result} + {MySocket write(vs: if {VirtualString.is Result} + then Result + else {Value.toVirtualString Result 1000 1000} + end)} + {Show 'Org-babel result: '#Result} + end} +end + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% +%% Aux defs +%% + +/** %% Binds the accumulation of the binary function Fn on all neighbors in Xs to Y. E.g., Accum returns the sum in Xs if Fn is Number.'+'. +%% */ +proc {Accum Xs Fn Y} + {List.foldL Xs.2 Fn Xs.1 Y} +end + + + + + + + diff --git a/contrib/scripts/dir2org.zsh b/contrib/scripts/dir2org.zsh new file mode 100755 index 0000000..1ea8be4 --- /dev/null +++ b/contrib/scripts/dir2org.zsh @@ -0,0 +1,54 @@ +# desc: +# +# Output an org compatible structure representing the filesystem from +# the point passed on the command line (or . by default). +# +# options: +# none +# +# usage: +# dir2org.zsh [DIR]... +# +# author: +# Phil Jackson (phil@shellarchive.co.uk) + +set -e + +function headline { + local depth="${1}" + local text="${2}" + + printf "%${depth}s %s" "" | tr ' ' '*' + echo " ${text}" +} + +function scan_and_populate { + local depth="${1}" + local dir="${2}" + + headline ${depth} "${dir}" + + # if there is no files in dir then just move on + [[ $(ls "${dir}" | wc -l) -eq 0 ]] && return + + (( depth += 1 )) + + for f in $(ls -d "${dir}"/*); do + if [ -d "${f}" ]; then + scan_and_populate ${depth} "${f}" + else + headline ${depth} "[[file://${f}][${${f##*/}%.*}]]" + fi + done + + (( depth -= 1 )) +} + +function main { + local scan_dir="${1:-$(pwd)}" + local depth=0 + + scan_and_populate ${depth} "${scan_dir}" +} + +main "${@}" diff --git a/contrib/scripts/docco.css b/contrib/scripts/docco.css new file mode 100644 index 0000000..9030b6c --- /dev/null +++ b/contrib/scripts/docco.css @@ -0,0 +1,185 @@ +/*--------------------- Layout and Typography ----------------------------*/ +body { + font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; + font-size: 15px; + line-height: 22px; + color: #252519; + margin: 0; padding: 0; +} +a { + color: #261a3b; +} + a:visited { + color: #261a3b; + } +p { + margin: 0 0 15px 0; +} +h1, h2, h3, h4, h5, h6 { + margin: 0px 0 15px 0; +} + h1 { + margin-top: 40px; + } +#container { + position: relative; +} +#background { + position: fixed; + top: 0; left: 525px; right: 0; bottom: 0; + background: #f5f5ff; + border-left: 1px solid #e5e5ee; + z-index: -1; +} +#jump_to, #jump_page { + background: white; + -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777; + -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px; + font: 10px Arial; + text-transform: uppercase; + cursor: pointer; + text-align: right; +} +#jump_to, #jump_wrapper { + position: fixed; + right: 0; top: 0; + padding: 5px 10px; +} + #jump_wrapper { + padding: 0; + display: none; + } + #jump_to:hover #jump_wrapper { + display: block; + } + #jump_page { + padding: 5px 0 3px; + margin: 0 0 25px 25px; + } + #jump_page .source { + display: block; + padding: 5px 10px; + text-decoration: none; + border-top: 1px solid #eee; + } + #jump_page .source:hover { + background: #f5f5ff; + } + #jump_page .source:first-child { + } +table td { + border: 0; + outline: 0; +} + td.docs, th.docs { + max-width: 450px; + min-width: 450px; + min-height: 5px; + padding: 10px 25px 1px 50px; + overflow-x: hidden; + vertical-align: top; + text-align: left; + } + .docs pre { + margin: 15px 0 15px; + padding-left: 15px; + } + .docs p tt, .docs p code { + background: #f8f8ff; + border: 1px solid #dedede; + font-size: 12px; + padding: 0 0.2em; + } + .pilwrap { + position: relative; + } + .pilcrow { + font: 12px Arial; + text-decoration: none; + color: #454545; + position: absolute; + top: 3px; left: -20px; + padding: 1px 2px; + opacity: 0; + -webkit-transition: opacity 0.2s linear; + } + td.docs:hover .pilcrow { + opacity: 1; + } + td.code, th.code { + padding: 14px 15px 16px 25px; + width: 100%; + vertical-align: top; + border-left: 1px solid #e5e5ee; + } + pre, tt, code { + font-size: 12px; line-height: 18px; + font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace; + margin: 0; padding: 0; + } + + +/*---------------------- Syntax Highlighting -----------------------------*/ +td.linenos { background-color: #f0f0f0; padding-right: 10px; } +span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } +body .hll { background-color: #ffffcc } +body .c { color: #408080; font-style: italic } /* Comment */ +body .err { border: 1px solid #FF0000 } /* Error */ +body .k { color: #954121 } /* Keyword */ +body .o { color: #666666 } /* Operator */ +body .cm { color: #408080; font-style: italic } /* Comment.Multiline */ +body .cp { color: #BC7A00 } /* Comment.Preproc */ +body .c1 { color: #408080; font-style: italic } /* Comment.Single */ +body .cs { color: #408080; font-style: italic } /* Comment.Special */ +body .gd { color: #A00000 } /* Generic.Deleted */ +body .ge { font-style: italic } /* Generic.Emph */ +body .gr { color: #FF0000 } /* Generic.Error */ +body .gh { color: #000080; font-weight: bold } /* Generic.Heading */ +body .gi { color: #00A000 } /* Generic.Inserted */ +body .go { color: #808080 } /* Generic.Output */ +body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ +body .gs { font-weight: bold } /* Generic.Strong */ +body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ +body .gt { color: #0040D0 } /* Generic.Traceback */ +body .kc { color: #954121 } /* Keyword.Constant */ +body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */ +body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */ +body .kp { color: #954121 } /* Keyword.Pseudo */ +body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */ +body .kt { color: #B00040 } /* Keyword.Type */ +body .m { color: #666666 } /* Literal.Number */ +body .s { color: #219161 } /* Literal.String */ +body .na { color: #7D9029 } /* Name.Attribute */ +body .nb { color: #954121 } /* Name.Builtin */ +body .nc { color: #0000FF; font-weight: bold } /* Name.Class */ +body .no { color: #880000 } /* Name.Constant */ +body .nd { color: #AA22FF } /* Name.Decorator */ +body .ni { color: #999999; font-weight: bold } /* Name.Entity */ +body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ +body .nf { color: #0000FF } /* Name.Function */ +body .nl { color: #A0A000 } /* Name.Label */ +body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ +body .nt { color: #954121; font-weight: bold } /* Name.Tag */ +body .nv { color: #19469D } /* Name.Variable */ +body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ +body .w { color: #bbbbbb } /* Text.Whitespace */ +body .mf { color: #666666 } /* Literal.Number.Float */ +body .mh { color: #666666 } /* Literal.Number.Hex */ +body .mi { color: #666666 } /* Literal.Number.Integer */ +body .mo { color: #666666 } /* Literal.Number.Oct */ +body .sb { color: #219161 } /* Literal.String.Backtick */ +body .sc { color: #219161 } /* Literal.String.Char */ +body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */ +body .s2 { color: #219161 } /* Literal.String.Double */ +body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ +body .sh { color: #219161 } /* Literal.String.Heredoc */ +body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ +body .sx { color: #954121 } /* Literal.String.Other */ +body .sr { color: #BB6688 } /* Literal.String.Regex */ +body .s1 { color: #219161 } /* Literal.String.Single */ +body .ss { color: #19469D } /* Literal.String.Symbol */ +body .bp { color: #954121 } /* Name.Builtin.Pseudo */ +body .vc { color: #19469D } /* Name.Variable.Class */ +body .vg { color: #19469D } /* Name.Variable.Global */ +body .vi { color: #19469D } /* Name.Variable.Instance */ +body .il { color: #666666 } /* Literal.Number.Integer.Long */ \ No newline at end of file diff --git a/contrib/scripts/org-docco.org b/contrib/scripts/org-docco.org new file mode 100644 index 0000000..d846aa3 --- /dev/null +++ b/contrib/scripts/org-docco.org @@ -0,0 +1,206 @@ +#+Title: Org-Docco +#+Author: Eric Schulte +#+Style: +#+Property: tangle yes + +The =docco= tool (see http://jashkenas.github.com/docco/) generates +HTML from JavaScript source code providing an attractive side-by-side +display of source code and comments. This file (see [[http://orgmode.org/w/?p=org-mode.git;a=blob_plain;f=contrib/scripts/org-docco.org;hb=HEAD][org-docco.org]]) +generates the same type of output from Org-mode documents with code +embedded in code blocks. + +The way this works is an Org-mode document with embedded code blocks +is exported to html using the standard Org-mode export functions. +This file defines a new function named =org-docco-buffer= which, when +added to the =org-export-html-final-hook=, will be run automatically +as part of the Org-mod export process doccoizing your Org-mode +document. + +A pure source code file can be extracted (or "/tangled/") from the +Org-mode document using the normal =org-babel-tangle= function. See +[[http://orgmode.org/manual/Working-With-Source-Code.html][Working With Source Code]] chapter of the Org-mode manual for more +information on using code blocks in Org-mode files. + +*Disclaimer*: this currently only works on /very/ simple Org-mode +files which have no headings but rather are just a collection of +alternating text and code blocks. It wouldn't be difficult to +generalize the following code so that it could be run in particular +sub-trees but I simply don't have the time to do so myself, and this +version perfectly satisfies my own limit needs. I make no promises to +support this code moving forward. /Caveat Emptor/ + +#+begin_src emacs-lisp :padline no +;;; org-docco.el --- docco type html generation from Org-mode + +;; Copyright (C) 2012 Eric Schulte + +;; Author: Eric Schulte +;; Keywords: org-mode, literate programming, html +;; Homepage: http://orgmode.org/worg/org-contrib/org-mime.php +;; Version: 0.01 + +;; This file is not part of GNU Emacs. + +;;; License: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; <- look over there +#+end_src + +The =cl= package provides all of the state-changing functions used +below e.g., =push= and =incf=. It looks like a namespace-safe version +of =cl= may soon be permissible for use in official Emacs packages. +#+begin_src emacs-lisp +;;; Code: +(require 'cl) +#+end_src + +This is a function which returns the buffer positions of matching +regular expressions. It has two special features... +1. It only counts matched instances of =beg-re= and =end-re= which are + properly nested, so for example if =beg-re= and =end-re= are set to + =(= and =)= respectively and we run this against the following, + : 1 2 3 4 5 6 + : | | | | | | + : v v v v v v + : (foo (bar baz) (qux) quux) + it will return 1 and 6 rather than 1 and 3. +2. It uses [[www.gnu.org/s/emacs/manual/html_node/elisp/Markers.html][markers]] which save their position in a buffer even as the + buffer is changed (e.g., by me adding in extra HTML text). +#+begin_src emacs-lisp +(defun org-docco-balanced-re (beg-re end-re) + "Return the beginning and of a balanced regexp." + (save-excursion + (save-match-data + (let ((both-re (concat "\\(" beg-re "\\|" end-re "\\)")) + (beg-count 0) (end-count 0) + beg end) + (when (re-search-forward beg-re nil t) + (goto-char (match-beginning 0)) + (setq beg (point-marker)) + (incf beg-count) + (goto-char (match-end 0)) + (while (and (not end) (re-search-forward both-re nil t)) + (goto-char (match-beginning 0)) + (cond ((looking-at beg-re) (incf beg-count)) + ((looking-at end-re) (incf end-count)) + (:otherwise (error "miss-matched"))) + (goto-char (match-end 0)) + (when (= beg-count end-count) (setq end (point-marker)))) + (when end (cons beg end))))))) +#+end_src + +This ugly large function does the actual conversion. It wraps the +entire main content =div= of the exported Org-mode html into a single +large table. Each row of the table has documentation on the left side +and code on the right side. This function has two parts. +1. We use =(org-docco-balanced-re "")= to find the + beginning and end of the main content div. We then break up this + div at =
= boundaries with multiple calls to
+   =(org-docco-balanced-re "
")=.
+2. With all documentation/code boundaries in hand we step through the
+   buffer inserting the table html code at boundary locations.
+#+begin_src emacs-lisp
+(defun org-docco-buffer ()
+  "Call from within an HTML buffer to doccoize it."
+  (interactive)
+  (let ((table-start "\n")
+        (doc-row-start  "\n")
+        (code-row-start "    \n")
+        (table-end "
\n") (doc-row-end "\n") (code-row-end "
" ) + pair transition-points next) + (save-excursion + (save-match-data + (goto-char (point-min)) + (when (re-search-forward "
" nil t) + (goto-char (match-end 0)) + (push (point-marker) transition-points) + (goto-char (match-beginning 0)) + (setq pair (org-docco-balanced-re "")) + (while (setq next (org-docco-balanced-re "
"))
+            (goto-char (cdr next))
+            (push (car next) transition-points)
+            (push (cdr next) transition-points))
+          (goto-char (cdr pair))
+          (push (and (re-search-backward "
" nil t) (point-marker)) + transition-points) + ;; collected transitions, so build the table + (setq transition-points (nreverse transition-points)) + (goto-char (pop transition-points)) + (insert table-start doc-row-start) + (while (> (length transition-points) 1) + (goto-char (pop transition-points)) + (insert doc-row-end code-row-start) + (goto-char (pop transition-points)) + (insert code-row-end doc-row-start)) + (goto-char (pop transition-points)) + (insert code-row-end table-end) + (unless (null transition-points) + (error "leftover points"))))))) +#+end_src + +We'll use Emacs [[http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html][File Local Variables]] and the +=org-export-html-final-hook= to control which buffers have +=org-docco-buffer= run as part of their export process. +#+begin_src emacs-lisp + (defvar org-docco-doccoize-me nil + "File local variable controlling if html export should be doccoized.") + (make-local-variable 'org-docco-doccoize-me) +#+end_src + +A simple function will conditionally process HTML output based on the +value of this variable. +#+begin_src emacs-lisp + (defun org-docco-buffer-maybe () + (when org-docco-doccoize-me (org-docco-buffer))) +#+end_src + +Finally this function is added to the =org-export-html-final-hook=. +#+begin_src emacs-lisp + (add-hook 'org-export-html-final-hook #'org-docco-buffer-maybe) +#+end_src + +That's it. To use this simply; +1. Checkout this file from https://github.com/eschulte/org-docco, + : git clone git://github.com/eschulte/org-docco.git + and open it using Emacs. +2. Tangle =org-docco.el= out of this file by calling + =org-babel-tangle= or =C-c C-v t=. +3. Load the resulting Emacs Lisp file. +4. Execute the following in any Org-mode buffer to add file local + variable declarations which will enable post-processed with + =org-docco-buffer=. + : (add-file-local-variable 'org-export-html-postamble nil) + : (add-file-local-variable 'org-export-html-style-include-default nil) + : (add-file-local-variable 'org-docco-doccoize-me t) + And add the following style declaration to make use of the + =docco.css= style sheet taken directly from + https://github.com/jashkenas/docco. + : #+Style: + +#+begin_src emacs-lisp +(provide 'org-docco) +;;; org-docco.el ends here +#+end_src + +# Local Variables: +# org-export-html-postamble: nil +# org-export-html-style-include-default: nil +# org-docco-doccoize-me: t +# End: diff --git a/contrib/scripts/org2hpda b/contrib/scripts/org2hpda new file mode 100755 index 0000000..de0b573 --- /dev/null +++ b/contrib/scripts/org2hpda @@ -0,0 +1,106 @@ +# org2hpda - a small utility to generate hipster pda style printouts from org mode +# Copyright (C) 2007-2012 Christian Egli +# +# Version: 0.6 +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Commentary: +# =========== +# +# set cal-tex-diary to true so that diary entries show up in the calendar +# +# Usage: +# ====== +# +# run this makefile with +# +# make -f org2hpda +# +# The makfile will take the entries from your diary file and generate +# two PDFs containing nicely printed weekly and monthly calendars. One +# is done in the style of a pocketMod (http://www.pocketmod.com/) and +# the other is done in the style of the Hipster PDA +# (http://en.wikipedia.org/wiki/Hipster_PDA). +# +# Requirements: +# ============= +# +# the pdf* commands are part of the pdfjam package which can be found +# at http://www.warwick.ac.uk/go/pdfjam + +EMACS = emacs -batch -l ~/.emacs +LATEX = latex +DIARY = $($(EMACS) -eval "diary-file") + +# Number of weeks to be printed. Should be a multiple of 4, because 4 +# of them are merged on one page. Can be set when invoking the script +# as follows: make NUMBER_OF_WEEKS=8 -f org2hpda +NUMBER_OF_WEEKS = 4 + +hipsterFiles = weekCalendar.pdf yearCalendar.pdf monthCalendar3.pdf monthCalendar2.pdf monthCalendar1.pdf +pocketModFiles = weekCalendar.pdf yearCalendar-rotated.pdf \ + monthCalendar3-rotated.pdf monthCalendar2-rotated.pdf monthCalendar1-rotated.pdf + +all: pocketMod.pdf hipsterPDA.pdf + +%.dvi: %.tex + # Quick hack to massage the LaTeX produced by cal-tex + # quote '@', then increase font size of week calendars, + # increase font of diary entries in moth calendar and + # finally reduce links to their destination, i.e. + # change '[[http://foo][bar]]' to 'bar' + sed -e 's/\\verb|@|/\@/g' \ + -e 's/documentclass\[11pt\]/documentclass[12pt]/g' \ + -e 's/{\\tiny \\raggedright #3}/{\\small \\raggedright #3}/g' \ + -e 's/\[\[[^]]\+\]\[\([^]]\+\)\]\]/\1/g' \ + < $< > /tmp/temp-org-file.$$$$; mv /tmp/temp-org-file.$$$$ $< + $(LATEX) $^ + +%.pdf: %.dvi + dvipdf $^ + +%-rotated.pdf: %.pdf + cp $^ $@ + for n in 1 2 3; do \ + pdf90 --quiet --outfile tmp.pdf $@; mv tmp.pdf $@; \ + done + +weekCalendar.tex: $(DIARY) + $(EMACS) -eval "(progn (calendar) (cal-tex-cursor-week-iso $(NUMBER_OF_WEEKS)) (with-current-buffer cal-tex-buffer (write-file \"$@\")))" + +monthCalendar1.tex: $(DIARY) + $(EMACS) -eval "(progn (calendar) (cal-tex-cursor-month-landscape 1) (with-current-buffer cal-tex-buffer (write-file \"$@\")))" + +monthCalendar2.tex: $(DIARY) + $(EMACS) -eval "(progn (calendar) (calendar-forward-month 1) (cal-tex-cursor-month-landscape 1) (with-current-buffer cal-tex-buffer (write-file \"$@\")))" + +monthCalendar3.tex: $(DIARY) + $(EMACS) -eval "(progn (calendar) (calendar-forward-month 2) (cal-tex-cursor-month-landscape 1) (with-current-buffer cal-tex-buffer (write-file \"$@\")))" + +yearCalendar.tex: $(DIARY) + $(EMACS) -eval "(progn (calendar) (calendar-forward-month 2) (cal-tex-cursor-year-landscape 1) (with-current-buffer cal-tex-buffer (write-file \"$@\")))" + +pocketMod.pdf: $(pocketModFiles) + pdfjoin --quiet --outfile tmp.pdf $^ + pdfnup tmp.pdf --quiet --outfile $@ --nup 4x2 --frame true + +hipsterPDA.pdf: $(hipsterFiles) + pdfnup weekCalendar.pdf --quiet --outfile page1.pdf --batch --nup 2x2 --frame true --no-landscape + pdfjoin --quiet --outfile tmp.pdf monthCalendar[1-3]-rotated.pdf yearCalendar-rotated.pdf + pdfnup tmp.pdf --quiet --outfile page2.pdf --batch --nup 2x2 --frame true --no-landscape + pdfjoin --quiet --outfile $@ page1.pdf page2.pdf + +clean: + rm -rf *.aux *.dvi *.tex *.log *.pdf diff --git a/contrib/scripts/staticmathjax/.gitignore b/contrib/scripts/staticmathjax/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/contrib/scripts/staticmathjax/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/contrib/scripts/staticmathjax/README.org b/contrib/scripts/staticmathjax/README.org new file mode 100644 index 0000000..d28fc90 --- /dev/null +++ b/contrib/scripts/staticmathjax/README.org @@ -0,0 +1,79 @@ +Static MathJax v0.1 README +#+AUTHOR: Jan Böcker + +Static MathJax is a XULRunner application which loads a HTML input +file that uses MathJax into a browser, waits until MathJax is done +processing, and then writes the formatted result to an output HTML +file. + +I have only tested exports from Emacs Org-mode as input files. (As of +2010-08-14, MathJax is used by default with HTML exports in the +current Org development version.) + +Optionally, references to the math fonts used will be converted to +"data:" URIs, thus embedding the font data into the HTML file itself. +(see [[http://en.wikipedia.org/wiki/Data_URI_scheme]]) + +The code is licensed under the GNU General Public License version +2, or, at your option, any later version. + + +* Usage + To run Static MathJax, an existing XULRunner installation is + required. From the directory to which you unpacked Static MathJax, + run: + + xulrunner application.ini <--embed-fonts | --final-mathjax-url > + + + If you prefer to call "staticmathjax" instead of "xulrunner + application.ini", link xulrunner-stub into the directory: + ln /usr/lib/xulrunner-1.9.2.8/xulrunner-stub ./staticmathjax + + - input file :: + name of the input file (the result of a HTML export + from Org-mode). It is assumed that this file uses the + UTF-8 character encoding. + + - output file :: + name of the output file. + + - --embed-fonts :: + if specified, the math fonts will be embedded into + the output file using data: URIs + + - --final-mathjax-url :: + if --embed-fonts is not specified, this + must be the URL to a MathJax installation folder (e.g. "MathJax" + if MathJax is installed in a subdirectory, or + "http://orgmode.org/mathjax" to use the version hosted on the Org + website. + + All references to math fonts in the output file will point to + this directory. + +* Caveats + + The input file must not use a MathJax installation on the + web. Otherwise, due to a security feature of Firefox, MathJax will + fallback to image fonts. If you have unpacked MathJax to a + subdirectory "MathJax", specify the following in your Org file: + + #+MathJax: path:"MathJax" + + The math is rendered in Firefox, so MathJax applies its + Firefox-specific settings. When viewing the output files in other + browsers, it will look slightly different than the result that + running MathJax in that browser would produce. + + Internet Explorer does not use the correct font, because it only + supports the EOT font format. For all other browsers (including + Firefox), MathJax uses the OTF font format. + + Embedding fonts into the HTML file wastes some space due to the + base64 encoding used in data: URIs. + + I have found no way to access stdout or set an exit code in an + XULRunner app, so any code which calls Static MathJax has no idea if + processing was successful and when an error occurs, graphical + message boxes are displayed. diff --git a/contrib/scripts/staticmathjax/application.ini b/contrib/scripts/staticmathjax/application.ini new file mode 100644 index 0000000..d7957b0 --- /dev/null +++ b/contrib/scripts/staticmathjax/application.ini @@ -0,0 +1,11 @@ +[App] +Vendor=Jan Boecker +Name=StaticMathJax +Version=0.2 +BuildID=2 +Copyright=Copyright (c) 2010 Jan Boecker +ID=xulapp@jboecker.de + +[Gecko] +MinVersion=1.8 + diff --git a/contrib/scripts/staticmathjax/chrome/chrome.manifest b/contrib/scripts/staticmathjax/chrome/chrome.manifest new file mode 100644 index 0000000..a05d8c8 --- /dev/null +++ b/contrib/scripts/staticmathjax/chrome/chrome.manifest @@ -0,0 +1 @@ +content staticmathjax file:content/ diff --git a/contrib/scripts/staticmathjax/chrome/content/main.js b/contrib/scripts/staticmathjax/chrome/content/main.js new file mode 100644 index 0000000..2e71f3b --- /dev/null +++ b/contrib/scripts/staticmathjax/chrome/content/main.js @@ -0,0 +1,198 @@ +var docFrame; +var logtextbox; +var destFile; +var embedFonts = false; +var finalMathJaxURL = null; + +function log(text) +{ + logtextbox.setAttribute("value", logtextbox.getAttribute("value") + "\n" + text); +} + +function init() +{ + try { + docFrame = document.getElementById("docFrame"); + logtextbox = document.getElementById("logtextbox"); + + // parse command line arguments + var cmdLine = window.arguments[0]; + cmdLine = cmdLine.QueryInterface(Components.interfaces.nsICommandLine); + + embedFonts = cmdLine.handleFlag("embed-fonts", false); + finalMathJaxURL = cmdLine.handleFlagWithParam("final-mathjax-url", false); + + if (!embedFonts && !finalMathJaxURL) { + alert("You must eiher specify --embed-fonts or --final-mathjax-url"); + window.close(); + return; + } + + sourceFilePath = cmdLine.getArgument(0); + destFilePath = cmdLine.getArgument(1); + if ( !sourceFilePath || !destFilePath ) { + alert("Not enough parameters, expecting two arguments:\nInput file, output file"); + window.close(); + return; + } + + sourceFile = cmdLine.resolveFile(sourceFilePath); + if (! (sourceFile.exists() && sourceFile.isFile()) ) { + alert("Invalid source file path."); + window.close(); + return; + } + sourceURI = cmdLine.resolveURI(sourceFilePath); + + // create a nsIFile object for the output file + try{ + destFile = cmdLine.resolveURI(destFilePath).QueryInterface(Components.interfaces.nsIFileURL).file; + }catch(e){ + alert("Invalid destination file.\n\nException:\n" + e); + window.close(); + return; + } + + // add iframeLoaded() as an onload event handler, then navigate to the source file + docFrame.addEventListener("DOMContentLoaded", iframeLoaded, true); + docFrame.setAttribute("src", sourceURI.spec); + + } catch (e) { + alert("Error in init():\n\n" + e); + window.close(); + return; + } +} + +function iframeLoaded() +{ + /* + // print every MathJax signal to the log + docFrame.contentWindow.MathJax.Hub.Startup.signal.Interest( + function (message) {log("Startup: "+message)} + ); + docFrame.contentWindow.MathJax.Hub.signal.Interest( + function (message) {log("Hub: "+message)} + ); + */ + + // tell MathJax to call serialize() when finished + docFrame.contentWindow.MathJax.Hub.Register.StartupHook("End", function() {serialize();}); +} + +function fileURLtoDataURI(url) +{ + var ios = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var url_object = ios.newURI(url, "", null); + var file = url_object.QueryInterface(Components.interfaces.nsIFileURL).file; + + var data = ""; + var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]. + createInstance(Components.interfaces.nsIFileInputStream); + fstream.init(file, -1, -1, false); + var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]. + createInstance(Components.interfaces.nsIBinaryInputStream); + bstream.setInputStream(fstream); + + var bytes = bstream.readBytes(bstream.available()); + b64bytes = btoa(bytes); + + return "data:;base64," + b64bytes; + +} + +function serialize() +{ + var MathJaxURL = docFrame.contentWindow.MathJax.Hub.config.root; + + var searchURIList = new Array(); + var replacementURIList = new Array(); + + log("serialize: preprocessing"); + + // remove the MathJax status message window + msgdiv = docFrame.contentDocument.getElementById("MathJax_Message"); + msgdiv.parentNode.removeChild(msgdiv); + + /* Loop through all CSS rules to find all @font-face rules. + At this point, they refer to local absolute paths using file:// URLs. + Replace them either with appropriate URLs relative to finalMathJaxURL + or with data URIs. */ + + for (var i = 0; i tag + try{ + var scriptTags = docFrame.contentDocument.getElementsByTagName("script"); + for (var i=0; i + + + + +