File: ThemeImporterMarkdown.cpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,204 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (84 lines) | stat: -rw-r--r-- 3,676 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "ThemeImporterMarkdown.hpp"

#include "ColoursAndFontsManager.h"
#include "cl_standard_paths.h"
#include "fileutils.h"
#include "globals.h"
#include "xmlutils.h"

#include <wx/dir.h>
#include <wx/stc/stc.h>

ThemeImporterMarkdown::ThemeImporterMarkdown()
{
    // Preprocessor definitions (we are going to use it for functions)
    SetFileExtensions("*.md;README");
}

ThemeImporterMarkdown::~ThemeImporterMarkdown() {}

LexerConf::Ptr_t ThemeImporterMarkdown::Import(const wxFileName& theme_file)
{
    LexerConf::Ptr_t lexer = InitializeImport(theme_file, "markdown", wxSTC_LEX_MARKDOWN);
    CHECK_PTR_RET_NULL(lexer);

    // Covnert to codelite's XML properties
    AddProperty(lexer, wxSTC_MARKDOWN_DEFAULT, "Default", m_editor);
    AddProperty(lexer, wxSTC_MARKDOWN_LINE_BEGIN, "Start of line", m_editor);
    AddProperty(lexer, wxSTC_MARKDOWN_STRONG1, "Strong 1", m_editor);
    AddProperty(lexer, wxSTC_MARKDOWN_STRONG2, "Strong 2", m_editor);
    AddProperty(lexer, wxSTC_MARKDOWN_EM1, "Emphasis 1", m_editor);
    AddProperty(lexer, wxSTC_MARKDOWN_EM2, "Emphasis 2", m_editor);
    AddProperty(lexer, wxSTC_MARKDOWN_HEADER1, "Header 1", m_klass);
    AddProperty(lexer, wxSTC_MARKDOWN_HEADER2, "Header 2", m_klass);
    AddProperty(lexer, wxSTC_MARKDOWN_HEADER3, "Header 3", m_klass);
    AddProperty(lexer, wxSTC_MARKDOWN_HEADER4, "Header 4", m_klass);
    AddProperty(lexer, wxSTC_MARKDOWN_HEADER5, "Header 5", m_klass);
    AddProperty(lexer, wxSTC_MARKDOWN_HEADER6, "Header 6", m_klass);
    AddProperty(lexer, wxSTC_MARKDOWN_PRECHAR, "Prechar", m_editor);
    AddProperty(lexer, wxSTC_MARKDOWN_ULIST_ITEM, "Unordered List Item", m_klass);
    AddProperty(lexer, wxSTC_MARKDOWN_OLIST_ITEM, "Ordered List Item", m_klass);
    AddProperty(lexer, wxSTC_MARKDOWN_BLOCKQUOTE, "Block Quote", m_multiLineComment);
    AddProperty(lexer, wxSTC_MARKDOWN_STRIKEOUT, "Strike out", m_singleLineComment);
    AddProperty(lexer, wxSTC_MARKDOWN_HRULE, "Hrule", m_number);
    AddProperty(lexer, wxSTC_MARKDOWN_LINK, "Link", m_variable);
    AddProperty(lexer, wxSTC_MARKDOWN_CODE, "Code", m_function);
    AddProperty(lexer, wxSTC_MARKDOWN_CODE2, "Code2", m_editor);
    AddProperty(lexer, wxSTC_MARKDOWN_CODEBK, "Code Block", m_editor);

    // bold font
    const std::vector<int> emphasis = { wxSTC_MARKDOWN_STRONG1, wxSTC_MARKDOWN_STRONG2, wxSTC_MARKDOWN_EM1,
                                        wxSTC_MARKDOWN_EM2 };
    for(auto state : emphasis) {
        auto& prop = lexer->GetProperty(state);
        prop.SetBold(true);
    }

    auto& prop_link = lexer->GetProperty(wxSTC_MARKDOWN_LINK);
    prop_link.SetUnderlined(true);
    prop_link.SetItalic(true);

    // headings
    const std::vector<int> headings = { wxSTC_MARKDOWN_HEADER1, wxSTC_MARKDOWN_HEADER2, wxSTC_MARKDOWN_HEADER3,
                                        wxSTC_MARKDOWN_HEADER4, wxSTC_MARKDOWN_HEADER5, wxSTC_MARKDOWN_HEADER6 };

    for(auto state : headings) {
        auto& prop_heading = lexer->GetProperty(state);
        prop_heading.SetBold(true);
        prop_heading.SetEolFilled(true);
    }

    // code style
    const std::vector<int> codes = { wxSTC_MARKDOWN_CODE2, wxSTC_MARKDOWN_CODE, wxSTC_MARKDOWN_CODEBK };
    bool is_dark = lexer->IsDark();
    for(auto state : codes) {
        auto& prop_code = lexer->GetProperty(state);
        // use different background colour for code sections
        wxColour code_bg_colour = wxColour(prop_code.GetBgColour()).ChangeLightness(is_dark ? 110 : 90);
        prop_code.SetBgColour(code_bg_colour.GetAsString(wxC2S_HTML_SYNTAX));
        prop_code.SetEolFilled(true);
    }

    FinalizeImport(lexer);
    return lexer;
}