Git Product home page Git Product logo

Comments (11)

kylebarron avatar kylebarron commented on May 30, 2024

Have you ever tried to use IPyStata in a non-Jupyter Notebook environment? Specifically Hydrogen, Jupyter console, or Jupyter QtConsole? Jupyter Notebook is the only one of the four that use CodeMirror for syntax highlighting (Jupyter console and Qtconsole use Pygments, and Hydrogen uses my Atom Stata syntax highlighting package). I'm not sure it's ideal for me to be serving up Javascript that those frontends won't be able to handle.

The best option would just be to add Stata syntax highlighting to the CodeMirror repository itself. Though then there would be a lag until the next release and when Jupyter Notebook uses that next release.

I can look into this a bit more in the future, but at the moment it isn't a high priority compared to making sure the package is stable.

from stata_kernel.

stevenlis avatar stevenlis commented on May 30, 2024

I've used Stata for a while just realized that "in" doesn't get highlighted in Stata's syntax?

from stata_kernel.

kylebarron avatar kylebarron commented on May 30, 2024

Highlighted where? Are you using Jupyter Notebook, Jupyter Console, or Atom? Each uses different syntax highlighters.

from stata_kernel.

stevenlis avatar stevenlis commented on May 30, 2024

The syntax doesn't get highlighted in Jupyter Lab unless I export an HTML file. nteract doesn't highlight the syntax either. It seems only Atom does so far based on your stata-language package.

from stata_kernel.

kylebarron avatar kylebarron commented on May 30, 2024

Jupyter notebook and I assume Jupyter lab and the nteract desktop app all use codemirror for syntax highlighting. Codemirror doesn't have Stata syntax highlighting yet, and I haven't taken the time to create a pr with one, though only slight modifications from the above file should be needed

from stata_kernel.

kylebarron avatar kylebarron commented on May 30, 2024

@TiesdeKok Is it OK with you if I start with your Codemirror stata.js syntax highlighting file, modify it, and submit it as a pull request to the Codemirror repository?

from stata_kernel.

kylebarron avatar kylebarron commented on May 30, 2024

@TiesdeKok In case you wanted to give some input, I'll be working on the Stata mode on my fork of the CodeMirror repo.

from stata_kernel.

TiesdeKok avatar TiesdeKok commented on May 30, 2024

Most definitely, thanks for picking that up! I will do my best to find some time to go through it at some point as well.

from stata_kernel.

kylebarron avatar kylebarron commented on May 30, 2024

I ended up starting over from scratch. There are two ways to write a syntax highlighter for codemirror, a simple way that uses regular expressions and a complex way where you do all the low level parsing yourself. R uses the complex way, so thus your fork did as well. It was much easier to start from scratch.

from stata_kernel.

kylebarron avatar kylebarron commented on May 30, 2024

@TiesdeKok In case you wanted to test it, (and have node.js installed) you can do

git clone https://github.com/kylebarron/codemirror
cd codemirror
npm install

Then open ./mode/stata/index.html in your web browser.

from stata_kernel.

kylebarron avatar kylebarron commented on May 30, 2024

I took an hour to look into it a little more... Since ipystata is a magic and not a kernel, you have to add that extra javascript in your code to register the syntax highlighting with the magic. In contrast, since stata_kernel is an actual kernel, I don't have to do give any extra javascript; if the highlighting file stata.js exists in the notebook package, then it will highlight Stata.

So even without a PR to codemirror, all I need to do is

from pkg_resources import resource_filename
path = resource_filename('notebook', 'static/components/codemirror/mode/stata/stata.js')

and then if path doesn't exist, copy the contents of stata.js there.

from stata_kernel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.