{ "metadata": { "name": "pandoc_test" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import os\n", "os.chdir(r\"D:\\workspace\\pandoc-citation-test\")\n", "print os.getcwd()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "D:\\workspace\\pandoc-citation-test\n" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "import pandoc\n", "pandoc.PANDOC_PATH = r'C:\\Program Files (x86)\\Pandoc\\bin\\pandoc.exe'\n", "import os.path\n", "os.path.exists(pandoc.PANDOC_PATH)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 31, "text": [ "True" ] } ], "prompt_number": 31 }, { "cell_type": "code", "collapsed": false, "input": [ "fin = open(r\"d:\\workspace\\msb\\pages\\pandoc-test.md\")\n", "text = fin.read()\n", "fin.close()\n", "print text" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "title: Pandoc test\n", "datetime: 2012-10-11 11:44:00 +2\n", "\n", "# Citation test in Markdown + Pandoc\n", "\n", "I like strawberries [@Prudhomme2006].\n", "\n", "## Section 1\n", "\n", "Oranges are cool, as noted by Rayssiguier [-@Rayssiguier1989].\n", "\n", "And of course @Hadany2003 says this is good.\n", "\n", "Bye!\n", "\n", "## References\n" ] } ], "prompt_number": 25 }, { "cell_type": "code", "collapsed": false, "input": [ "doc = pandoc.Document()\n", "dir(doc)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 33, "text": [ "['INPUT_FORMATS',\n", " 'OUTPUT_FORMATS',\n", " '__class__',\n", " '__delattr__',\n", " '__dict__',\n", " '__doc__',\n", " '__format__',\n", " '__getattribute__',\n", " '__hash__',\n", " '__init__',\n", " '__module__',\n", " '__new__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__setattr__',\n", " '__sizeof__',\n", " '__str__',\n", " '__subclasshook__',\n", " '__weakref__',\n", " '_content',\n", " '_format',\n", " '_input',\n", " '_output',\n", " '_register_formats',\n", " 'context',\n", " 'docbook',\n", " 'epub',\n", " 'html',\n", " 'html_lhs',\n", " 'latex',\n", " 'latex_lhs',\n", " 'man',\n", " 'markdown',\n", " 'markdown_lhs',\n", " 'mediawiki',\n", " 'native',\n", " 'odt',\n", " 'opendocument',\n", " 'plain',\n", " 'rst',\n", " 'rst_lhs',\n", " 'rtf',\n", " 's5',\n", " 'slidy',\n", " 'texinfo']" ] } ], "prompt_number": 33 }, { "cell_type": "code", "collapsed": false, "input": [ "doc.markdown = text\n", "print doc.html" ], "language": "python", "metadata": {}, "outputs": [ { "ename": "WindowsError", "evalue": "[Error 2] The system cannot find the file specified", "output_type": "pyerr", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mWindowsError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mdoc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmarkdown\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtext\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[0mdoc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;32mC:\\Python27\\lib\\site-packages\\pandoc\\core.pyc\u001b[0m in \u001b[0;36m\u001b[1;34m(x, fmt)\u001b[0m\n\u001b[0;32m 33\u001b[0m \u001b[0mclean_fmt\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfmt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreplace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'+'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'_'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 34\u001b[0m \t\t\tsetattr(cls, clean_fmt, property(\n\u001b[1;32m---> 35\u001b[1;33m \u001b[1;33m(\u001b[0m\u001b[1;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfmt\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfmt\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mcls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_output\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfmt\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;31m# fget\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 36\u001b[0m \t\t\t\t(lambda x, y, fmt=fmt: cls._input(x, y, fmt)))) # fset\n\u001b[0;32m 37\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32mC:\\Python27\\lib\\site-packages\\pandoc\\core.pyc\u001b[0m in \u001b[0;36m_output\u001b[1;34m(self, format)\u001b[0m\n\u001b[0;32m 46\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mPANDOC_PATH\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'--from=%s'\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_format\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'--to=%s'\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mformat\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 47\u001b[0m \u001b[0mstdin\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msubprocess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mPIPE\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 48\u001b[1;33m \u001b[0mstdout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msubprocess\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mPIPE\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mshell\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 49\u001b[0m \t\t)\n\u001b[0;32m 50\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32mC:\\Python27\\lib\\subprocess.pyc\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)\u001b[0m\n\u001b[0;32m 677\u001b[0m \u001b[0mp2cread\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mp2cwrite\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 678\u001b[0m \u001b[0mc2pread\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mc2pwrite\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 679\u001b[1;33m errread, errwrite)\n\u001b[0m\u001b[0;32m 680\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 681\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mmswindows\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32mC:\\Python27\\lib\\subprocess.pyc\u001b[0m in \u001b[0;36m_execute_child\u001b[1;34m(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)\u001b[0m\n\u001b[0;32m 894\u001b[0m \u001b[0menv\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 895\u001b[0m \u001b[0mcwd\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 896\u001b[1;33m startupinfo)\n\u001b[0m\u001b[0;32m 897\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mpywintypes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merror\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 898\u001b[0m \u001b[1;31m# Translate pywintypes.error to WindowsError, which is\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mWindowsError\u001b[0m: [Error 2] The system cannot find the file specified" ] } ], "prompt_number": 34 }, { "cell_type": "code", "collapsed": false, "input": [ "pandoc.PANDOC_PATH = r'D:\\workspace\\pandoc-citation-test\\Pandoc\\bin\\pandoc.exe'\n", "print pandoc.PANDOC_PATH\n", "os.path.exists(pandoc.PANDOC_PATH)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ " D:\\workspace\\pandoc-citation-test\\Pandoc\\bin\\pandoc.exe\n" ] }, { "output_type": "pyout", "prompt_number": 30, "text": [ "True" ] } ], "prompt_number": 30 }, { "cell_type": "code", "collapsed": false, "input": [ "pandoc.__file__" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 19, "text": [ "'C:\\\\Python27\\\\lib\\\\site-packages\\\\pandoc\\\\__init__.pyc'" ] } ], "prompt_number": 19 }, { "cell_type": "code", "collapsed": false, "input": [ "print pandoc.PANDOC_PATH" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "D:\\workspace\\pandoc-citation-test\\Pandoc\\bin\\pandoc.exe\n" ] } ], "prompt_number": 27 }, { "cell_type": "code", "collapsed": false, "input": [ "def check_if_file_exists_on_path(filename):\n", " import sys\n", " from os.path import exists\n", " if exists(filename):\n", " return filename\n", " paths = ['pandoc']\n", " paths.extend(sys.path)\n", " print paths\n", " for p in paths:\n", " if exists(p + '/' + filename):\n", " return p + '/' + filename\n", " raise IOError(\"File not found on path: %s\" % filename)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 19 }, { "cell_type": "code", "collapsed": false, "input": [ "pwd" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 11, "text": [ "u'C:\\\\Users\\\\yoavram\\\\Desktop'" ] } ], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "filename = r'd:\\library.bib'#'bdb.py'#'Voelkl.pdf'" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 16 }, { "cell_type": "code", "collapsed": false, "input": [ "check_if_file_exists_on_path(filename)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 20, "text": [ "'d:\\\\library.bib'" ] } ], "prompt_number": 20 }, { "cell_type": "code", "collapsed": false, "input": [ "import re\n", "pattern = re.compile('@\\w+\\d\\d\\d\\d')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 21 }, { "cell_type": "code", "collapsed": false, "input": [ "m=pattern.search(\"dashjdhaskjdhakjsdhaskj\")\n", "m" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 33 }, { "cell_type": "code", "collapsed": false, "input": [ "csl=\"chicago-full.csl\"\n", "csl" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 2, "text": [ "'chicago-full.csl'" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "csl[:-4]+\".abbr\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 4, "text": [ "'chicago-full.abbr'" ] } ], "prompt_number": 4 } ], "metadata": {} } ] }