Class: Inkpen::Extensions::CodeBlockSyntax
- Defined in:
- lib/inkpen/extensions/code_block_syntax.rb
Overview
Code Block with Syntax Highlighting extension.
Enhances the standard code block with syntax highlighting using lowlight (highlight.js). Supports multiple programming languages with automatic language detection.
Constant Summary collapse
- AVAILABLE_LANGUAGES =
All available programming languages for syntax highlighting. These are loaded from highlight.js via lowlight.
%i[ javascript typescript ruby python css xml html json bash shell sql markdown yaml go rust java kotlin swift php c cpp csharp elixir erlang haskell scala r matlab dockerfile nginx apache graphql ].freeze
- DEFAULT_LANGUAGES =
Default languages to load (for performance).
%i[ javascript typescript ruby python css xml json bash sql markdown ].freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#copy_button? ⇒ Boolean
Whether to enable copy-to-clipboard button.
-
#default_language ⇒ Symbol?
Default language when none is specified.
-
#languages ⇒ Array<Symbol>
Languages to enable for syntax highlighting.
-
#line_numbers? ⇒ Boolean
Whether to show line numbers in code blocks.
-
#name ⇒ Symbol
The unique name of this extension.
-
#show_language_selector? ⇒ Boolean
Whether to show a language selector dropdown.
-
#theme ⇒ String
CSS theme for syntax highlighting.
-
#to_config ⇒ Hash
Convert to configuration hash for JavaScript.
Methods inherited from Base
#enabled?, #initialize, #to_h, #to_json
Constructor Details
This class inherits a constructor from Inkpen::Extensions::Base
Instance Method Details
#copy_button? ⇒ Boolean
Whether to enable copy-to-clipboard button.
132 133 134 |
# File 'lib/inkpen/extensions/code_block_syntax.rb', line 132 def .fetch(:copy_button, true) end |
#default_language ⇒ Symbol?
Default language when none is specified.
105 106 107 |
# File 'lib/inkpen/extensions/code_block_syntax.rb', line 105 def default_language [:default_language] end |
#languages ⇒ Array<Symbol>
Languages to enable for syntax highlighting.
Only these languages will be loaded from highlight.js to reduce bundle size.
96 97 98 |
# File 'lib/inkpen/extensions/code_block_syntax.rb', line 96 def languages .fetch(:languages, DEFAULT_LANGUAGES) end |
#line_numbers? ⇒ Boolean
Whether to show line numbers in code blocks.
114 115 116 |
# File 'lib/inkpen/extensions/code_block_syntax.rb', line 114 def line_numbers? .fetch(:line_numbers, false) end |
#name ⇒ Symbol
The unique name of this extension.
84 85 86 |
# File 'lib/inkpen/extensions/code_block_syntax.rb', line 84 def name :code_block_syntax end |
#show_language_selector? ⇒ Boolean
Whether to show a language selector dropdown.
123 124 125 |
# File 'lib/inkpen/extensions/code_block_syntax.rb', line 123 def show_language_selector? .fetch(:language_selector, true) end |
#theme ⇒ String
CSS theme for syntax highlighting.
141 142 143 |
# File 'lib/inkpen/extensions/code_block_syntax.rb', line 141 def theme .fetch(:theme, "github") end |
#to_config ⇒ Hash
Convert to configuration hash for JavaScript.
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/inkpen/extensions/code_block_syntax.rb', line 150 def to_config { languages: languages, defaultLanguage: default_language, lineNumbers: line_numbers?, languageSelector: show_language_selector?, copyButton: , theme: theme, lowlight: { languages: languages } } end |