aramk / crayon-syntax-highlighter

Syntax Highlighter supporting multiple languages, themes, fonts, highlighting from a URL, local file or post text.
https://wordpress.org/plugins/crayon-syntax-highlighter/
GNU General Public License v3.0
1.1k stars 247 forks source link

Matlab comment symbol "%" does not work when it's at the beginning of a line #340

Open yalewoo opened 8 years ago

yalewoo commented 8 years ago

1. Matlab comment symbol "%" does not work when it's at the beginning of a line Here is the test page It recognize the first "%" of the line as a TAG, and a blank line is added after that.

2. Matlab use single quotation marks to do the matrix transposition, but it is always recognized as string.

tweh commented 8 years ago

👍

Same for TeX

cminto commented 8 years ago

Confirming the same issues as yalewoo on this page. 1) % causes blank line to be added. 2) ' recognized as string rather than transpose operator.

Line 31 has: A = [-sum(k1) k2;k1(2:n+1)' -diag(k2)]; The single quote is the transpose operator and Crayon makes everything that follows green (comment) and reverts back to code after the next single quote several lines down the page. I can see that the solution has to the correct regex in this line STRING (?default) in this file: crayon-syntax-highlighter/langs/matlab/matlab.txt Can anyone offer the correct regex for this rule:

A single quotation character is a tranpose operator if it follows: right bracket ("]"), right parenthesis (")"), right brace ("}"), letter, digit, underline ("_"), punctuation mark ("."), or another single quote character ("'"). If the single quotation character follows anything else then it starts a string. Hope that helps.

cminto commented 8 years ago

Jeff Mandel has changed line 31 of the page link given in the previous post from: A = [-sum(k1) k2;k1(2:n+1)' -diag(k2)]; to: A = [-sum(k1) k2;transpose(k1(2:n+1))-diag(k2)]; which is a simple work around - the regex works fine for transpose(x) but not for x' (where everything to the right of the x' gets treated as a string up until the next '

cminto commented 8 years ago

The regex for comment in crayon-syntax-highlighter/langs/matlab/matlab.txt is: COMMENT (%.*?$) This should pick up comments with % at the beginning of the line as well as later in the line, but it doesn't (so far I'm unsuccessful in finding the reason)

cminto commented 8 years ago

Point 1 was posted earlier here: https://github.com/aramk/crayon-syntax-highlighter/issues/145 The second point above can be worked around with the transpose( ) function.