##// END OF EJS Templates
Merge pull request #1490 from minrk/raw...
Merge pull request #1490 from minrk/raw rename plaintext cell -> raw cell Raw cells should be *untransformed* when writing various output formats, as the point of them is to let users pass through IPython to their rendered document format (rst, latex, etc.). This is different from what is the logical meaning of 'plaintext', which would suggest that the contents should be preserved as unformatted plaintext (e.g. in a `<pre>` tag, or literal block). In the UI, these cells will be displayed as 'Raw Text'. WARNING: any existing v3 notebooks which use plaintext cells, when read in by versions after this merge, will silently rename those cells to 'raw'. But if such a notebook is uploaded into a pre-merge IPython, cells labeled as 'raw' will simply *not be displayed*.

File last commit:

r4872:34c10438
r6480:a0e0f391 merge
Show More
ipy_render.py
65 lines | 1.5 KiB | text/x-python | PythonLexer
vivainio
crlf cleanup
r680 """ IPython extension: Render templates from variables and paste to clipbard """
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
vivainio
crlf cleanup
r680
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 ip = ipapi.get()
vivainio
crlf cleanup
r680
from string import Template
import sys,os
Brian Granger
Moved Itpl.py to deathrow as we already have a copy in external.
r2031 from IPython.external.Itpl import itplns
vivainio
crlf cleanup
r680
def toclip_w32(s):
""" Places contents of s to clipboard
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 Needs pyvin32 to work:
http://sourceforge.net/projects/pywin32/
"""
import win32clipboard as cl
import win32con
cl.OpenClipboard()
cl.EmptyClipboard()
cl.SetClipboardText( s.replace('\n','\r\n' ))
cl.CloseClipboard()
try:
Bernardo B. Marques
remove all trailling spaces
r4872 import win32clipboard
vivainio
crlf cleanup
r680 toclip = toclip_w32
except ImportError:
def toclip(s): pass
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680
def render(tmpl):
""" Render a template (Itpl format) from ipython variables
Example:
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 $ import ipy_render
$ my_name = 'Bob' # %store this for convenience
$ t_submission_form = "Submission report, author: $my_name" # %store also
$ render t_submission_form
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 => returns "Submission report, author: Bob" and copies to clipboard on win32
# if template exist as a file, read it. Note: ;f hei vaan => f("hei vaan")
Bernardo B. Marques
remove all trailling spaces
r4872 $ ;render c:/templates/greeting.txt
vivainio
crlf cleanup
r680 Template examples (Ka-Ping Yee's Itpl library):
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 Here is a $string.
Here is a $module.member.
Here is an $object.member.
Here is a $functioncall(with, arguments).
Here is an ${arbitrary + expression}.
Here is an $array[3] member.
Here is a $dictionary['member'].
"""
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 if os.path.isfile(tmpl):
tmpl = open(tmpl).read()
Bernardo B. Marques
remove all trailling spaces
r4872
vivainio
crlf cleanup
r680 res = itplns(tmpl, ip.user_ns)
toclip(res)
return res
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.push('render')