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

Improving the text editor for live cells w/ CodeMirror #95

Closed
choldgraf opened this issue Jan 5, 2019 · 10 comments
Closed

Improving the text editor for live cells w/ CodeMirror #95

choldgraf opened this issue Jan 5, 2019 · 10 comments

Comments

@choldgraf
Copy link
Collaborator

A nice feature of the Juniper package is that it replaces code cells with CodeMirror cells that have syntax highlighting, themeing, etc. It seems that the code they use for creating codemirror cells is here:

https://github.com/ines/juniper/blob/master/src/index.js#L135

Just flagging this in case it's in-scope and would be of value to thebelab

@nthiery
Copy link
Collaborator

nthiery commented Jan 5, 2019

Thanks for the pointer; I had not seen Juniper on my radar. In ines/juniper#2, I asked about a potential Juniper/Thebelab convergence.

@choldgraf
Copy link
Collaborator Author

I think a convergence would be great - my feeling w/ that project is that they liked thebelab's experience, wanted something slightly different for a specific use-case, and also wanted an excuse to learn a bit about the lab API, so perhaps they'd be open to working together a bit. It does seem like there's a lot of overlap

@minrk
Copy link
Collaborator

minrk commented Jan 7, 2019

I'm a little confused. thebelab also creates CodeMirror instances for cells with syntax highlighting, etc.. Is the issue about what CodeMirror options are enabled or not?

@choldgraf
Copy link
Collaborator Author

oh interesting, I am confused as well then :-) For some reason when I launch thebelab I don't have any kind of syntax highlighting, so I assumed it wasn't using codemirror. Perhaps I am invoking it wrong?

@minrk
Copy link
Collaborator

minrk commented Jan 8, 2019

It could certainly be something wrong in thebelab not setting itself up right. Where is this happening? Do you see any errors in the js console? What's the highlight language?

@choldgraf
Copy link
Collaborator Author

for an example see here: https://predictablynoisy.com/jupyter-book/features/notebooks

(click the "thebelab" button)

@Miniland1333
Copy link
Contributor

Miniland1333 commented Jan 10, 2019

Could it be that you aren't adding a data-language attribute to your code cells? This was an issue I ran into when I was using Thebelab for the first time and swapping languages for testing.
In the thebelab examples, it has a data-language attribute in order to indicate what syntax highlighter to use:
<pre data-executable="true" data-language="python">print("Hello!")</pre>

Based on the source code of that page, I would recommend adding code around line 169 of the notebooks.html file to correct this issue!

// Find all code cells, replace with Thebelab interactive code cells
const codeCells = document.querySelectorAll('.input_area pre')
codeCells.forEach((codeCell, index) => {
       const id = codeCellId(index)
       codeCell.setAttribute('data-executable', '')
       codeCell.setAttribute('data-language', 'python') //added line
});

@choldgraf
Copy link
Collaborator Author

This totally fixed my problem @Miniland1333 , thanks for letting me know :-)

@slel
Copy link

slel commented Jan 15, 2019

Should there be a word about that on Thebelab's homepage?

@choldgraf
Copy link
Collaborator Author

@slel I added in a short mention of this in #100 though that documentation hasn't gone live yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants