Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Statax: JavaScript Syntax Highlighter for Stata

    I have written a JavaScript Syntax Highlighter for Stata code, named Statax, as a part of the Weaver package. It accurately highlights Stata commands, functions, strings, local and global macros, and numbers, braces, operators (not on the default CSS). Also a Stata package is written to allow you simply convert your do and ado files to HTML and highlight the syntax. The package is named Statax and can be installed from SSC server.

    Code:
    ssc instal statax
    To make using the program easy, I have made it available online so that everyone can source it from my website's server. This will ensure that you will always run the most recent updated version. Although the program can be downloaded and installed manually as well. The JavaScript works as an addition to the SHJS.

    In order to include the JavaScript engine in your webpage:
    1. Add the following script to the heading of your HTML document. <script type= "text/javascript" src= 'http://haghish.com/statax/Statax.js' ></script>
    2. Next include your Stata code withing the <pre> tag and sh_stata class as shown below. for example:
    Code:
    <pre class= "sh_stata" >
    . Stata code
    . Stata code
    ... 
    <pre>
    For downloading the program and seeing examples, visit the Statax web page. http://www.haghish.com/statax/statax.php

    here is an example, using the Wrangler style:


    Click image for larger version

Name:	Wrangler.png
Views:	2
Size:	83.8 KB
ID:	1314168
    Attached Files
    Last edited by haghish; 25 Oct 2015, 05:56.
    ——————————————
    E. F. Haghish, IMBI, University of Freiburg
    [email protected]
    http://www.haghish.com/

  • #2
    Link to the Statax package web page can be found at http://www.haghish.com/statax/statax_package.php
    ——————————————
    E. F. Haghish, IMBI, University of Freiburg
    [email protected]
    http://www.haghish.com/

    Comment


    • #3
      I know I'm a bit late here, but thanks haghish this is really helpful!

      Comment


      • #4
        Thank you haghish. I have recently explored some of your packages, for example, -markdoc-, -diagram-, and here the -statax-. My question is about -statax-. When I use statax command to convert do-file to html, the resulting file does not have syntax highlight effect. Below are my codes and results (I show a screen shot of the resulting html file):
        Code:
        /*Firstly write these contents in do-file editor and save them as haghish.do;
        Secondly, use statax command to convert dofile into html*/
        
        quietly erase "`This' $Example"
        noisily do `Something' $Awesome
        forvalues num = 5/13 {
                count if vari`num' > 10
                generate x = runiform()
        }
        Code:
        statax convert using haghish.do, style(sunset) css(C:\ado\plus\s\statax.css) replace
        Click image for larger version

Name:	haghish.png
Views:	1
Size:	14.5 KB
ID:	1488697

        Comment


        • #5
          My problem in #4 rose from invalid https link of jquery.js file. I have substituted https://code.jquery.com/jquery-3.3.1.min.js for https://ajax.googleapis.com/ajax/lib.../jquery.min.js. And thus put it right. Below is my code and result.
          Code:
          /*SAVE the following code as test.do*/
          Statax JavaScript Syntax Highlighter for Stata
          Example of Statax syntax highlighter
          * Introducing Statax package!
          // JavaScript Syntax Highlighter for Stata
          
          quietly erase "`This' $Example"
          noisily do `Something' $Awesome
          forvalues num = 5/13 {
              count if vari`num' > 10
              generate x = runiform()
              margin(10)
          }
          
          /*
          E. F. Haghish
          Center for Medical Biometry and Medical Informatics
          Unersity of Freiburg, Germany
          */
          
          --------------------------------------------------------------------------------------------
          /*Codes: convert test.do to HTML and highlight the syntax*/
          statax convert using test.do, replace style(daring) css(daring.css)
          Click image for larger version

Name:	statax.png
Views:	1
Size:	48.5 KB
ID:	1489133

          Comment


          • #6
            Chen Samulsion the command you used for converting the do-file is no longer included in the package. statax is now only a JS and TeX engine, and nothing more. It seems that statax is still on SSC server... I will contact them to remove it from SSC. All my packages are only hosted on GitHub. Please see this link:

            https://github.com/haghish/statax
            ——————————————
            E. F. Haghish, IMBI, University of Freiburg
            [email protected]
            http://www.haghish.com/

            Comment


            • #7
              Thank you, haghish. I tried to apply this awesome syntax highlighter on my weebly page, but syntax highlighting only worked for IE; other browsers like chrome, edge, mobile opera displayed just plain-white-text. I tried to host Statax on both your website and my weebly page but neither worked. I cannot even guess why it goes wrong. Currently I swifted to highlight.js but Statax offers much better syntax highlighting and I would be very grateful if you could figure out the problem.

              Comment


              • #8
                Statax works fine on all browsers. But when you implement it in your site, especially if you are using a template, the JavaScripts may not be loaded correctly. This is something you have to figure out in the template of your site. Here are some information to help you:

                Statax manuscript provides a useful guide how to implement it: https://journals.sagepub.com/doi/abs...urnalCode=stja

                Statax HTML examples. You can download these HTML files and test them on your machine, using different browsers.
                https://github.com/haghish/statax/tr.../examples/HTML

                ——————————————
                E. F. Haghish, IMBI, University of Freiburg
                [email protected]
                http://www.haghish.com/

                Comment


                • #9
                  haghish I hosted all statax-related-files on my website and modified all src links in Statax.js(line #54, 58, 73) to local host and now it works. It seems that Chrome (and other browsers?) automatically disables javascripts loaded from personal websites other than the current page. Thank you for the right advice!

                  Comment

                  Working...
                  X