Class: Homebrew::Manpages::Parser::Ronn Private
- Inherits:
-
Kramdown::Parser::Kramdown
- Object
- Kramdown::Parser::Kramdown
- Homebrew::Manpages::Parser::Ronn
- Defined in:
- manpages/parser/ronn.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Kramdown parser with compatibility for ronn variable syntax.
Constant Summary collapse
- VARIABLE_REGEX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
HTML-like tags denote variables instead, except
. /<([\w\-|]+)>/
Instance Method Summary collapse
- #initialize(source, options) ⇒ void constructor private
- #parse_variable ⇒ Integer? private
Constructor Details
#initialize(source, options) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'manpages/parser/ronn.rb', line 12 def initialize(source, ) super @block_parsers = T.let(@block_parsers, T::Array[Symbol]) @span_parsers = T.let(@span_parsers, T::Array[Symbol]) # Disable HTML parsing and replace it with variable parsing. # Also disable table parsing too because it depends on HTML parsing # and existing command descriptions may get misinterpreted as tables. # Typographic symbols is disabled as it detects `--` as en-dash. @block_parsers.delete(:block_html) @block_parsers.delete(:table) @span_parsers.delete(:span_html) @span_parsers.delete(:typographic_syms) @span_parsers << :variable end |
Instance Method Details
#parse_variable ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'manpages/parser/ronn.rb', line 30 def parse_variable @src = T.let(@src, T.nilable(Kramdown::Utils::StringScanner)) raise "Ronn src is nil" if @src.nil? start_line_number = @src.current_line_number @src.scan(VARIABLE_REGEX) variable = @src[1] @tree = T.let(@tree, T.nilable(Kramdown::Element)) raise "Ronn tree is nil" if @tree.nil? if variable == "br" @src.skip(/\n/) @tree.children << Element.new(:br, nil, nil, location: start_line_number) else @tree.children << Element.new(:variable, variable, nil, location: start_line_number) end start_line_number end |