项目作者: amroamroamro

项目描述 :
MATLAB syntax highlighting for google-code-prettify
高级语言: JavaScript
项目地址: git://github.com/amroamroamro/prettify-matlab.git
创建时间: 2012-05-02T18:43:35Z
项目社区:https://github.com/amroamroamro/prettify-matlab

开源协议:MIT License

下载


MATLAB syntax highlighting for Google Code Prettify

Build Status
Build Status
devDependency Status
Built with Grunt
License

An implementation of MATLAB syntax highlighting for google-code-prettify.

The following constructs are recognized:

  • single line and block comments (% comment and %{,%})
  • quoted string ('hello world')
  • number literals (1, -2.5, 1i, 2.9E-5, etc…)
  • shell escape (!touch filename)
  • line continuation (...)
  • transpose operator (x' and x.')
  • command prompt (>> now)
  • error/warning messages (??? Error in ... and Warning: ...)
  • parentheses, brackets, braces ((), [], {})
  • other operators (<>=~@&;,:!-+*^.|\/)
  • MATLAB language keywords (if, else, end, etc…)
  • some special variables and constants (inf, nan, varargin, etc..)
  • user-defined indentifiers (function and variable names not matched in
    previous steps)

The “full” version also adds highlighting for MATLAB functions:

(Since this increases the resulting script size, a separate “lite” version is
also available which excludes function names detection)
.

The project was inspired by the similar Mathematica.SE syntax
highlighter.

Build

Requirements: Node.js and the NPM package manager.

To rebuild the project, run the following in the command line:

  1. $ cd prettify-matlab
  2. $ npm install
  3. $ npm run build
  4. # (optional) run unit tests
  5. $ npm test

First this will install build dependencies, then generate the output
javascript and stylesheet files in the dist directory using the
source templates from the src directory.

  1. dist/
  2. |
  3. |-- js/
  4. | |-- full/
  5. | | |-- lang-matlab.js # code-prettify extension (full version)
  6. | | |-- lang-matlab.min.js # and minified version
  7. | |
  8. | |-- lite/
  9. | |-- lang-matlab.js # code-prettify extension (lite version)
  10. | |-- lang-matlab.min.js # and minified version
  11. |
  12. |-- css/
  13. | |-- matlab.css # optional skin for code-prettify
  14. | |-- matlab.min.css # and minified version
  15. |
  16. |-- userscripts/
  17. |-- prettify-matlab.user.js # userscripts for
  18. |-- switch-lang.user.js # Stack Overflow
  19. |-- prettify-mathworks-answers.user.js # userscripts for
  20. |-- prettify-mathworks-fileexchange.user.js # various MathWorks
  21. |-- prettify-mathworks-examples.user.js # websites

Usage: Extension

Version Source
Full Source
Lite Source

To apply the MALTAB syntax highlighting on code snippets in your own web
pages, first include the prettify scripts and stylesheets in your document (as
explained in the code-prettify project documentation). Next include the
MATLAB language extension, and place your
source code inside a preformatted HTML tag as follows:

  1. <html>
  2. <head>
  3. <title>MATLAB</title>
  4. <link rel="stylesheet" type="text/css" href="prettify.css" />
  5. <script src="prettify.js"></script>
  6. <script src="lang-matlab.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-matlab">
  10. % example code
  11. x = [1, 2, 3]';
  12. fprintf('sum(x^2) = %f\n', sum(x.^2));
  13. </pre>
  14. </body>
  15. </html>

When PR.prettyPrint() is called, marked sections will be pretty-printed, and
the default styles will be applied. You can customize them with your own, or
use the provided stylesheet which has a color scheme
inspired by that of the MATLAB IDE (with some modifications).

See the demo page for a demonstration.

UPDATE: The MATLAB extension is now integrated upstream in
google/code-prettify. So you can use the auto-loader to directly
load both code-prettify along with the MATLAB extension via one URL:

  1. <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?lang=matlab"></script>

Usage: Userscripts

For instructions on installing userscripts for various browsers, see
this page. Also check out the wiki for sample screenshots.

Stack Overflow

Apply MATLAB syntax highlighting on Stack Overflow and other
Stack Exchange sites. The script is only activated on questions tagged as
matlab.

Source
Install

In addition, a separate userscript is included to allow switching the language
used by the prettifier. It adds a small button to the top-right corner of each
code block, with an attached drop-down menu to allow language selection.

Source
Install

UPDATE: Stack Overflow recently integrated MATLAB syntax support, so you
should get proper syntax highlighting by default. This userscript is still
useful if you want to get full highlighting for function names as well as the
customized stylesheet which applies colors resembling the MATLAB editor.

MathWorks MATLAB Answers

Apply MATLAB syntax highlighting on MATLAB Answers.

Source
Install

MathWorks File Exchange

Apply MATLAB syntax highlighting on File Exchange.

Source
Install

MathWorks MATLAB Examples

Apply MATLAB syntax highlighting on MATLAB Examples.

Source
Install

License

Project released under the MIT License.