Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 31addf6

Browse files
author
Henrik Holst
committedMay 6, 2014
Added ruby example.
1 parent 1b67830 commit 31addf6

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed
 

‎README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
pandoc octave filter
2-
====================
1+
pandoc codeblock filters
2+
========================
33

4-
This is an example of [Pandoc] filters and [loginteractive].
4+
This is an example of [Pandoc] filters and [loginteractive] for logging
5+
interactive programs as if they where executed from a terminal.
56

6-
Octave
7+
## Octave
78

89
~~~ { .octave .interactive }
9-
A = rand(4,4)
10+
A = reshape(1:4,[2 2])
1011
v = eig(A)
1112
~~~
1213

13-
Python
14+
## Python
1415

1516
~~~ { .python .interactive }
1617
def isPrime(n):
@@ -25,6 +26,15 @@ for n in range(2,100):
2526
if isPrime(n):
2627
print n,
2728
~~~
29+
## Ruby
30+
31+
~~~ { .ruby .interactive }
32+
def factorial(n)
33+
return 1 if n <= 1
34+
return n * factorial(n - 1)
35+
end
36+
factorial(20)
37+
~~~
2838

2939
[Pandoc]: http://johnmacfarlane.net/pandoc/
3040
[loginteractive]: https://github.com/hholst80/loginteractive

‎README.pdf

-66.2 KB
Binary file not shown.

‎pandoc_codeblock_interactive.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ def codeblock_interactive(key, value, format, meta):
2020
elif 'python' in options and 'interactive' in options:
2121
prg = 'python'
2222
cmd = 'env LD_PRELOAD=./loginteractive.so STDIN=stdin.txt STDOUT=stdout.txt python -i > /dev/null'
23+
elif 'ruby' in options and 'interactive' in options:
24+
prg = 'ruby'
25+
cmd = 'env LD_PRELOAD=./loginteractive.so STDIN=stdin.txt STDOUT=stdout.txt irb --simple-prompt > /dev/null'
2326
if prg and cmd:
2427
f = file('stdin.txt','w')
2528
f.write(text)
2629
f.close()
2730
subprocess.call(cmd, shell=True, bufsize=1)
2831
f = open('stdout.txt','r')
29-
text = "\n".join(f.read().split("\n")[0:-1])
32+
text = f.read().split("\n")
33+
if len(text[-1]) == 0:
34+
text = "\n".join(text[0:-2])
35+
else: # no ending line feed.
36+
text = "\n".join(text[0:-1])
3037
f.close()
3138
return CodeBlock(("",[prg, "interactive"],[]),text)
3239

‎run_example.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/sh
2-
pandoc -t json < README.md | ./pandoc_codeblock_interactive.py | pandoc -f json -o README.pdf
2+
#pandoc -t json < README.md | ./pandoc_codeblock_interactive.py | pandoc -N --variable mainfont=Georgia --variable sansfont=Arial --variable monofont="Bitstream Vera Sans Mono Bold" --variable fontsize=12pt --variable version=1.10 -f json --latex-engine=xelatex --toc -o README.pdf
3+
pandoc -t json < README.md | ./pandoc_codeblock_interactive.py | pandoc -N --variable mainfont=Georgia --variable sansfont=Arial --variable monofont="Inconsolata" --variable fontsize=12pt --variable version=1.10 -f json --latex-engine=xelatex --toc -o README.pdf

0 commit comments

Comments
 (0)
Please sign in to comment.