-
Notifications
You must be signed in to change notification settings - Fork 334
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
Support exporting markdown cells to notebook file #1498
Support exporting markdown cells to notebook file #1498
Conversation
Should I make # %% Md
# %% Markdown |
Hello @kylebarron , thanks for the developement, this feature was wanted for a long time! Is it correct that |
I'm also working on a PR to import Notebook files into Hydrogen, and hopefully it'll be possible to import, modify, and export without any data loss. I'd love to explore a |
Very nice!
That sounds great! That will make Hydrogen the first text editor where users can act on the |
Well, not necessarily, at least not at first. I'm working on a simple PR to import just the source text. That's quite straightforward. In the short run, no outputs will be saved in import or export. I don't know enough about Hydrogen internals yet to work with output in import or export. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kylebarron this looks, good. I'm happy to add this functionality to Hydrogen.
Could you add some documentation in the readme?
return "code"; | ||
} | ||
var rowText = getRow(editor, start.row - 1); | ||
if (_.includes(rowText, "md") || _.includes(rowText, "markdown")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's OK for now.
lib/code-manager.js
Outdated
_.forEach(lines, line => { | ||
if (line.startsWith(commentStartString)) { | ||
// Remove comment from start of line | ||
editedLines.push(line.slice(commentStartString.length).trimLeft()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still allow for indentation in the markdown cell?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I don't think it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just removing .trimLeft()
isn't my favorite solution because then if a markdown cell looks like
# %% markdown
# # Header
# **bold**
# - list
# - indented list
then the text in the markdown cell in the Jupyter notebook would still have a leading space in each row, i.e.:
# Header
**bold**
- list
- indented list
I think writing with a space after the #
is clearer in the .py
file, while having a leading space on every line in the exported markdown cell is annoying.
I added code to dedent common leading whitespace for Markdown blocks, so that the above cell would be converted to
# Header
**bold**
- list
- indented list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered the tiny dependency https://github.com/sindresorhus/strip-indent, which probably has better code than mine. I added that and removed my custom code.
@@ -307,13 +307,15 @@ describe("Store", () => { | |||
expect(store.notebook).toEqual(commutable.toJS(nb)); | |||
}); | |||
|
|||
xit("should return a fully-fledged notebook when the file isn't empty", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the test had used xit()
, so I think the test was never run, especially because it would have failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was marked as expect fail intentionally because the error didn't make sense and we didn't want to hold up ci.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh that makes sense. Is the updated test ok now?
@@ -307,13 +307,15 @@ describe("Store", () => { | |||
expect(store.notebook).toEqual(commutable.toJS(nb)); | |||
}); | |||
|
|||
xit("should return a fully-fledged notebook when the file isn't empty", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test still doesn't pass, but I'm not sure why because it seems to produce the correct output when I paste the test commands into the dev console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You seem to have discovered why it was failing and made it pass, though It looks like we are testing that there is an empty cell at the top now, which seems like a bug. I know you pointed this out before, is it something to fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated that in #1505 https://github.com/nteract/hydrogen/pull/1505/files
@lgeiger It took a while but I figured out why the test wasn't passing. I think I had to activate I also added one simple test for testing that code under Maybe tomorrow I'll add some documentation. |
I'll add the WIP tag for now, but remove it when you are ready and we can merge. |
@BenRussert I added a new page in the documentation for exporting a file to a notebook. Hopefully in the future that page will also be updated for notebook import #1501 |
I also updated the breakpoints grammar so that markdown cell markers also get highlighted, at least if not using tree-sitter (#1134 (comment)) |
@BenRussert @lgeiger |
Thanks @kylebarron! |
Nice, looks like the test is correct there. Thanks for digging into that!
…On Mon, Jan 14, 2019, 2:34 PM Kyle Barron ***@***.*** wrote:
***@***.**** commented on this pull request.
------------------------------
In spec/store/index-spec.js
<#1498 (comment)>:
> @@ -307,13 +307,15 @@ describe("Store", () => {
expect(store.notebook).toEqual(commutable.toJS(nb));
});
- xit("should return a fully-fledged notebook when the file isn't empty", () => {
I updated that in #1505 <#1505>
https://github.com/nteract/hydrogen/pull/1505/files
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#1498 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AKW4cTzArOeAWb1cDczd9sBReTsKWjGCks5vDPf0gaJpZM4ZgvFD>
.
|
This adds support for Markdown cells in the
export-notebook
command (closes #1296).This requires the substring
md
ormarkdown
to be present on the cell marker line, i.e. any of the following would work correctly:Right now,
# <md>
and# <markdown>
are not supported. It wouldn't be hard to support them; I'd just have to change this regex list:hydrogen/lib/code-manager.js
Line 138 in ea00043
If there's a comment symbol as the first characters on a line, it and any left whitespace will be removed.
There's always a cell created before the first
# %%
marker, even if it's on the first line. To me that's a bug, but that should be solved in another PR.Any comments/code improvement suggestions are welcome. Hopefully this JS is a little more idiomatic than my last PR.
In Jupyter Notebook:
cc: @mwouts, @Madhu94