Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major but far-for-complete refactoring (stilll better to use jupytext) #97

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__
.mypy_cache
.ipynb_checkpoints
*.swp
venv
**/create_package/dist
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
*Python 2/3 and IPython 4 / Jupyter compatible!* <a href='https://travis-ci.org/aaren/wavelets'> <img src='https://secure.travis-ci.org/aaren/wavelets.png?branch=master'></a>
[Original repo](https://github.com/aaren/notedown) is dead and has only one [semialive fork](https://github.com/mli/notedown) (with changed default behavior).
This is the fork of original repo with 2 last pull request applied (#93, #96) and refactoring.

Also there is no R support.

I needed it for https://github.com/szymonmaszke/vimpyter but switched to https://github.com/goerz/jupytext.vim

---

Convert IPython Notebooks to markdown (and back)
------------------------------------------------
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions create_package/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include notedown *.tpl
21 changes: 21 additions & 0 deletions create_package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Convert IPython Notebooks to markdown (and back)

`notedown` is a simple tool to create IPython notebooks from markdown.

`notedown` separates your markdown into code and not code.
Code blocks (fenced or indented) go into input cells, everything else goes into markdown cells.


## Usage:

`notedown input.md > output.ipynb`


## Installation

`pip install notedown`


## Documentation and more info

<https://github.com/banderlog/notedown>
22 changes: 22 additions & 0 deletions create_package/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import setuptools


with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="notedown",
version="1.5.1",
author="Aaron O'Leary",
author_email='dev@aaren.me',
url='http://github.com/aaren/notedown',
license='BSD 2-Clause',
description="Convert markdown to IPython notebook.",
long_description=long_description,
long_description_content_type="text/markdown",
packages=['notedown'],
package_data={'notedown': ['*.tpl']},
install_requires=['nbformat', 'nbconvert', 'pandoc-attributes', 'jupyter'],
entry_points={'console_scripts': ['notedown = notedown.main:app', ]},
package_dir={'notedown': 'notedown'},
)
13 changes: 0 additions & 13 deletions notedown/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
from __future__ import absolute_import

from .notedown import *
from .main import convert, markdown_template, __version__

# avoid having to require the notebook to install notedown
try:
from .contentsmanager import NotedownContentsManager
from .contentsmanager import NotedownContentsManagerStripped
except ImportError:
err = 'You need to install the jupyter notebook.'
NotedownContentsManager = err
NotedownContentsManagerStripped = err
11 changes: 2 additions & 9 deletions notedown/contentsmanager.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import os

import nbformat

from tornado import web
from notebook.services.contents.filemanager import FileContentsManager

try:
import notebook.transutils
from notebook.services.contents.filemanager import FileContentsManager
except ImportError:
from IPython.html.services.contents.filemanager import FileContentsManager

from .main import ftdetect, convert
from notedown.main import ftdetect, convert


class NotedownContentsManager(FileContentsManager):
Expand Down
102 changes: 5 additions & 97 deletions notedown/main.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,17 @@
from __future__ import absolute_import
from __future__ import print_function

import os
import sys
import argparse
import pkg_resources
import io
import logging

import nbformat as nbformat
import nbformat
from nbconvert.utils.io import unicode_std_stream

from .notedown import (MarkdownReader,
MarkdownWriter,
Knitr,
run,
strip)


try:
__version__ = pkg_resources.require('notedown')[0].version

except pkg_resources.DistributionNotFound:
__version__ = 'testing'

markdown_template \
= pkg_resources.resource_filename('notedown',
'templates/markdown.tpl')
markdown_figure_template \
= pkg_resources.resource_filename('notedown',
'templates/markdown_outputs.tpl')

examples = """
Example usage of notedown
-------------------------

Convert markdown into notebook:

notedown input.md > output.ipynb

notedown input.md --output output.ipynb


Convert a notebook into markdown, with outputs intact:

notedown input.ipynb --from notebook --to markdown > output_with_outputs.md


Convert a notebook into markdown, stripping all outputs:

notedown input.ipynb --from notebook --to markdown --strip > output.md


Strip the output cells from markdown:
from notedown.notedown import MarkdownReader, MarkdownWriter, run, strip

notedown with_output_cells.md --to markdown --strip > no_output_cells.md


Convert from markdown and execute:

notedown input.md --run > executed_notebook.ipynb


Convert r-markdown into markdown:

notedown input.Rmd --to markdown --knit > output.md


Convert r-markdown into an IPython notebook:

notedown input.Rmd --knit > output.ipynb


Convert r-markdown into a notebook with the outputs computed, using
the rmagic extension to execute the code blocks:

notedown input.Rmd --knit --rmagic --run > executed_output.ipynb
"""
markdown_template = pkg_resources.resource_filename('notedown', 'templates/markdown.tpl')
markdown_figure_template = pkg_resources.resource_filename('notedown', 'templates/markdown_outputs.tpl')


def convert(content, informat, outformat, strip_outputs=False):
Expand Down Expand Up @@ -168,17 +103,6 @@ def command_line_parser():
help=("additional code to place at the start of the "
"notebook, e.g. --pre '%%matplotlib inline' "
"'import numpy as np'"))
parser.add_argument('--knit',
nargs='?',
help=("pre-process the markdown with knitr. "
"Default chunk options are 'eval=FALSE' "
"but you can change this by passing a string. "
"Requires R in your path and knitr installed."),
const='eval=FALSE')
parser.add_argument('--rmagic',
action='store_true',
help=("autoload the rmagic extension. Synonym for "
"--precode '%%load_ext rpy2.ipython'"))
parser.add_argument('--nomagic',
action='store_false',
dest='magic',
Expand All @@ -194,16 +118,12 @@ def command_line_parser():
"converted into code cells. "
"choose from 'all' (default), 'fenced', "
"'strict' or a specific language to match on"))
parser.add_argument('--examples',
help=('show example usage'),
action='store_true')
parser.add_argument('--version',
help=('print version number'),
action='store_true')
parser.add_argument('--debug',
help=('show logging output'),
action='store_true')

return parser


Expand All @@ -212,11 +132,7 @@ def main(args, help=''):
logging.basicConfig(level=logging.DEBUG)

if args.version:
print(__version__)
sys.exit()

if args.examples:
print(examples)
print(pkg_resources.require('notedown')[0].version)
sys.exit()

# if no stdin and no input file
Expand All @@ -233,14 +149,6 @@ def main(args, help=''):
else:
sys.exit('malformed input')

# pre-process markdown by using knitr on it
if args.knit:
knitr = Knitr()
input_file = knitr.knit(input_file, opts_chunk=args.knit)

if args.rmagic:
args.precode.append(r"%load_ext rpy2.ipython")

if args.render:
template_file = markdown_figure_template
else:
Expand Down
Loading