:github_url: hide .. _class_CodeHighlighter: CodeHighlighter =============== **繼承:** :ref:`SyntaxHighlighter` **<** :ref:`Resource` **<** :ref:`RefCounted` **<** :ref:`Object` 用於程式碼的語法高亮器。 .. rst-class:: classref-introduction-group 說明 ---- 通過調整該資源的各種屬性,可以更改 :ref:`TextEdit` 控制項內的字串、注釋、數位、和其他文字圖案的顏色。 .. rst-class:: classref-reftable-group 屬性 ---- .. table:: :widths: auto +-------------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Dictionary` | :ref:`color_regions` | ``{}`` | +-------------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Color` | :ref:`function_color` | ``Color(0, 0, 0, 1)`` | +-------------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Dictionary` | :ref:`keyword_colors` | ``{}`` | +-------------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Dictionary` | :ref:`member_keyword_colors` | ``{}`` | +-------------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Color` | :ref:`member_variable_color` | ``Color(0, 0, 0, 1)`` | +-------------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Color` | :ref:`number_color` | ``Color(0, 0, 0, 1)`` | +-------------------------------------+------------------------------------------------------------------------------------+-----------------------+ | :ref:`Color` | :ref:`symbol_color` | ``Color(0, 0, 0, 1)`` | +-------------------------------------+------------------------------------------------------------------------------------+-----------------------+ .. rst-class:: classref-reftable-group 方法 ---- .. table:: :widths: auto +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_color_region`\ (\ start_key\: :ref:`String`, end_key\: :ref:`String`, color\: :ref:`Color`, line_only\: :ref:`bool` = false\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_keyword_color`\ (\ keyword\: :ref:`String`, color\: :ref:`Color`\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_member_keyword_color`\ (\ member_keyword\: :ref:`String`, color\: :ref:`Color`\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`clear_color_regions`\ (\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`clear_keyword_colors`\ (\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`clear_member_keyword_colors`\ (\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Color` | :ref:`get_keyword_color`\ (\ keyword\: :ref:`String`\ ) |const| | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Color` | :ref:`get_member_keyword_color`\ (\ member_keyword\: :ref:`String`\ ) |const| | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_color_region`\ (\ start_key\: :ref:`String`\ ) |const| | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_keyword_color`\ (\ keyword\: :ref:`String`\ ) |const| | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_member_keyword_color`\ (\ member_keyword\: :ref:`String`\ ) |const| | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`remove_color_region`\ (\ start_key\: :ref:`String`\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`remove_keyword_color`\ (\ keyword\: :ref:`String`\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`remove_member_keyword_color`\ (\ member_keyword\: :ref:`String`\ ) | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group 屬性說明 -------- .. _class_CodeHighlighter_property_color_regions: .. rst-class:: classref-property :ref:`Dictionary` **color_regions** = ``{}`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_color_regions**\ (\ value\: :ref:`Dictionary`\ ) - :ref:`Dictionary` **get_color_regions**\ (\ ) 設定顏色區域。現有區域都將被移除。\ :ref:`Dictionary` 的鍵為該區域的開始鍵和結束鍵,用空格隔開。對應的值為區域的顏色。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_property_function_color: .. rst-class:: classref-property :ref:`Color` **function_color** = ``Color(0, 0, 0, 1)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_function_color**\ (\ value\: :ref:`Color`\ ) - :ref:`Color` **get_function_color**\ (\ ) 設定函式的顏色。函式是後跟“(”的非關鍵字字串。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_property_keyword_colors: .. rst-class:: classref-property :ref:`Dictionary` **keyword_colors** = ``{}`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_keyword_colors**\ (\ value\: :ref:`Dictionary`\ ) - :ref:`Dictionary` **get_keyword_colors**\ (\ ) 設定關鍵字的顏色。現有關鍵字都將被移除。\ :ref:`Dictionary` 的鍵為關鍵字。對應的值為關鍵字的顏色。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_property_member_keyword_colors: .. rst-class:: classref-property :ref:`Dictionary` **member_keyword_colors** = ``{}`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_member_keyword_colors**\ (\ value\: :ref:`Dictionary`\ ) - :ref:`Dictionary` **get_member_keyword_colors**\ (\ ) 設定成員關鍵字的顏色。現有成員關鍵字都將被移除。\ :ref:`Dictionary` 的鍵為成員關鍵字。對應的值為成員關鍵字的顏色。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_property_member_variable_color: .. rst-class:: classref-property :ref:`Color` **member_variable_color** = ``Color(0, 0, 0, 1)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_member_variable_color**\ (\ value\: :ref:`Color`\ ) - :ref:`Color` **get_member_variable_color**\ (\ ) 設定成員變數的顏色。成員變數是以“.”開頭的非關鍵字、非函式字串。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_property_number_color: .. rst-class:: classref-property :ref:`Color` **number_color** = ``Color(0, 0, 0, 1)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_number_color**\ (\ value\: :ref:`Color`\ ) - :ref:`Color` **get_number_color**\ (\ ) 設定數字的顏色。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_property_symbol_color: .. rst-class:: classref-property :ref:`Color` **symbol_color** = ``Color(0, 0, 0, 1)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_symbol_color**\ (\ value\: :ref:`Color`\ ) - :ref:`Color` **get_symbol_color**\ (\ ) 設定符號的顏色。 .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group 方法說明 -------- .. _class_CodeHighlighter_method_add_color_region: .. rst-class:: classref-method |void| **add_color_region**\ (\ start_key\: :ref:`String`, end_key\: :ref:`String`, color\: :ref:`Color`, line_only\: :ref:`bool` = false\ ) :ref:`🔗` Adds a color region (such as for comments or strings) from ``start_key`` to ``end_key``. Both keys should be symbols, and ``start_key`` must not be shared with other delimiters. If ``line_only`` is ``true`` or ``end_key`` is an empty :ref:`String`, the region does not carry over to the next line. .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_add_keyword_color: .. rst-class:: classref-method |void| **add_keyword_color**\ (\ keyword\: :ref:`String`, color\: :ref:`Color`\ ) :ref:`🔗` 設定關鍵字的顏色。 關鍵字不能包含除“\_”之外的任何符號。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_add_member_keyword_color: .. rst-class:: classref-method |void| **add_member_keyword_color**\ (\ member_keyword\: :ref:`String`, color\: :ref:`Color`\ ) :ref:`🔗` 設定成員關鍵字的顏色。 成員關鍵字不能包含除“\_”之外的任何符號。 如果前面有“.”,則不會高亮顯示。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_clear_color_regions: .. rst-class:: classref-method |void| **clear_color_regions**\ (\ ) :ref:`🔗` 移除所有顏色區域。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_clear_keyword_colors: .. rst-class:: classref-method |void| **clear_keyword_colors**\ (\ ) :ref:`🔗` 移除所有關鍵字。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_clear_member_keyword_colors: .. rst-class:: classref-method |void| **clear_member_keyword_colors**\ (\ ) :ref:`🔗` 移除所有成員關鍵字。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_get_keyword_color: .. rst-class:: classref-method :ref:`Color` **get_keyword_color**\ (\ keyword\: :ref:`String`\ ) |const| :ref:`🔗` 返回某個關鍵字的顏色。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_get_member_keyword_color: .. rst-class:: classref-method :ref:`Color` **get_member_keyword_color**\ (\ member_keyword\: :ref:`String`\ ) |const| :ref:`🔗` 返回某個成員關鍵字的顏色。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_has_color_region: .. rst-class:: classref-method :ref:`bool` **has_color_region**\ (\ start_key\: :ref:`String`\ ) |const| :ref:`🔗` 如果開始鍵存在則返回 ``true``\ ,否則返回 ``false``\ 。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_has_keyword_color: .. rst-class:: classref-method :ref:`bool` **has_keyword_color**\ (\ keyword\: :ref:`String`\ ) |const| :ref:`🔗` 如果關鍵字存在則返回 ``true``\ ,否則返回 ``false``\ 。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_has_member_keyword_color: .. rst-class:: classref-method :ref:`bool` **has_member_keyword_color**\ (\ member_keyword\: :ref:`String`\ ) |const| :ref:`🔗` 如果成員關鍵字存在則返回 ``true``\ ,否則返回 ``false``\ 。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_remove_color_region: .. rst-class:: classref-method |void| **remove_color_region**\ (\ start_key\: :ref:`String`\ ) :ref:`🔗` 移除使用該開始鍵的顏色區域。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_remove_keyword_color: .. rst-class:: classref-method |void| **remove_keyword_color**\ (\ keyword\: :ref:`String`\ ) :ref:`🔗` 移除關鍵字。 .. rst-class:: classref-item-separator ---- .. _class_CodeHighlighter_method_remove_member_keyword_color: .. rst-class:: classref-method |void| **remove_member_keyword_color**\ (\ member_keyword\: :ref:`String`\ ) :ref:`🔗` 移除成員關鍵字。 .. |virtual| replace:: :abbr:`virtual (本方法通常需要使用者覆寫才能生效。)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (本方法沒有副作用。不會修改該實例的任何成員變數。)` .. |vararg| replace:: :abbr:`vararg (本方法除了這裡描述的參數外,還可以接受任意數量的參數。)` .. |constructor| replace:: :abbr:`constructor (本方法用於建構一個型別。)` .. |static| replace:: :abbr:`static (本方法無需實例即可呼叫,因此可以直接使用類別名稱呼叫。)` .. |operator| replace:: :abbr:`operator (本方法描述將本型別作為左運算元時可用的有效運算子。)` .. |bitfield| replace:: :abbr:`BitField (此值是由下列旗標組成的位元遮罩整數。)` .. |void| replace:: :abbr:`void (無回傳值。)`