qscilexerhtml.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. // This module implements the QsciLexerHTML class.
  2. //
  3. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of QScintilla.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. #include "Qsci/qscilexerhtml.h"
  20. #include <qcolor.h>
  21. #include <qfont.h>
  22. #include <qsettings.h>
  23. #include "Qsci/qscilexerjavascript.h"
  24. #include "Qsci/qscilexerpython.h"
  25. // The ctor.
  26. QsciLexerHTML::QsciLexerHTML(QObject *parent)
  27. : QsciLexer(parent),
  28. fold_compact(true), fold_preproc(true), case_sens_tags(false),
  29. fold_script_comments(false), fold_script_heredocs(false),
  30. django_templates(false), mako_templates(false)
  31. {
  32. }
  33. // The dtor.
  34. QsciLexerHTML::~QsciLexerHTML()
  35. {
  36. }
  37. // Returns the language name.
  38. const char *QsciLexerHTML::language() const
  39. {
  40. return "HTML";
  41. }
  42. // Returns the lexer name.
  43. const char *QsciLexerHTML::lexer() const
  44. {
  45. return "hypertext";
  46. }
  47. // Return the auto-completion fillup characters.
  48. const char *QsciLexerHTML::autoCompletionFillups() const
  49. {
  50. return "/>";
  51. }
  52. // Return the string of characters that comprise a word.
  53. const char *QsciLexerHTML::wordCharacters() const
  54. {
  55. return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
  56. }
  57. // Returns the foreground colour of the text for a style.
  58. QColor QsciLexerHTML::defaultColor(int style) const
  59. {
  60. switch (style)
  61. {
  62. case Default:
  63. case JavaScriptDefault:
  64. case JavaScriptWord:
  65. case JavaScriptSymbol:
  66. case ASPJavaScriptDefault:
  67. case ASPJavaScriptWord:
  68. case ASPJavaScriptSymbol:
  69. case VBScriptDefault:
  70. case ASPVBScriptDefault:
  71. case PHPOperator:
  72. return QColor(0x00,0x00,0x00);
  73. case Tag:
  74. case XMLTagEnd:
  75. case Script:
  76. case SGMLDefault:
  77. case SGMLCommand:
  78. case VBScriptKeyword:
  79. case VBScriptIdentifier:
  80. case VBScriptUnclosedString:
  81. case ASPVBScriptKeyword:
  82. case ASPVBScriptIdentifier:
  83. case ASPVBScriptUnclosedString:
  84. return QColor(0x00,0x00,0x80);
  85. case UnknownTag:
  86. case UnknownAttribute:
  87. return QColor(0xff,0x00,0x00);
  88. case Attribute:
  89. case VBScriptNumber:
  90. case ASPVBScriptNumber:
  91. return QColor(0x00,0x80,0x80);
  92. case HTMLNumber:
  93. case JavaScriptNumber:
  94. case ASPJavaScriptNumber:
  95. case PythonNumber:
  96. case PythonFunctionMethodName:
  97. case ASPPythonNumber:
  98. case ASPPythonFunctionMethodName:
  99. return QColor(0x00,0x7f,0x7f);
  100. case HTMLDoubleQuotedString:
  101. case HTMLSingleQuotedString:
  102. case JavaScriptDoubleQuotedString:
  103. case JavaScriptSingleQuotedString:
  104. case ASPJavaScriptDoubleQuotedString:
  105. case ASPJavaScriptSingleQuotedString:
  106. case PythonDoubleQuotedString:
  107. case PythonSingleQuotedString:
  108. case ASPPythonDoubleQuotedString:
  109. case ASPPythonSingleQuotedString:
  110. case PHPKeyword:
  111. return QColor(0x7f,0x00,0x7f);
  112. case OtherInTag:
  113. case Entity:
  114. case VBScriptString:
  115. case ASPVBScriptString:
  116. return QColor(0x80,0x00,0x80);
  117. case HTMLComment:
  118. case SGMLComment:
  119. return QColor(0x80,0x80,0x00);
  120. case XMLStart:
  121. case XMLEnd:
  122. case PHPStart:
  123. case PythonClassName:
  124. case ASPPythonClassName:
  125. return QColor(0x00,0x00,0xff);
  126. case HTMLValue:
  127. return QColor(0xff,0x00,0xff);
  128. case SGMLParameter:
  129. return QColor(0x00,0x66,0x00);
  130. case SGMLDoubleQuotedString:
  131. case SGMLError:
  132. return QColor(0x80,0x00,0x00);
  133. case SGMLSingleQuotedString:
  134. return QColor(0x99,0x33,0x00);
  135. case SGMLSpecial:
  136. return QColor(0x33,0x66,0xff);
  137. case SGMLEntity:
  138. return QColor(0x33,0x33,0x33);
  139. case SGMLBlockDefault:
  140. return QColor(0x00,0x00,0x66);
  141. case JavaScriptStart:
  142. case ASPJavaScriptStart:
  143. return QColor(0x7f,0x7f,0x00);
  144. case JavaScriptComment:
  145. case JavaScriptCommentLine:
  146. case ASPJavaScriptComment:
  147. case ASPJavaScriptCommentLine:
  148. case PythonComment:
  149. case ASPPythonComment:
  150. case PHPDoubleQuotedString:
  151. return QColor(0x00,0x7f,0x00);
  152. case JavaScriptCommentDoc:
  153. return QColor(0x3f,0x70,0x3f);
  154. case JavaScriptKeyword:
  155. case ASPJavaScriptKeyword:
  156. case PythonKeyword:
  157. case ASPPythonKeyword:
  158. case PHPVariable:
  159. case PHPDoubleQuotedVariable:
  160. return QColor(0x00,0x00,0x7f);
  161. case ASPJavaScriptCommentDoc:
  162. return QColor(0x7f,0x7f,0x7f);
  163. case VBScriptComment:
  164. case ASPVBScriptComment:
  165. return QColor(0x00,0x80,0x00);
  166. case PythonStart:
  167. case PythonDefault:
  168. case ASPPythonStart:
  169. case ASPPythonDefault:
  170. return QColor(0x80,0x80,0x80);
  171. case PythonTripleSingleQuotedString:
  172. case PythonTripleDoubleQuotedString:
  173. case ASPPythonTripleSingleQuotedString:
  174. case ASPPythonTripleDoubleQuotedString:
  175. return QColor(0x7f,0x00,0x00);
  176. case PHPDefault:
  177. return QColor(0x00,0x00,0x33);
  178. case PHPSingleQuotedString:
  179. return QColor(0x00,0x9f,0x00);
  180. case PHPNumber:
  181. return QColor(0xcc,0x99,0x00);
  182. case PHPComment:
  183. return QColor(0x99,0x99,0x99);
  184. case PHPCommentLine:
  185. return QColor(0x66,0x66,0x66);
  186. }
  187. return QsciLexer::defaultColor(style);
  188. }
  189. // Returns the end-of-line fill for a style.
  190. bool QsciLexerHTML::defaultEolFill(int style) const
  191. {
  192. switch (style)
  193. {
  194. case JavaScriptDefault:
  195. case JavaScriptComment:
  196. case JavaScriptCommentDoc:
  197. case JavaScriptUnclosedString:
  198. case ASPJavaScriptDefault:
  199. case ASPJavaScriptComment:
  200. case ASPJavaScriptCommentDoc:
  201. case ASPJavaScriptUnclosedString:
  202. case VBScriptDefault:
  203. case VBScriptComment:
  204. case VBScriptNumber:
  205. case VBScriptKeyword:
  206. case VBScriptString:
  207. case VBScriptIdentifier:
  208. case VBScriptUnclosedString:
  209. case ASPVBScriptDefault:
  210. case ASPVBScriptComment:
  211. case ASPVBScriptNumber:
  212. case ASPVBScriptKeyword:
  213. case ASPVBScriptString:
  214. case ASPVBScriptIdentifier:
  215. case ASPVBScriptUnclosedString:
  216. case PythonDefault:
  217. case PythonComment:
  218. case PythonNumber:
  219. case PythonDoubleQuotedString:
  220. case PythonSingleQuotedString:
  221. case PythonKeyword:
  222. case PythonTripleSingleQuotedString:
  223. case PythonTripleDoubleQuotedString:
  224. case PythonClassName:
  225. case PythonFunctionMethodName:
  226. case PythonOperator:
  227. case PythonIdentifier:
  228. case ASPPythonDefault:
  229. case ASPPythonComment:
  230. case ASPPythonNumber:
  231. case ASPPythonDoubleQuotedString:
  232. case ASPPythonSingleQuotedString:
  233. case ASPPythonKeyword:
  234. case ASPPythonTripleSingleQuotedString:
  235. case ASPPythonTripleDoubleQuotedString:
  236. case ASPPythonClassName:
  237. case ASPPythonFunctionMethodName:
  238. case ASPPythonOperator:
  239. case ASPPythonIdentifier:
  240. case PHPDefault:
  241. return true;
  242. }
  243. return QsciLexer::defaultEolFill(style);
  244. }
  245. // Returns the font of the text for a style.
  246. QFont QsciLexerHTML::defaultFont(int style) const
  247. {
  248. QFont f;
  249. switch (style)
  250. {
  251. case Default:
  252. case Entity:
  253. #if defined(Q_OS_WIN)
  254. f = QFont("Times New Roman",11);
  255. #elif defined(Q_OS_MAC)
  256. f = QFont("Times New Roman", 12);
  257. #else
  258. f = QFont("Bitstream Charter",10);
  259. #endif
  260. break;
  261. case HTMLComment:
  262. #if defined(Q_OS_WIN)
  263. f = QFont("Verdana",9);
  264. #elif defined(Q_OS_MAC)
  265. f = QFont("Verdana", 12);
  266. #else
  267. f = QFont("Bitstream Vera Sans",8);
  268. #endif
  269. break;
  270. case SGMLCommand:
  271. case PythonKeyword:
  272. case PythonClassName:
  273. case PythonFunctionMethodName:
  274. case PythonOperator:
  275. case ASPPythonKeyword:
  276. case ASPPythonClassName:
  277. case ASPPythonFunctionMethodName:
  278. case ASPPythonOperator:
  279. f = QsciLexer::defaultFont(style);
  280. f.setBold(true);
  281. break;
  282. case JavaScriptDefault:
  283. case JavaScriptCommentDoc:
  284. case JavaScriptKeyword:
  285. case JavaScriptSymbol:
  286. case ASPJavaScriptDefault:
  287. case ASPJavaScriptCommentDoc:
  288. case ASPJavaScriptKeyword:
  289. case ASPJavaScriptSymbol:
  290. #if defined(Q_OS_WIN)
  291. f = QFont("Comic Sans MS",9);
  292. #elif defined(Q_OS_MAC)
  293. f = QFont("Comic Sans MS", 12);
  294. #else
  295. f = QFont("Bitstream Vera Serif",9);
  296. #endif
  297. f.setBold(true);
  298. break;
  299. case JavaScriptComment:
  300. case JavaScriptCommentLine:
  301. case JavaScriptNumber:
  302. case JavaScriptWord:
  303. case JavaScriptDoubleQuotedString:
  304. case JavaScriptSingleQuotedString:
  305. case ASPJavaScriptComment:
  306. case ASPJavaScriptCommentLine:
  307. case ASPJavaScriptNumber:
  308. case ASPJavaScriptWord:
  309. case ASPJavaScriptDoubleQuotedString:
  310. case ASPJavaScriptSingleQuotedString:
  311. case VBScriptComment:
  312. case ASPVBScriptComment:
  313. case PythonComment:
  314. case ASPPythonComment:
  315. case PHPComment:
  316. #if defined(Q_OS_WIN)
  317. f = QFont("Comic Sans MS",9);
  318. #elif defined(Q_OS_MAC)
  319. f = QFont("Comic Sans MS", 12);
  320. #else
  321. f = QFont("Bitstream Vera Serif",9);
  322. #endif
  323. break;
  324. case VBScriptDefault:
  325. case VBScriptNumber:
  326. case VBScriptString:
  327. case VBScriptIdentifier:
  328. case VBScriptUnclosedString:
  329. case ASPVBScriptDefault:
  330. case ASPVBScriptNumber:
  331. case ASPVBScriptString:
  332. case ASPVBScriptIdentifier:
  333. case ASPVBScriptUnclosedString:
  334. #if defined(Q_OS_WIN)
  335. f = QFont("Lucida Sans Unicode",9);
  336. #elif defined(Q_OS_MAC)
  337. f = QFont("Lucida Grande", 12);
  338. #else
  339. f = QFont("Bitstream Vera Serif",9);
  340. #endif
  341. break;
  342. case VBScriptKeyword:
  343. case ASPVBScriptKeyword:
  344. #if defined(Q_OS_WIN)
  345. f = QFont("Lucida Sans Unicode",9);
  346. #elif defined(Q_OS_MAC)
  347. f = QFont("Lucida Grande", 12);
  348. #else
  349. f = QFont("Bitstream Vera Serif",9);
  350. #endif
  351. f.setBold(true);
  352. break;
  353. case PythonDoubleQuotedString:
  354. case PythonSingleQuotedString:
  355. case ASPPythonDoubleQuotedString:
  356. case ASPPythonSingleQuotedString:
  357. #if defined(Q_OS_WIN)
  358. f = QFont("Courier New",10);
  359. #elif defined(Q_OS_MAC)
  360. f = QFont("Courier New", 12);
  361. #else
  362. f = QFont("Bitstream Vera Sans Mono",9);
  363. #endif
  364. break;
  365. case PHPKeyword:
  366. case PHPVariable:
  367. case PHPDoubleQuotedVariable:
  368. f = QsciLexer::defaultFont(style);
  369. f.setItalic(true);
  370. break;
  371. case PHPCommentLine:
  372. #if defined(Q_OS_WIN)
  373. f = QFont("Comic Sans MS",9);
  374. #elif defined(Q_OS_MAC)
  375. f = QFont("Comic Sans MS", 12);
  376. #else
  377. f = QFont("Bitstream Vera Serif",9);
  378. #endif
  379. f.setItalic(true);
  380. break;
  381. default:
  382. f = QsciLexer::defaultFont(style);
  383. }
  384. return f;
  385. }
  386. // Returns the set of keywords.
  387. const char *QsciLexerHTML::keywords(int set) const
  388. {
  389. if (set == 1)
  390. return
  391. "a abbr acronym address applet area "
  392. "b base basefont bdo big blockquote body br button "
  393. "caption center cite code col colgroup "
  394. "dd del dfn dir div dl dt "
  395. "em "
  396. "fieldset font form frame frameset "
  397. "h1 h2 h3 h4 h5 h6 head hr html "
  398. "i iframe img input ins isindex "
  399. "kbd "
  400. "label legend li link "
  401. "map menu meta "
  402. "noframes noscript "
  403. "object ol optgroup option "
  404. "p param pre "
  405. "q "
  406. "s samp script select small span strike strong style "
  407. "sub sup "
  408. "table tbody td textarea tfoot th thead title tr tt "
  409. "u ul "
  410. "var "
  411. "xml xmlns "
  412. "abbr accept-charset accept accesskey action align "
  413. "alink alt archive axis "
  414. "background bgcolor border "
  415. "cellpadding cellspacing char charoff charset checked "
  416. "cite class classid clear codebase codetype color "
  417. "cols colspan compact content coords "
  418. "data datafld dataformatas datapagesize datasrc "
  419. "datetime declare defer dir disabled "
  420. "enctype event "
  421. "face for frame frameborder "
  422. "headers height href hreflang hspace http-equiv "
  423. "id ismap label lang language leftmargin link "
  424. "longdesc "
  425. "marginwidth marginheight maxlength media method "
  426. "multiple "
  427. "name nohref noresize noshade nowrap "
  428. "object onblur onchange onclick ondblclick onfocus "
  429. "onkeydown onkeypress onkeyup onload onmousedown "
  430. "onmousemove onmouseover onmouseout onmouseup onreset "
  431. "onselect onsubmit onunload "
  432. "profile prompt "
  433. "readonly rel rev rows rowspan rules "
  434. "scheme scope selected shape size span src standby "
  435. "start style summary "
  436. "tabindex target text title topmargin type "
  437. "usemap "
  438. "valign value valuetype version vlink vspace "
  439. "width "
  440. "text password checkbox radio submit reset file "
  441. "hidden image "
  442. "public !doctype";
  443. if (set == 2)
  444. return QsciLexerJavaScript::keywordClass;
  445. if (set == 3)
  446. return
  447. // Move these to QsciLexerVisualBasic when we
  448. // get round to implementing it.
  449. "and begin case call continue do each else elseif end "
  450. "erase error event exit false for function get gosub "
  451. "goto if implement in load loop lset me mid new next "
  452. "not nothing on or property raiseevent rem resume "
  453. "return rset select set stop sub then to true unload "
  454. "until wend while with withevents attribute alias as "
  455. "boolean byref byte byval const compare currency date "
  456. "declare dim double enum explicit friend global "
  457. "integer let lib long module object option optional "
  458. "preserve private property public redim single static "
  459. "string type variant";
  460. if (set == 4)
  461. return QsciLexerPython::keywordClass;
  462. if (set == 5)
  463. return
  464. "and argv as argc break case cfunction class continue "
  465. "declare default do die "
  466. "echo else elseif empty enddeclare endfor endforeach "
  467. "endif endswitch endwhile e_all e_parse e_error "
  468. "e_warning eval exit extends "
  469. "false for foreach function global "
  470. "http_cookie_vars http_get_vars http_post_vars "
  471. "http_post_files http_env_vars http_server_vars "
  472. "if include include_once list new not null "
  473. "old_function or "
  474. "parent php_os php_self php_version print "
  475. "require require_once return "
  476. "static switch stdclass this true var xor virtual "
  477. "while "
  478. "__file__ __line__ __sleep __wakeup";
  479. if (set == 6)
  480. return "ELEMENT DOCTYPE ATTLIST ENTITY NOTATION";
  481. return 0;
  482. }
  483. // Returns the user name of a style.
  484. QString QsciLexerHTML::description(int style) const
  485. {
  486. switch (style)
  487. {
  488. case Default:
  489. return tr("HTML default");
  490. case Tag:
  491. return tr("Tag");
  492. case UnknownTag:
  493. return tr("Unknown tag");
  494. case Attribute:
  495. return tr("Attribute");
  496. case UnknownAttribute:
  497. return tr("Unknown attribute");
  498. case HTMLNumber:
  499. return tr("HTML number");
  500. case HTMLDoubleQuotedString:
  501. return tr("HTML double-quoted string");
  502. case HTMLSingleQuotedString:
  503. return tr("HTML single-quoted string");
  504. case OtherInTag:
  505. return tr("Other text in a tag");
  506. case HTMLComment:
  507. return tr("HTML comment");
  508. case Entity:
  509. return tr("Entity");
  510. case XMLTagEnd:
  511. return tr("End of a tag");
  512. case XMLStart:
  513. return tr("Start of an XML fragment");
  514. case XMLEnd:
  515. return tr("End of an XML fragment");
  516. case Script:
  517. return tr("Script tag");
  518. case ASPAtStart:
  519. return tr("Start of an ASP fragment with @");
  520. case ASPStart:
  521. return tr("Start of an ASP fragment");
  522. case CDATA:
  523. return tr("CDATA");
  524. case PHPStart:
  525. return tr("Start of a PHP fragment");
  526. case HTMLValue:
  527. return tr("Unquoted HTML value");
  528. case ASPXCComment:
  529. return tr("ASP X-Code comment");
  530. case SGMLDefault:
  531. return tr("SGML default");
  532. case SGMLCommand:
  533. return tr("SGML command");
  534. case SGMLParameter:
  535. return tr("First parameter of an SGML command");
  536. case SGMLDoubleQuotedString:
  537. return tr("SGML double-quoted string");
  538. case SGMLSingleQuotedString:
  539. return tr("SGML single-quoted string");
  540. case SGMLError:
  541. return tr("SGML error");
  542. case SGMLSpecial:
  543. return tr("SGML special entity");
  544. case SGMLComment:
  545. return tr("SGML comment");
  546. case SGMLParameterComment:
  547. return tr("First parameter comment of an SGML command");
  548. case SGMLBlockDefault:
  549. return tr("SGML block default");
  550. case JavaScriptStart:
  551. return tr("Start of a JavaScript fragment");
  552. case JavaScriptDefault:
  553. return tr("JavaScript default");
  554. case JavaScriptComment:
  555. return tr("JavaScript comment");
  556. case JavaScriptCommentLine:
  557. return tr("JavaScript line comment");
  558. case JavaScriptCommentDoc:
  559. return tr("JavaDoc style JavaScript comment");
  560. case JavaScriptNumber:
  561. return tr("JavaScript number");
  562. case JavaScriptWord:
  563. return tr("JavaScript word");
  564. case JavaScriptKeyword:
  565. return tr("JavaScript keyword");
  566. case JavaScriptDoubleQuotedString:
  567. return tr("JavaScript double-quoted string");
  568. case JavaScriptSingleQuotedString:
  569. return tr("JavaScript single-quoted string");
  570. case JavaScriptSymbol:
  571. return tr("JavaScript symbol");
  572. case JavaScriptUnclosedString:
  573. return tr("JavaScript unclosed string");
  574. case JavaScriptRegex:
  575. return tr("JavaScript regular expression");
  576. case ASPJavaScriptStart:
  577. return tr("Start of an ASP JavaScript fragment");
  578. case ASPJavaScriptDefault:
  579. return tr("ASP JavaScript default");
  580. case ASPJavaScriptComment:
  581. return tr("ASP JavaScript comment");
  582. case ASPJavaScriptCommentLine:
  583. return tr("ASP JavaScript line comment");
  584. case ASPJavaScriptCommentDoc:
  585. return tr("JavaDoc style ASP JavaScript comment");
  586. case ASPJavaScriptNumber:
  587. return tr("ASP JavaScript number");
  588. case ASPJavaScriptWord:
  589. return tr("ASP JavaScript word");
  590. case ASPJavaScriptKeyword:
  591. return tr("ASP JavaScript keyword");
  592. case ASPJavaScriptDoubleQuotedString:
  593. return tr("ASP JavaScript double-quoted string");
  594. case ASPJavaScriptSingleQuotedString:
  595. return tr("ASP JavaScript single-quoted string");
  596. case ASPJavaScriptSymbol:
  597. return tr("ASP JavaScript symbol");
  598. case ASPJavaScriptUnclosedString:
  599. return tr("ASP JavaScript unclosed string");
  600. case ASPJavaScriptRegex:
  601. return tr("ASP JavaScript regular expression");
  602. case VBScriptStart:
  603. return tr("Start of a VBScript fragment");
  604. case VBScriptDefault:
  605. return tr("VBScript default");
  606. case VBScriptComment:
  607. return tr("VBScript comment");
  608. case VBScriptNumber:
  609. return tr("VBScript number");
  610. case VBScriptKeyword:
  611. return tr("VBScript keyword");
  612. case VBScriptString:
  613. return tr("VBScript string");
  614. case VBScriptIdentifier:
  615. return tr("VBScript identifier");
  616. case VBScriptUnclosedString:
  617. return tr("VBScript unclosed string");
  618. case ASPVBScriptStart:
  619. return tr("Start of an ASP VBScript fragment");
  620. case ASPVBScriptDefault:
  621. return tr("ASP VBScript default");
  622. case ASPVBScriptComment:
  623. return tr("ASP VBScript comment");
  624. case ASPVBScriptNumber:
  625. return tr("ASP VBScript number");
  626. case ASPVBScriptKeyword:
  627. return tr("ASP VBScript keyword");
  628. case ASPVBScriptString:
  629. return tr("ASP VBScript string");
  630. case ASPVBScriptIdentifier:
  631. return tr("ASP VBScript identifier");
  632. case ASPVBScriptUnclosedString:
  633. return tr("ASP VBScript unclosed string");
  634. case PythonStart:
  635. return tr("Start of a Python fragment");
  636. case PythonDefault:
  637. return tr("Python default");
  638. case PythonComment:
  639. return tr("Python comment");
  640. case PythonNumber:
  641. return tr("Python number");
  642. case PythonDoubleQuotedString:
  643. return tr("Python double-quoted string");
  644. case PythonSingleQuotedString:
  645. return tr("Python single-quoted string");
  646. case PythonKeyword:
  647. return tr("Python keyword");
  648. case PythonTripleDoubleQuotedString:
  649. return tr("Python triple double-quoted string");
  650. case PythonTripleSingleQuotedString:
  651. return tr("Python triple single-quoted string");
  652. case PythonClassName:
  653. return tr("Python class name");
  654. case PythonFunctionMethodName:
  655. return tr("Python function or method name");
  656. case PythonOperator:
  657. return tr("Python operator");
  658. case PythonIdentifier:
  659. return tr("Python identifier");
  660. case ASPPythonStart:
  661. return tr("Start of an ASP Python fragment");
  662. case ASPPythonDefault:
  663. return tr("ASP Python default");
  664. case ASPPythonComment:
  665. return tr("ASP Python comment");
  666. case ASPPythonNumber:
  667. return tr("ASP Python number");
  668. case ASPPythonDoubleQuotedString:
  669. return tr("ASP Python double-quoted string");
  670. case ASPPythonSingleQuotedString:
  671. return tr("ASP Python single-quoted string");
  672. case ASPPythonKeyword:
  673. return tr("ASP Python keyword");
  674. case ASPPythonTripleDoubleQuotedString:
  675. return tr("ASP Python triple double-quoted string");
  676. case ASPPythonTripleSingleQuotedString:
  677. return tr("ASP Python triple single-quoted string");
  678. case ASPPythonClassName:
  679. return tr("ASP Python class name");
  680. case ASPPythonFunctionMethodName:
  681. return tr("ASP Python function or method name");
  682. case ASPPythonOperator:
  683. return tr("ASP Python operator");
  684. case ASPPythonIdentifier:
  685. return tr("ASP Python identifier");
  686. case PHPDefault:
  687. return tr("PHP default");
  688. case PHPDoubleQuotedString:
  689. return tr("PHP double-quoted string");
  690. case PHPSingleQuotedString:
  691. return tr("PHP single-quoted string");
  692. case PHPKeyword:
  693. return tr("PHP keyword");
  694. case PHPNumber:
  695. return tr("PHP number");
  696. case PHPVariable:
  697. return tr("PHP variable");
  698. case PHPComment:
  699. return tr("PHP comment");
  700. case PHPCommentLine:
  701. return tr("PHP line comment");
  702. case PHPDoubleQuotedVariable:
  703. return tr("PHP double-quoted variable");
  704. case PHPOperator:
  705. return tr("PHP operator");
  706. }
  707. return QString();
  708. }
  709. // Returns the background colour of the text for a style.
  710. QColor QsciLexerHTML::defaultPaper(int style) const
  711. {
  712. switch (style)
  713. {
  714. case ASPAtStart:
  715. return QColor(0xff,0xff,0x00);
  716. case ASPStart:
  717. case CDATA:
  718. return QColor(0xff,0xdf,0x00);
  719. case PHPStart:
  720. return QColor(0xff,0xef,0xbf);
  721. case HTMLValue:
  722. return QColor(0xff,0xef,0xff);
  723. case SGMLDefault:
  724. case SGMLCommand:
  725. case SGMLParameter:
  726. case SGMLDoubleQuotedString:
  727. case SGMLSingleQuotedString:
  728. case SGMLSpecial:
  729. case SGMLEntity:
  730. case SGMLComment:
  731. return QColor(0xef,0xef,0xff);
  732. case SGMLError:
  733. return QColor(0xff,0x66,0x66);
  734. case SGMLBlockDefault:
  735. return QColor(0xcc,0xcc,0xe0);
  736. case JavaScriptDefault:
  737. case JavaScriptComment:
  738. case JavaScriptCommentLine:
  739. case JavaScriptCommentDoc:
  740. case JavaScriptNumber:
  741. case JavaScriptWord:
  742. case JavaScriptKeyword:
  743. case JavaScriptDoubleQuotedString:
  744. case JavaScriptSingleQuotedString:
  745. case JavaScriptSymbol:
  746. return QColor(0xf0,0xf0,0xff);
  747. case JavaScriptUnclosedString:
  748. case ASPJavaScriptUnclosedString:
  749. return QColor(0xbf,0xbb,0xb0);
  750. case JavaScriptRegex:
  751. case ASPJavaScriptRegex:
  752. return QColor(0xff,0xbb,0xb0);
  753. case ASPJavaScriptDefault:
  754. case ASPJavaScriptComment:
  755. case ASPJavaScriptCommentLine:
  756. case ASPJavaScriptCommentDoc:
  757. case ASPJavaScriptNumber:
  758. case ASPJavaScriptWord:
  759. case ASPJavaScriptKeyword:
  760. case ASPJavaScriptDoubleQuotedString:
  761. case ASPJavaScriptSingleQuotedString:
  762. case ASPJavaScriptSymbol:
  763. return QColor(0xdf,0xdf,0x7f);
  764. case VBScriptDefault:
  765. case VBScriptComment:
  766. case VBScriptNumber:
  767. case VBScriptKeyword:
  768. case VBScriptString:
  769. case VBScriptIdentifier:
  770. return QColor(0xef,0xef,0xff);
  771. case VBScriptUnclosedString:
  772. case ASPVBScriptUnclosedString:
  773. return QColor(0x7f,0x7f,0xff);
  774. case ASPVBScriptDefault:
  775. case ASPVBScriptComment:
  776. case ASPVBScriptNumber:
  777. case ASPVBScriptKeyword:
  778. case ASPVBScriptString:
  779. case ASPVBScriptIdentifier:
  780. return QColor(0xcf,0xcf,0xef);
  781. case PythonDefault:
  782. case PythonComment:
  783. case PythonNumber:
  784. case PythonDoubleQuotedString:
  785. case PythonSingleQuotedString:
  786. case PythonKeyword:
  787. case PythonTripleSingleQuotedString:
  788. case PythonTripleDoubleQuotedString:
  789. case PythonClassName:
  790. case PythonFunctionMethodName:
  791. case PythonOperator:
  792. case PythonIdentifier:
  793. return QColor(0xef,0xff,0xef);
  794. case ASPPythonDefault:
  795. case ASPPythonComment:
  796. case ASPPythonNumber:
  797. case ASPPythonDoubleQuotedString:
  798. case ASPPythonSingleQuotedString:
  799. case ASPPythonKeyword:
  800. case ASPPythonTripleSingleQuotedString:
  801. case ASPPythonTripleDoubleQuotedString:
  802. case ASPPythonClassName:
  803. case ASPPythonFunctionMethodName:
  804. case ASPPythonOperator:
  805. case ASPPythonIdentifier:
  806. return QColor(0xcf,0xef,0xcf);
  807. case PHPDefault:
  808. case PHPDoubleQuotedString:
  809. case PHPSingleQuotedString:
  810. case PHPKeyword:
  811. case PHPNumber:
  812. case PHPVariable:
  813. case PHPComment:
  814. case PHPCommentLine:
  815. case PHPDoubleQuotedVariable:
  816. case PHPOperator:
  817. return QColor(0xff,0xf8,0xf8);
  818. }
  819. return QsciLexer::defaultPaper(style);
  820. }
  821. // Refresh all properties.
  822. void QsciLexerHTML::refreshProperties()
  823. {
  824. setCompactProp();
  825. setPreprocProp();
  826. setCaseSensTagsProp();
  827. setScriptCommentsProp();
  828. setScriptHeredocsProp();
  829. setDjangoProp();
  830. setMakoProp();
  831. }
  832. // Read properties from the settings.
  833. bool QsciLexerHTML::readProperties(QSettings &qs,const QString &prefix)
  834. {
  835. int rc = true;
  836. fold_compact = qs.value(prefix + "foldcompact", true).toBool();
  837. fold_preproc = qs.value(prefix + "foldpreprocessor", false).toBool();
  838. case_sens_tags = qs.value(prefix + "casesensitivetags", false).toBool();
  839. fold_script_comments = qs.value(prefix + "foldscriptcomments", false).toBool();
  840. fold_script_heredocs = qs.value(prefix + "foldscriptheredocs", false).toBool();
  841. django_templates = qs.value(prefix + "djangotemplates", false).toBool();
  842. mako_templates = qs.value(prefix + "makotemplates", false).toBool();
  843. return rc;
  844. }
  845. // Write properties to the settings.
  846. bool QsciLexerHTML::writeProperties(QSettings &qs,const QString &prefix) const
  847. {
  848. int rc = true;
  849. qs.setValue(prefix + "foldcompact", fold_compact);
  850. qs.setValue(prefix + "foldpreprocessor", fold_preproc);
  851. qs.setValue(prefix + "casesensitivetags", case_sens_tags);
  852. qs.setValue(prefix + "foldscriptcomments", fold_script_comments);
  853. qs.setValue(prefix + "foldscriptheredocs", fold_script_heredocs);
  854. qs.setValue(prefix + "djangotemplates", django_templates);
  855. qs.setValue(prefix + "makotemplates", mako_templates);
  856. return rc;
  857. }
  858. // Set if tags are case sensitive.
  859. void QsciLexerHTML::setCaseSensitiveTags(bool sens)
  860. {
  861. case_sens_tags = sens;
  862. setCaseSensTagsProp();
  863. }
  864. // Set the "html.tags.case.sensitive" property.
  865. void QsciLexerHTML::setCaseSensTagsProp()
  866. {
  867. emit propertyChanged("html.tags.case.sensitive",(case_sens_tags ? "1" : "0"));
  868. }
  869. // Set if folds are compact
  870. void QsciLexerHTML::setFoldCompact(bool fold)
  871. {
  872. fold_compact = fold;
  873. setCompactProp();
  874. }
  875. // Set the "fold.compact" property.
  876. void QsciLexerHTML::setCompactProp()
  877. {
  878. emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));
  879. }
  880. // Set if preprocessor blocks can be folded.
  881. void QsciLexerHTML::setFoldPreprocessor(bool fold)
  882. {
  883. fold_preproc = fold;
  884. setPreprocProp();
  885. }
  886. // Set the "fold.html.preprocessor" property.
  887. void QsciLexerHTML::setPreprocProp()
  888. {
  889. emit propertyChanged("fold.html.preprocessor",(fold_preproc ? "1" : "0"));
  890. }
  891. // Set if script comments can be folded.
  892. void QsciLexerHTML::setFoldScriptComments(bool fold)
  893. {
  894. fold_script_comments = fold;
  895. setScriptCommentsProp();
  896. }
  897. // Set the "fold.hypertext.comment" property.
  898. void QsciLexerHTML::setScriptCommentsProp()
  899. {
  900. emit propertyChanged("fold.hypertext.comment",(fold_script_comments ? "1" : "0"));
  901. }
  902. // Set if script heredocs can be folded.
  903. void QsciLexerHTML::setFoldScriptHeredocs(bool fold)
  904. {
  905. fold_script_heredocs = fold;
  906. setScriptHeredocsProp();
  907. }
  908. // Set the "fold.hypertext.heredoc" property.
  909. void QsciLexerHTML::setScriptHeredocsProp()
  910. {
  911. emit propertyChanged("fold.hypertext.heredoc",(fold_script_heredocs ? "1" : "0"));
  912. }
  913. // Set if Django templates are supported.
  914. void QsciLexerHTML::setDjangoTemplates(bool enable)
  915. {
  916. django_templates = enable;
  917. setDjangoProp();
  918. }
  919. // Set the "lexer.html.django" property.
  920. void QsciLexerHTML::setDjangoProp()
  921. {
  922. emit propertyChanged("lexer.html.django", (django_templates ? "1" : "0"));
  923. }
  924. // Set if Mako templates are supported.
  925. void QsciLexerHTML::setMakoTemplates(bool enable)
  926. {
  927. mako_templates = enable;
  928. setMakoProp();
  929. }
  930. // Set the "lexer.html.mako" property.
  931. void QsciLexerHTML::setMakoProp()
  932. {
  933. emit propertyChanged("lexer.html.mako", (mako_templates ? "1" : "0"));
  934. }