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

Blanks on the left are removed (in the markdown portion) when exporting .py to .ipynb (jupyter) #3666

Closed
dem108 opened this issue Jan 17, 2019 · 0 comments
Assignees

Comments

@dem108
Copy link
Member

dem108 commented Jan 17, 2019

Environment data

  • VS Code version: 1.30.2
  • Extension version (available under the Extensions sidebar): 2018.12.1
  • OS and version: Windows_NT x64 10.0.17134
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.8
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: none

Expected behaviour

When I export a .py file (which is imported from an .ipynb) to a .ipynb, the new Jupyter notebook should be the same as the original. Especially the markdown portion should not break.

Actual behaviour

Markdown portion breaks because the blanks on the left of each line are removed when exporting .py to .ipynb.

Steps to reproduce:

  1. import a notebook from vscode. Import is okay.
{
  "cells": [
    {
      "metadata": {
        "collapsed": true
      },
      "cell_type": "markdown",
      "source": "# Simple Notebook to replicate the issue\n\n## Issue\nWhen export .py with #%% markdown blocks, blanks on the left of each line are removed, breaking the intended markdown format.\n"
    },
    {
      "metadata": {},
      "cell_type": "markdown",
      "source": "## Block of Interest\n\n### Take a look\n\n\n  1. Item 1\n\n    - Item 1-a\n      1. Item 1-a-1\n         - Item 1-a-1-a\n         - Item 1-a-1-b\n      2. Item 1-a-2\n         - Item 1-a-2-a\n         - Item 1-a-2-b\n      3. Item 1-a-3\n         - Item 1-a-3-a\n         - Item 1-a-3-b\n         - Item 1-a-3-c\n\n  2. Item 2"
    }
  ],
  "metadata": {
    "kernelspec": {
      "name": "python36",
      "display_name": "Python 3.6",
      "language": "python"
    },
    "language_info": {
      "mimetype": "text/x-python",
      "nbconvert_exporter": "python",
      "name": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.6",
      "file_extension": ".py",
      "codemirror_mode": {
        "version": 3,
        "name": "ipython"
      }
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}

01-snapshot-notebook

02-snapshot-imported-py

  1. Export the imported .py to .ipynb. The blanks are removed on the left of each line, breaking the intended format.

03-snapshot-exported-ipynb

04-snapshot-exported-ipynb2

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

You can try exporting below Python script for replication.

#%% [markdown]
# # Simple Notebook to replicate the issue
# 
# ## Issue
# When export .py with #%% markdown blocks, blanks on the left of each line are removed, breaking the intended markdown format.
# 
#%% [markdown]
# ## Block of Interest
# 
# ### Take a look
# 
# 
#   1. Item 1
# 
#     - Item 1-a
#       1. Item 1-a-1
#          - Item 1-a-1-a
#          - Item 1-a-1-b
#       2. Item 1-a-2
#          - Item 1-a-2-a
#          - Item 1-a-2-b
#       3. Item 1-a-3
#          - Item 1-a-3-a
#          - Item 1-a-3-b
#          - Item 1-a-3-c
# 
#   2. Item 2

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

N/A

@rchiodo rchiodo self-assigned this Mar 29, 2019
@rchiodo rchiodo closed this as completed Apr 24, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 22, 2019
@microsoft microsoft unlocked this conversation Nov 14, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants