qscilexermarkdown.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // This module implements the QsciLexerMarkdown 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/qscilexermarkdown.h"
  20. #include <qfont.h>
  21. // The ctor.
  22. QsciLexerMarkdown::QsciLexerMarkdown(QObject *parent)
  23. : QsciLexer(parent)
  24. {
  25. }
  26. // The dtor.
  27. QsciLexerMarkdown::~QsciLexerMarkdown()
  28. {
  29. }
  30. // Returns the language name.
  31. const char *QsciLexerMarkdown::language() const
  32. {
  33. return "Markdown";
  34. }
  35. // Returns the lexer name.
  36. const char *QsciLexerMarkdown::lexer() const
  37. {
  38. return "markdown";
  39. }
  40. // Returns the foreground colour of the text for a style.
  41. QColor QsciLexerMarkdown::defaultColor(int style) const
  42. {
  43. switch (style)
  44. {
  45. case Special:
  46. return QColor(0xcc, 0x00, 0xff);
  47. case StrongEmphasisAsterisks:
  48. case StrongEmphasisUnderscores:
  49. return QColor(0x22, 0x44, 0x66);
  50. case EmphasisAsterisks:
  51. case EmphasisUnderscores:
  52. return QColor(0x88, 0x00, 0x88);
  53. case Header1:
  54. return QColor(0xff, 0x77, 0x00);
  55. case Header2:
  56. return QColor(0xdd, 0x66, 0x00);
  57. case Header3:
  58. return QColor(0xbb, 0x55, 0x00);
  59. case Header4:
  60. return QColor(0x99, 0x44, 0x00);
  61. case Header5:
  62. return QColor(0x77, 0x33, 0x00);
  63. case Header6:
  64. return QColor(0x55, 0x22, 0x00);
  65. case Prechar:
  66. return QColor(0x00, 0x00, 0x00);
  67. case UnorderedListItem:
  68. return QColor(0x82, 0x5d, 0x00);
  69. case OrderedListItem:
  70. return QColor(0x00, 0x00, 0x70);
  71. case BlockQuote:
  72. return QColor(0x00, 0x66, 0x00);
  73. case StrikeOut:
  74. return QColor(0xdd, 0xdd, 0xdd);
  75. case HorizontalRule:
  76. return QColor(0x1f, 0x1c, 0x1b);
  77. case Link:
  78. return QColor(0x00, 0x00, 0xaa);
  79. case CodeBackticks:
  80. case CodeDoubleBackticks:
  81. return QColor(0x7f, 0x00, 0x7f);
  82. case CodeBlock:
  83. return QColor(0x00, 0x45, 0x8a);
  84. }
  85. return QsciLexer::defaultColor(style);
  86. }
  87. // Returns the font of the text for a style.
  88. QFont QsciLexerMarkdown::defaultFont(int style) const
  89. {
  90. QFont f;
  91. switch (style)
  92. {
  93. case StrongEmphasisAsterisks:
  94. case StrongEmphasisUnderscores:
  95. f = QsciLexer::defaultFont(style);
  96. f.setBold(true);
  97. break;
  98. case EmphasisAsterisks:
  99. case EmphasisUnderscores:
  100. f = QsciLexer::defaultFont(style);
  101. f.setItalic(true);
  102. break;
  103. case Header1:
  104. case Header2:
  105. case Header3:
  106. case Header4:
  107. case Header5:
  108. case Header6:
  109. #if defined(Q_OS_WIN)
  110. f = QFont("Courier New", 10);
  111. #elif defined(Q_OS_MAC)
  112. f = QFont("Courier", 12);
  113. #else
  114. f = QFont("Bitstream Vera Sans Mono", 9);
  115. #endif
  116. f.setBold(true);
  117. break;
  118. case HorizontalRule:
  119. case CodeBackticks:
  120. case CodeDoubleBackticks:
  121. case CodeBlock:
  122. #if defined(Q_OS_WIN)
  123. f = QFont("Courier New", 10);
  124. #elif defined(Q_OS_MAC)
  125. f = QFont("Courier", 12);
  126. #else
  127. f = QFont("Bitstream Vera Sans Mono", 9);
  128. #endif
  129. break;
  130. case Link:
  131. f = QsciLexer::defaultFont(style);
  132. f.setUnderline(true);
  133. break;
  134. default:
  135. f = QsciLexer::defaultFont(style);
  136. }
  137. return f;
  138. }
  139. // Returns the background colour of the text for a style.
  140. QColor QsciLexerMarkdown::defaultPaper(int style) const
  141. {
  142. switch (style)
  143. {
  144. case Prechar:
  145. return QColor(0xee, 0xee, 0xaa);
  146. case UnorderedListItem:
  147. return QColor(0xde, 0xd8, 0xc3);
  148. case OrderedListItem:
  149. return QColor(0xb8, 0xc3, 0xe1);
  150. case BlockQuote:
  151. return QColor(0xcb, 0xdc, 0xcb);
  152. case StrikeOut:
  153. return QColor(0xaa, 0x00, 0x00);
  154. case HorizontalRule:
  155. return QColor(0xe7, 0xd1, 0xc9);
  156. case CodeBackticks:
  157. case CodeDoubleBackticks:
  158. return QColor(0xef, 0xff, 0xef);
  159. case CodeBlock:
  160. return QColor(0xc5, 0xe0, 0xf5);
  161. }
  162. return QsciLexer::defaultPaper(style);
  163. }
  164. // Returns the user name of a style.
  165. QString QsciLexerMarkdown::description(int style) const
  166. {
  167. switch (style)
  168. {
  169. case Default:
  170. return tr("Default");
  171. case Special:
  172. return tr("Special");
  173. case StrongEmphasisAsterisks:
  174. return tr("Strong emphasis using double asterisks");
  175. case StrongEmphasisUnderscores:
  176. return tr("Strong emphasis using double underscores");
  177. case EmphasisAsterisks:
  178. return tr("Emphasis using single asterisks");
  179. case EmphasisUnderscores:
  180. return tr("Emphasis using single underscores");
  181. case Header1:
  182. return tr("Level 1 header");
  183. case Header2:
  184. return tr("Level 2 header");
  185. case Header3:
  186. return tr("Level 3 header");
  187. case Header4:
  188. return tr("Level 4 header");
  189. case Header5:
  190. return tr("Level 5 header");
  191. case Header6:
  192. return tr("Level 6 header");
  193. case Prechar:
  194. return tr("Pre-char");
  195. case UnorderedListItem:
  196. return tr("Unordered list item");
  197. case OrderedListItem:
  198. return tr("Ordered list item");
  199. case BlockQuote:
  200. return tr("Block quote");
  201. case StrikeOut:
  202. return tr("Strike out");
  203. case HorizontalRule:
  204. return tr("Horizontal rule");
  205. case Link:
  206. return tr("Link");
  207. case CodeBackticks:
  208. return tr("Code between backticks");
  209. case CodeDoubleBackticks:
  210. return tr("Code between double backticks");
  211. case CodeBlock:
  212. return tr("Code block");
  213. }
  214. return QString();
  215. }