Module: Asciidoctor::SyntaxHighlighter
Overview
prettify. Additional adapters can be registered using SyntaxHighlighter.register or by supplying a custom factory.
Defined Under Namespace
Modules: Config, DefaultFactory, Factory Classes: Base, CodeRayAdapter, CustomFactory, DefaultFactoryProxy, HighlightJsAdapter, HtmlPipelineAdapter, PrettifyAdapter, PygmentsAdapter, RougeAdapter
Constant Summary
Constants included from DefaultFactory
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Public: Returns the String name of this syntax highlighter for referencing it in messages and option names.
Instance Method Summary collapse
-
#docinfo(location) ⇒ Object
Public: Generates docinfo markup to insert in the output document at the specified location.
-
#docinfo?(location) ⇒ Boolean
Public: Indicates whether this syntax highlighter has docinfo (i.e., markup) to insert into the output document at the specified location.
-
#format(node, lang, opts) ⇒ Object
Public: Format the highlighted source for inclusion in an HTML document.
-
#highlight(node, source, lang, opts) ⇒ Object
Public: Highlights the specified source when this source block is being converted.
-
#highlight? ⇒ Boolean
Public: Indicates whether highlighting is handled by this syntax highlighter or by the client.
- #initialize(name, backend = 'html5', opts = {}) ⇒ Object
-
#write_stylesheet(doc, to_dir) ⇒ Object
Public: Writes the stylesheet to support the highlighted source(s) to disk.
-
#write_stylesheet?(doc) ⇒ Boolean
Public: Indicates whether this syntax highlighter wants to write a stylesheet to disk.
Methods included from DefaultFactory
Methods included from Factory
Instance Attribute Details
#name ⇒ Object (readonly)
Public: Returns the String name of this syntax highlighter for referencing it in messages and option names.
16 17 18 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 16 def name @name end |
Instance Method Details
#docinfo(location) ⇒ Object
Public: Generates docinfo markup to insert in the output document at the specified location.
location - The Symbol representing the location slot (:head or :footer).
Return the [String] markup to insert.
35 36 37 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 35 def docinfo location raise ::NotImplementedError, %(#{SyntaxHighlighter} subclass #{self.class} must implement the ##{__method__} method since #docinfo? returns true) end |
#docinfo?(location) ⇒ Boolean
Public: Indicates whether this syntax highlighter has docinfo (i.e., markup) to insert into the output document at the specified location.
location - The Symbol representing the location slot (:head or :footer).
Returns a [Boolean] indicating whether the docinfo method should be called for this location.
28 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 28 def docinfo? location; end |
#format(node, lang, opts) ⇒ Object
Public: Format the highlighted source for inclusion in an HTML document.
node - The source Block being processed. lang - The source language String for this Block (e.g., ruby). opts - A Hash of options that control syntax highlighting:
:nowrap - A Boolean that indicates whether wrapping should be disabled (optional).
Returns the highlighted source [String] wrapped in preformatted tags (e.g., pre and code)
74 75 76 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 74 def format node, lang, opts raise ::NotImplementedError, %(#{SyntaxHighlighter} subclass #{self.class} must implement the ##{__method__} method) end |
#highlight(node, source, lang, opts) ⇒ Object
Public: Highlights the specified source when this source block is being converted.
If the source contains callout marks, the caller assumes the source remains on the same lines and no closing tags are added to the end of each line. If the source gets shifted by one or more lines, this method must return a tuple containing the highlighted source and the number of lines by which the source was shifted.
node - The source Block to syntax highlight. source - The raw source text String of this source block (after preprocessing). lang - The source language String specified on this block (e.g., ruby). opts - A Hash of options that configure the syntax highlighting:
:callouts - A Hash of callouts extracted from the source, indexed by line number (1-based) (optional).
:css_mode - The Symbol CSS mode (:class or :inline).
:highlight_lines - A 1-based Array of Integer line numbers to highlight (aka emphasize) (optional).
:number_lines - A Symbol indicating whether lines should be numbered (:table or :inline) (optional).
:start_line_number - The starting Integer (1-based) line number (optional, default: 1).
:style - The String style (aka theme) to use for colorizing the code (optional).
Returns the highlighted source String or a tuple of the highlighted source String and an Integer line offset.
62 63 64 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 62 def highlight node, source, lang, opts raise ::NotImplementedError, %(#{SyntaxHighlighter} subclass #{self.class} must implement the ##{__method__} method since #highlight? returns true) end |
#highlight? ⇒ Boolean
Public: Indicates whether highlighting is handled by this syntax highlighter or by the client.
Returns a [Boolean] indicating whether the highlight method should be used to handle the :specialchars substitution.
42 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 42 def highlight?; end |
#initialize(name, backend = 'html5', opts = {}) ⇒ Object
18 19 20 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 18 def initialize name, backend = 'html5', opts = {} @name = @pre_class = name end |
#write_stylesheet(doc, to_dir) ⇒ Object
Public: Writes the stylesheet to support the highlighted source(s) to disk.
doc - The Document in which this syntax highlighter is being used. to_dir - The absolute String path of the stylesheet output directory.
Returns nothing.
92 93 94 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 92 def write_stylesheet doc, to_dir raise ::NotImplementedError, %(#{SyntaxHighlighter} subclass #{self.class} must implement the ##{__method__} method since #write_stylesheet? returns true) end |
#write_stylesheet?(doc) ⇒ Boolean
Public: Indicates whether this syntax highlighter wants to write a stylesheet to disk. Only called if both the linkcss and copycss attributes are set on the document.
doc - The Document in which this syntax highlighter is being used.
Returns a [Boolean] indicating whether the write_stylesheet method should be called.
84 |
# File 'lib/asciidoctor/syntax_highlighter.rb', line 84 def write_stylesheet? doc; end |