code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def previous_sibling_node return nil if @parent.nil? ind = @parent.index(self) return nil if ind == 0 @parent[ ind - 1 ] end
@return the previous sibling (nil if unset)
previous_sibling_node
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/node.rb
Apache-2.0
def to_s indent=nil unless indent.nil? Kernel.warn( "#{self.class.name}.to_s(indent) parameter is deprecated", uplevel: 1) f = REXML::Formatters::Pretty.new( indent ) f.write( self, rv = "" ) else f = REXML::Formatters::Default.new f.write( self, rv = "" ) end return rv end
indent:: *DEPRECATED* This parameter is now ignored. See the formatters in the REXML::Formatters package for changing the output style.
to_s
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/node.rb
Apache-2.0
def each_recursive(&block) # :yields: node self.elements.each {|node| block.call(node) node.each_recursive(&block) } end
Visit all subnodes of +self+ recursively
each_recursive
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/node.rb
Apache-2.0
def find_first_recursive(&block) # :yields: node each_recursive {|node| return node if block.call(node) } return nil end
Find (and return) first subnode (recursively) for which the block evaluates to true. Returns +nil+ if none was found.
find_first_recursive
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/node.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/node.rb
Apache-2.0
def initialize parent=nil super(parent) @children = [] end
Constructor @param parent if supplied, will be set as the parent of this object
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
Apache-2.0
def insert_before( child1, child2 ) if child1.kind_of? String child1 = XPath.first( self, child1 ) child1.parent.insert_before child1, child2 else ind = index(child1) child2.parent.delete(child2) if child2.parent @children[ind,0] = child2 child2.parent = self end self end
Inserts an child before another child @param child1 this is either an xpath or an Element. If an Element, child2 will be inserted before child1 in the child list of the parent. If an xpath, child2 will be inserted before the first child to match the xpath. @param child2 the child to insert @return the parent (self)
insert_before
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
Apache-2.0
def insert_after( child1, child2 ) if child1.kind_of? String child1 = XPath.first( self, child1 ) child1.parent.insert_after child1, child2 else ind = index(child1)+1 child2.parent.delete(child2) if child2.parent @children[ind,0] = child2 child2.parent = self end self end
Inserts an child after another child @param child1 this is either an xpath or an Element. If an Element, child2 will be inserted after child1 in the child list of the parent. If an xpath, child2 will be inserted after the first child to match the xpath. @param child2 the child to insert @return the parent (self)
insert_after
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
Apache-2.0
def index( child ) count = -1 @children.find { |i| count += 1 ; i.hash == child.hash } count end
Fetches the index of a given child @param child the child to get the index of @return the index of the child, or nil if the object is not a child of this parent.
index
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
Apache-2.0
def replace_child( to_replace, replacement ) @children.map! {|c| c.equal?( to_replace ) ? replacement : c } to_replace.parent = nil replacement.parent = self end
Replaces one child with another, making sure the nodelist is correct @param to_replace the child to replace (must be a Child) @param replacement the child to insert into the nodelist (must be a Child)
replace_child
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
Apache-2.0
def deep_clone cl = clone() each do |child| if child.kind_of? Parent cl << child.deep_clone else cl << child.clone end end cl end
Deeply clones this object. This creates a complete duplicate of this Parent, including all descendants.
deep_clone
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parent.rb
Apache-2.0
def initialize(arg, encoding=nil) @orig = @buffer = arg if encoding self.encoding = encoding else detect_encoding end @line = 0 end
Constructor @param arg must be a String, and should be a valid XML document @param encoding if non-null, sets the encoding of the source to this value, overriding all encoding detection
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
Apache-2.0
def scan(pattern, cons=false) return nil if @buffer.nil? rv = @buffer.scan(pattern) @buffer = $' if cons and rv.size>0 rv end
Scans the source for a given pattern. Note, that this is not your usual scan() method. For one thing, the pattern argument has some requirements; for another, the source can be consumed. You can easily confuse this method. Originally, the patterns were easier to construct and this method more robust, because this method generated search regexps on the fly; however, this was computationally expensive and slowed down the entire REXML package considerably, since this is by far the most commonly called method. @param pattern must be a Regexp, and must be in the form of /^\s*(#{your pattern, with no groups})(.*)/. The first group will be returned; the second group is used if the consume flag is set. @param consume if true, the pattern returned will be consumed, leaving everything after it in the Source. @return the pattern, if found, or nil if the Source is empty or the pattern is not found.
scan
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
Apache-2.0
def empty? @buffer == "" end
@return true if the Source is exhausted
empty?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
Apache-2.0
def current_line lines = @orig.split res = lines.grep @buffer[0..30] res = res[-1] if res.kind_of? Array lines.index( res ) if res end
@return the current line in the source
current_line
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
Apache-2.0
def current_line begin pos = @er_source.pos # The byte position in the source lineno = @er_source.lineno # The XML < position in the source @er_source.rewind line = 0 # The \r\n position in the source begin while @er_source.pos < pos @er_source.readline line += 1 end rescue end @er_source.seek(pos) rescue IOError pos = -1 line = -1 end [pos, lineno, line] end
@return the current line in the source
current_line
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/source.rb
Apache-2.0
def initialize(arg, respect_whitespace=false, parent=nil, raw=nil, entity_filter=nil, illegal=NEEDS_A_SECOND_CHECK ) @raw = false @parent = nil @entity_filter = nil if parent super( parent ) @raw = parent.raw end if arg.kind_of? String @string = arg.dup elsif arg.kind_of? Text @string = arg.instance_variable_get(:@string).dup @raw = arg.raw @entity_filter = arg.instance_variable_get(:@entity_filter) else raise "Illegal argument of type #{arg.type} for Text constructor (#{arg})" end @string.squeeze!(" \n\t") unless respect_whitespace @string.gsub!(/\r\n?/, "\n") @raw = raw unless raw.nil? @entity_filter = entity_filter if entity_filter clear_cache Text.check(@string, illegal, doctype) if @raw end
Constructor +arg+ if a String, the content is set to the String. If a Text, the object is shallowly cloned. +respect_whitespace+ (boolean, false) if true, whitespace is respected +parent+ (nil) if this is a Parent object, the parent will be set to this. +raw+ (nil) This argument can be given three values. If true, then the value of used to construct this object is expected to contain no unescaped XML markup, and REXML will not change the text. If this value is false, the string may contain any characters, and REXML will escape any and all defined entities whose values are contained in the text. If this value is nil (the default), then the raw value of the parent will be used as the raw value for this node. If there is no raw value for the parent, and no value is supplied, the default is false. Use this field if you have entities defined for some text, and you don't want REXML to escape that text in output. Text.new( "<&", false, nil, false ) #-> "&lt;&amp;" Text.new( "&lt;&amp;", false, nil, false ) #-> "&amp;lt;&amp;amp;" Text.new( "<&", false, nil, true ) #-> Parse exception Text.new( "&lt;&amp;", false, nil, true ) #-> "&lt;&amp;" # Assume that the entity "s" is defined to be "sean" # and that the entity "r" is defined to be "russell" Text.new( "sean russell" ) #-> "&s; &r;" Text.new( "sean russell", false, nil, true ) #-> "sean russell" +entity_filter+ (nil) This can be an array of entities to match in the supplied text. This argument is only useful if +raw+ is set to false. Text.new( "sean russell", false, nil, false, ["s"] ) #-> "&s; russell" Text.new( "sean russell", false, nil, true, ["s"] ) #-> "sean russell" In the last example, the +entity_filter+ argument is ignored. +illegal+ INTERNAL USE ONLY
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
Apache-2.0
def to_s return @string if @raw @normalized ||= Text::normalize( @string, doctype, @entity_filter ) end
Returns the string value of this text node. This string is always escaped, meaning that it is a valid XML text node string, and all entities that can be escaped, have been inserted. This method respects the entity filter set in the constructor. # Assume that the entity "s" is defined to be "sean", and that the # entity "r" is defined to be "russell" t = Text.new( "< & sean russell", false, nil, false, ['s'] ) t.to_s #-> "&lt; &amp; &s; russell" t = Text.new( "< & &s; russell", false, nil, false ) t.to_s #-> "&lt; &amp; &s; russell" u = Text.new( "sean russell", false, nil, true ) u.to_s #-> "sean russell"
to_s
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
Apache-2.0
def value @unnormalized ||= Text::unnormalize( @string, doctype ) end
Returns the string value of this text. This is the text without entities, as it might be used programmatically, or printed to the console. This ignores the 'raw' attribute setting, and any entity_filter. # Assume that the entity "s" is defined to be "sean", and that the # entity "r" is defined to be "russell" t = Text.new( "< & sean russell", false, nil, false, ['s'] ) t.value #-> "< & sean russell" t = Text.new( "< & &s; russell", false, nil, false ) t.value #-> "< & sean russell" u = Text.new( "sean russell", false, nil, true ) u.value #-> "sean russell"
value
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
Apache-2.0
def xpath path = @parent.xpath path += "/text()" return path end
FIXME This probably won't work properly
xpath
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
Apache-2.0
def write_with_substitution out, input copy = input.clone # Doing it like this rather than in a loop improves the speed copy.gsub!( SPECIALS[0], SUBSTITUTES[0] ) copy.gsub!( SPECIALS[1], SUBSTITUTES[1] ) copy.gsub!( SPECIALS[2], SUBSTITUTES[2] ) copy.gsub!( SPECIALS[3], SUBSTITUTES[3] ) copy.gsub!( SPECIALS[4], SUBSTITUTES[4] ) copy.gsub!( SPECIALS[5], SUBSTITUTES[5] ) out << copy end
Writes out text, substituting special characters beforehand. +out+ A String, IO, or any other object supporting <<( String ) +input+ the text to substitute and the write out z=utf8.unpack("U*") ascOut="" z.each{|r| if r < 0x100 ascOut.concat(r.chr) else ascOut.concat(sprintf("&#x%x;", r)) end } puts ascOut
write_with_substitution
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/text.rb
Apache-2.0
def write(writer, indent=-1, transitive=false, ie_hack=false) return nil unless @writethis or writer.kind_of? Output writer << START writer << " #{content encoding}" writer << STOP end
indent:: Ignored. There must be no whitespace before an XML declaration transitive:: Ignored ie_hack:: Ignored
write
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xmldecl.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xmldecl.rb
Apache-2.0
def dclone klone = self.clone klone.clear self.each{|v| klone << v.dclone} klone end
provides a unified +clone+ operation, for REXML::XPathParser to use across multiple Object+ types
dclone
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
Apache-2.0
def first( path_stack, node ) return nil if path.size == 0 case path[0] when :document # do nothing return first( path[1..-1], node ) when :child for c in node.children r = first( path[1..-1], c ) return r if r end when :qname name = path[2] if node.name == name return node if path.size == 3 return first( path[3..-1], node ) else return nil end when :descendant_or_self r = first( path[1..-1], node ) return r if r for c in node.children r = first( path, c ) return r if r end when :node return first( path[1..-1], node ) when :any return first( path[1..-1], node ) end return nil end
Performs a depth-first (document order) XPath search, and returns the first match. This is the fastest, lightest way to return a single result. FIXME: This method is incomplete!
first
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
Apache-2.0
def get_namespace( node, prefix ) if @namespaces return @namespaces[prefix] || '' else return node.namespace( prefix ) if node.node_type == :element return '' end end
Returns a String namespace for a node, given a prefix The rules are: 1. Use the supplied namespace mapping first. 2. If no mapping was supplied, use the context node to look up the namespace
get_namespace
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
Apache-2.0
def expr( path_stack, nodeset, context=nil ) enter(:expr, path_stack, nodeset) if @debug return nodeset if path_stack.length == 0 || nodeset.length == 0 while path_stack.length > 0 trace(:while, path_stack, nodeset) if @debug if nodeset.length == 0 path_stack.clear return [] end op = path_stack.shift case op when :document first_raw_node = nodeset.first.raw_node nodeset = [XPathNode.new(first_raw_node.root_node, position: 1)] when :self nodeset = step(path_stack) do [nodeset] end when :child nodeset = step(path_stack) do child(nodeset) end when :literal trace(:literal, path_stack, nodeset) if @debug return path_stack.shift when :attribute nodeset = step(path_stack, any_type: :attribute) do nodesets = [] nodeset.each do |node| raw_node = node.raw_node next unless raw_node.node_type == :element attributes = raw_node.attributes next if attributes.empty? nodesets << attributes.each_attribute.collect.with_index do |attribute, i| XPathNode.new(attribute, position: i + 1) end end nodesets end when :namespace pre_defined_namespaces = { "xml" => "http://www.w3.org/XML/1998/namespace", } nodeset = step(path_stack, any_type: :namespace) do nodesets = [] nodeset.each do |node| raw_node = node.raw_node case raw_node.node_type when :element if @namespaces nodesets << pre_defined_namespaces.merge(@namespaces) else nodesets << pre_defined_namespaces.merge(raw_node.namespaces) end when :attribute if @namespaces nodesets << pre_defined_namespaces.merge(@namespaces) else nodesets << pre_defined_namespaces.merge(raw_node.element.namespaces) end end end nodesets end when :parent nodeset = step(path_stack) do nodesets = [] nodeset.each do |node| raw_node = node.raw_node if raw_node.node_type == :attribute parent = raw_node.element else parent = raw_node.parent end nodesets << [XPathNode.new(parent, position: 1)] if parent end nodesets end when :ancestor nodeset = step(path_stack) do nodesets = [] # new_nodes = {} nodeset.each do |node| raw_node = node.raw_node new_nodeset = [] while raw_node.parent raw_node = raw_node.parent # next if new_nodes.key?(node) new_nodeset << XPathNode.new(raw_node, position: new_nodeset.size + 1) # new_nodes[node] = true end nodesets << new_nodeset unless new_nodeset.empty? end nodesets end when :ancestor_or_self nodeset = step(path_stack) do nodesets = [] # new_nodes = {} nodeset.each do |node| raw_node = node.raw_node next unless raw_node.node_type == :element new_nodeset = [XPathNode.new(raw_node, position: 1)] # new_nodes[node] = true while raw_node.parent raw_node = raw_node.parent # next if new_nodes.key?(node) new_nodeset << XPathNode.new(raw_node, position: new_nodeset.size + 1) # new_nodes[node] = true end nodesets << new_nodeset unless new_nodeset.empty? end nodesets end when :descendant_or_self nodeset = step(path_stack) do descendant(nodeset, true) end when :descendant nodeset = step(path_stack) do descendant(nodeset, false) end when :following_sibling nodeset = step(path_stack) do nodesets = [] nodeset.each do |node| raw_node = node.raw_node next unless raw_node.respond_to?(:parent) next if raw_node.parent.nil? all_siblings = raw_node.parent.children current_index = all_siblings.index(raw_node) following_siblings = all_siblings[(current_index + 1)..-1] next if following_siblings.empty? nodesets << following_siblings.collect.with_index do |sibling, i| XPathNode.new(sibling, position: i + 1) end end nodesets end when :preceding_sibling nodeset = step(path_stack, order: :reverse) do nodesets = [] nodeset.each do |node| raw_node = node.raw_node next unless raw_node.respond_to?(:parent) next if raw_node.parent.nil? all_siblings = raw_node.parent.children current_index = all_siblings.index(raw_node) preceding_siblings = all_siblings[0, current_index].reverse next if preceding_siblings.empty? nodesets << preceding_siblings.collect.with_index do |sibling, i| XPathNode.new(sibling, position: i + 1) end end nodesets end when :preceding nodeset = step(path_stack, order: :reverse) do unnode(nodeset) do |node| preceding(node) end end when :following nodeset = step(path_stack) do unnode(nodeset) do |node| following(node) end end when :variable var_name = path_stack.shift return [@variables[var_name]] when :eq, :neq, :lt, :lteq, :gt, :gteq left = expr( path_stack.shift, nodeset.dup, context ) right = expr( path_stack.shift, nodeset.dup, context ) res = equality_relational_compare( left, op, right ) trace(op, left, right, res) if @debug return res when :or left = expr(path_stack.shift, nodeset.dup, context) return true if Functions.boolean(left) right = expr(path_stack.shift, nodeset.dup, context) return Functions.boolean(right) when :and left = expr(path_stack.shift, nodeset.dup, context) return false unless Functions.boolean(left) right = expr(path_stack.shift, nodeset.dup, context) return Functions.boolean(right) when :div, :mod, :mult, :plus, :minus left = expr(path_stack.shift, nodeset, context) right = expr(path_stack.shift, nodeset, context) left = unnode(left) if left.is_a?(Array) right = unnode(right) if right.is_a?(Array) left = Functions::number(left) right = Functions::number(right) case op when :div return left / right when :mod return left % right when :mult return left * right when :plus return left + right when :minus return left - right else raise "[BUG] Unexpected operator: <#{op.inspect}>" end when :union left = expr( path_stack.shift, nodeset, context ) right = expr( path_stack.shift, nodeset, context ) left = unnode(left) if left.is_a?(Array) right = unnode(right) if right.is_a?(Array) return (left | right) when :neg res = expr( path_stack, nodeset, context ) res = unnode(res) if res.is_a?(Array) return -Functions.number(res) when :not when :function func_name = path_stack.shift.tr('-','_') arguments = path_stack.shift if nodeset.size != 1 message = "[BUG] Node set size must be 1 for function call: " message += "<#{func_name}>: <#{nodeset.inspect}>: " message += "<#{arguments.inspect}>" raise message end node = nodeset.first if context target_context = context else target_context = {:size => nodeset.size} if node.is_a?(XPathNode) target_context[:node] = node.raw_node target_context[:index] = node.position else target_context[:node] = node target_context[:index] = 1 end end args = arguments.dclone.collect do |arg| result = expr(arg, nodeset, target_context) result = unnode(result) if result.is_a?(Array) result end Functions.context = target_context return Functions.send(func_name, *args) else raise "[BUG] Unexpected path: <#{op.inspect}>: <#{path_stack.inspect}>" end end # while return nodeset ensure leave(:expr, path_stack, nodeset) if @debug end
Expr takes a stack of path elements and a set of nodes (either a Parent or an Array and returns an Array of matching nodes
expr
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
Apache-2.0
def sort(array_of_nodes, order) new_arry = [] array_of_nodes.each { |node| node_idx = [] np = node.node_type == :attribute ? node.element : node while np.parent and np.parent.node_type == :element node_idx << np.parent.index( np ) np = np.parent end new_arry << [ node_idx.reverse, node ] } ordered = new_arry.sort_by do |index, node| if order == :forward index else -index end end ordered.collect do |_index, node| node end end
Reorders an array of nodes so that they are in document order It tries to do this efficiently. FIXME: I need to get rid of this, but the issue is that most of the XPath interpreter functions as a filter, which means that we lose context going in and out of function calls. If I knew what the index of the nodes was, I wouldn't have to do this. Maybe add a document IDX for each node? Problems with mutable documents. Or, rewrite everything.
sort
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
Apache-2.0
def preceding(node) ancestors = [] parent = node.parent while parent ancestors << parent parent = parent.parent end precedings = [] preceding_node = preceding_node_of(node) while preceding_node if ancestors.include?(preceding_node) ancestors.delete(preceding_node) else precedings << XPathNode.new(preceding_node, position: precedings.size + 1) end preceding_node = preceding_node_of(preceding_node) end precedings end
Builds a nodeset of all of the preceding nodes of the supplied node, in reverse document order preceding:: includes every element in the document that precedes this node, except for ancestors
preceding
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb
Apache-2.0
def initialize( ie_hack=false ) @ie_hack = ie_hack end
Prints out the XML document with no formatting -- except if ie_hack is set. ie_hack:: If set to true, then inserts whitespace before the close of an empty tag, so that IE's bad XML parser doesn't choke.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/formatters/default.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/formatters/default.rb
Apache-2.0
def write( node, output ) case node when Document if node.xml_decl.encoding != 'UTF-8' && !output.kind_of?(Output) output = Output.new( output, node.xml_decl.encoding ) end write_document( node, output ) when Element write_element( node, output ) when Declaration, ElementDecl, NotationDecl, ExternalEntity, Entity, Attribute, AttlistDecl node.write( output,-1 ) when Instruction write_instruction( node, output ) when DocType, XMLDecl node.write( output ) when Comment write_comment( node, output ) when CData write_cdata( node, output ) when Text write_text( node, output ) else raise Exception.new("XML FORMATTING ERROR") end end
Writes the node to some output. node:: The node to write output:: A class implementing <TT>&lt;&lt;</TT>. Pass in an Output object to change the output encoding.
write
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/formatters/default.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/formatters/default.rb
Apache-2.0
def initialize( indentation=2, ie_hack=false ) @indentation = indentation @level = 0 @ie_hack = ie_hack @width = 80 @compact = false end
Create a new pretty printer. output:: An object implementing '<<(String)', to which the output will be written. indentation:: An integer greater than 0. The indentation of each level will be this number of spaces. If this is < 1, the behavior of this object is undefined. Defaults to 2. ie_hack:: If true, the printer will insert whitespace before closing empty tags, thereby allowing Internet Explorer's XML parser to function. Defaults to false.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/formatters/pretty.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/formatters/pretty.rb
Apache-2.0
def empty? return (@source.empty? and @stack.empty?) end
Returns true if there are no more events
empty?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb
Apache-2.0
def has_next? return !(@source.empty? and @stack.empty?) end
Returns true if there are more events. Synonymous with !empty?
has_next?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb
Apache-2.0
def peek depth=0 raise %Q[Illegal argument "#{depth}"] if depth < -1 temp = [] if depth == -1 temp.push(pull()) until empty? else while @stack.size+temp.size < depth+1 temp.push(pull()) end end @stack += temp if temp.size > 0 @stack[depth] end
Peek at the +depth+ event in the stack. The first element on the stack is at depth 0. If +depth+ is -1, will parse to the end of the input stream and return the last event, which is always :end_document. Be aware that this causes the stream to be parsed up to the +depth+ event, so you can effectively pre-parse the entire document (pull the entire thing into memory) using this method.
peek
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb
Apache-2.0
def pull pull_event.tap do |event| @listeners.each do |listener| listener.receive event end end end
Returns the next event. This is a +PullEvent+ object.
pull
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb
Apache-2.0
def initialize(arg) @contents = arg end
The type of this event. Will be one of :tag_start, :tag_end, :text, :processing_instruction, :comment, :doctype, :attlistdecl, :entitydecl, :notationdecl, :entity, :cdata, :xmldecl, or :error.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb
Apache-2.0
def doctype? @contents[0] == :start_doctype end
Content: [ String name, String pub_sys, String long_name, String uri ]
doctype?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb
Apache-2.0
def entitydecl? @contents[0] == :entitydecl end
Due to the wonders of DTDs, an entity declaration can be just about anything. There's no way to normalize it; you'll have to interpret the content yourself. However, the following is true: * If the entity declaration is an internal entity: [ String name, String value ] Content: [ String text ]
entitydecl?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb
Apache-2.0
def xmldecl? @contents[0] == :xmldecl end
Content: [ String version, String encoding, String standalone ]
xmldecl?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb
Apache-2.0
def listen( *args, &blok ) if args[0].kind_of? Symbol if args.size == 2 args[1].each { |match| @procs << [args[0], match, blok] } else add( [args[0], nil, blok] ) end elsif args[0].kind_of? Array if args.size == 2 args[0].each { |match| add( [nil, match, args[1]] ) } else args[0].each { |match| add( [ :start_element, match, blok ] ) } end else add([nil, nil, args[0]]) end end
Listen arguments: Symbol, Array, Block Listen to Symbol events on Array elements Symbol, Block Listen to Symbol events Array, Listener Listen to all events on Array elements Array, Block Listen to :start_element events on Array elements Listener Listen to All events Symbol can be one of: :start_element, :end_element, :start_prefix_mapping, :end_prefix_mapping, :characters, :processing_instruction, :doctype, :attlistdecl, :elementdecl, :entitydecl, :notationdecl, :cdata, :xmldecl, :comment There is an additional symbol that can be listened for: :progress. This will be called for every event generated, passing in the current stream position. Array contains regular expressions or strings which will be matched against fully qualified element names. Listener must implement the methods in SAX2Listener Block will be passed the same arguments as a SAX2Listener method would be, where the method name is the same as the matched Symbol. See the SAX2Listener for more information.
listen
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/sax2parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/sax2parser.rb
Apache-2.0
def get_procs( symbol, name ) return nil if @procs.size == 0 @procs.find_all do |sym, match, block| ( (sym.nil? or symbol == sym) and ((name.nil? and match.nil?) or match.nil? or ( (name == match) or (match.kind_of? Regexp and name =~ match) ) ) ) end.collect{|x| x[-1]} end
The following methods are duplicates, but it is faster than using a helper
get_procs
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/sax2parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/parsers/sax2parser.rb
Apache-2.0
def highlight(text, lexer, formatter, &b) lexer = Lexer.find(lexer) unless lexer.respond_to? :lex raise "unknown lexer #{lexer}" unless lexer formatter = Formatter.find(formatter) unless formatter.respond_to? :format raise "unknown formatter #{formatter}" unless formatter formatter.format(lexer.lex(text), &b) end
Highlight some text with a given lexer and formatter. @example Rouge.highlight('@foo = 1', 'ruby', 'html') Rouge.highlight('var foo = 1;', 'js', 'terminal256') # streaming - chunks become available as they are lexed Rouge.highlight(large_string, 'ruby', 'html') do |chunk| $stdout.print chunk end
highlight
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge.rb
Apache-2.0
def load_file(path) Kernel::load File.join(LIB_DIR, "rouge/#{path}.rb") end
Load a file relative to the `lib/rouge` path. @api private
load_file
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge.rb
Apache-2.0
def load_lexers # The trailing slash is necessary to avoid lexers being loaded multiple # times by `Lexers.load_lexer` lexer_dir = File.join(LIB_DIR, "rouge/lexers/") Dir.glob(File.join(lexer_dir, '*.rb')).each do |f| Lexers.load_lexer(f.sub(lexer_dir, '')) end end
Load the lexers in the `lib/rouge/lexers` directory. @api private
load_lexers
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge.rb
Apache-2.0
def stream(tokens, &b) raise 'abstract' end
@abstract yield strings that, when concatenated, form the formatted output
stream
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatter.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatter.rb
Apache-2.0
def lex(stream, opts={}, &b) new(opts).lex(stream, &b) end
Lexes `stream` with the given options. The lex is delegated to a new instance. @see #lex
lex
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def continue_lex(*a, &b) lex(*a, &b) end
In case #continue_lex is called statically, we simply begin a new lex from the beginning, since there is no state. @see #continue_lex
continue_lex
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def lookup_fancy(str, code=nil, default_options={}) if str && !str.include?('?') && str != 'guess' lexer_class = find(str) return [lexer_class, default_options] end name, opts = str ? str.split('?', 2) : [nil, ''] # parse the options hash from a cgi-style string opts = CGI.parse(opts || '').map do |k, vals| val = case vals.size when 0 then true when 1 then vals[0] else vals end [ k.to_s, val ] end opts = default_options.merge(Hash[opts]) lexer_class = case name when 'guess', nil self.guess(:source => code, :mimetype => opts['mimetype']) when String self.find(name) end [lexer_class, opts] end
Same as ::find_fancy, except instead of returning an instantiated lexer, returns a pair of [lexer_class, options], so that you can modify or provide additional options to the lexer. Please note: the lexer class might be nil!
lookup_fancy
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def find_fancy(str, code=nil, default_options={}) lexer_class, opts = lookup_fancy(str, code, default_options) lexer_class && lexer_class.new(opts) end
Find a lexer, with fancy shiny features. * The string you pass can include CGI-style options Lexer.find_fancy('erb?parent=tex') * You can pass the special name 'guess' so we guess for you, and you can pass a second argument of the code to guess by Lexer.find_fancy('guess', "#!/bin/bash\necho Hello, world") If the code matches more than one lexer then Guesser::Ambiguous is raised. This is used in the Redcarpet plugin as well as Rouge's own markdown lexer for highlighting internal code blocks.
find_fancy
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def title(t=nil) if t.nil? t = tag.capitalize end @title ||= t end
Specify or get this lexer's title. Meant to be human-readable.
title
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def desc(arg=:absent) if arg == :absent @desc else @desc = arg end end
Specify or get this lexer's description.
desc
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def demo_file(arg=:absent) return @demo_file = Pathname.new(arg) unless arg == :absent @demo_file = Pathname.new(File.join(__dir__, 'demos', tag)) end
Specify or get the path name containing a small demo for this lexer (can be overriden by {demo}).
demo_file
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def demo(arg=:absent) return @demo = arg unless arg == :absent @demo = File.read(demo_file, mode: 'rt:bom|utf-8') end
Specify or get a small demo string for this lexer
demo
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def guesses(info={}) mimetype, filename, source = info.values_at(:mimetype, :filename, :source) custom_globs = info[:custom_globs] guessers = (info[:guessers] || []).dup guessers << Guessers::Mimetype.new(mimetype) if mimetype guessers << Guessers::GlobMapping.by_pairs(custom_globs, filename) if custom_globs && filename guessers << Guessers::Filename.new(filename) if filename guessers << Guessers::Modeline.new(source) if source guessers << Guessers::Source.new(source) if source guessers << Guessers::Disambiguation.new(filename, source) if source && filename Guesser.guess(guessers, Lexer.all) end
Guess which lexer to use based on a hash of info. This accepts the same arguments as Lexer.guess, but will never throw an error. It will return a (possibly empty) list of potential lexers to use.
guesses
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def detectable? return @detectable if defined?(@detectable) @detectable = singleton_methods(false).include?(:detect?) end
Determine if a lexer has a method named +:detect?+ defined in its singleton class.
detectable?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def tag(t=nil) return @tag if t.nil? @tag = t.to_s Lexer.register(@tag, self) end
Used to specify or get the canonical name of this lexer class. @example class MyLexer < Lexer tag 'foo' end MyLexer.tag # => 'foo' Lexer.find('foo') # => MyLexer
tag
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def aliases(*args) args.map!(&:to_s) args.each { |arg| Lexer.register(arg, self) } (@aliases ||= []).concat(args) end
Used to specify alternate names this lexer class may be found by. @example class Erb < Lexer tag 'erb' aliases 'eruby', 'rhtml' end Lexer.find('eruby') # => Erb
aliases
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def filenames(*fnames) (@filenames ||= []).concat(fnames) end
Specify a list of filename globs associated with this lexer. If a filename glob is associated with more than one lexer, this can cause a Guesser::Ambiguous error to be raised in various guessing methods. These errors can be avoided by disambiguation. Filename globs are disambiguated in one of two ways. Either the lexer will define a `self.detect?` method (intended for use with shebangs and doctypes) or a manual rule will be specified in Guessers::Disambiguation. @example class Ruby < Lexer filenames '*.rb', '*.ruby', 'Gemfile', 'Rakefile' end
filenames
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def mimetypes(*mts) (@mimetypes ||= []).concat(mts) end
Specify a list of mimetypes associated with this lexer. @example class Html < Lexer mimetypes 'text/html', 'application/xhtml+xml' end
mimetypes
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def initialize(opts={}) @options = {} opts.each { |k, v| @options[k.to_s] = v } @debug = Lexer.debug_enabled? && bool_option('debug') end
Create a new lexer with the given options. Individual lexers may specify extra options. The only current globally accepted option is `:debug`. @option opts :debug Prints debug information to stdout. The particular info depends on the lexer in question. In regex lexers, this will log the state stack at the beginning of each step, along with each regex tried and each stream consumed. Try it, it's pretty useful.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def with(opts={}) new_options = @options.dup opts.each { |k, v| new_options[k.to_s] = v } self.class.new(new_options) end
Returns a new lexer with the given options set. Useful for e.g. setting debug flags post hoc, or providing global overrides for certain options
with
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def lex(string, opts=nil, &b) if opts if (opts.keys - [:continue]).size > 0 # improper use of options hash warn('Improper use of Lexer#lex - this method does not receive options.' + ' This will become an error in a future version.') end if opts[:continue] warn '`lex :continue => true` is deprecated, please use #continue_lex instead' return continue_lex(string, &b) end end return enum_for(:lex, string) unless block_given? Lexer.assert_utf8!(string) reset! continue_lex(string, &b) end
Given a string, yield [token, chunk] pairs. If no block is given, an enumerator is returned. @option opts :continue Continue the lex from the previous state (i.e. don't call #reset!) @note The use of :continue => true has been deprecated. A warning is issued if run with `$VERBOSE` set to true. @note The use of arbitrary `opts` has never been supported, but we previously ignored them with no error. We now warn unconditionally.
lex
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def continue_lex(string, &b) return enum_for(:continue_lex, string, &b) unless block_given? # consolidate consecutive tokens of the same type last_token = nil last_val = nil stream_tokens(string) do |tok, val| next if val.empty? if tok == last_token last_val << val next end b.call(last_token, last_val) if last_token last_token = tok last_val = val end b.call(last_token, last_val) if last_token end
Continue the lex from the the current state without resetting
continue_lex
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def stream_tokens(stream, &b) raise 'abstract' end
@abstract Yield `[token, chunk]` pairs, given a prepared input stream. This must be implemented. @param [StringScanner] stream the stream
stream_tokens
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexer.rb
Apache-2.0
def rule(re, tok=nil, next_state=nil, &callback) raise ClosedState.new(self) if @closed if tok.nil? && callback.nil? raise "please pass `rule` a token to yield or a callback" end matches_empty = re =~ '' callback ||= case next_state when :pop! proc do |stream| puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug @output_stream.call(tok, stream[0]) puts " popping stack: 1" if @debug @stack.pop or raise 'empty stack!' end when :push proc do |stream| puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug @output_stream.call(tok, stream[0]) puts " pushing :#{@stack.last.name}" if @debug @stack.push(@stack.last) end when Symbol proc do |stream| puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug @output_stream.call(tok, stream[0]) state = @states[next_state] || self.class.get_state(next_state) puts " pushing :#{state.name}" if @debug @stack.push(state) end when nil # cannot use an empty-matching regexp with no predicate raise InvalidRegex.new(re) if matches_empty proc do |stream| puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug @output_stream.call(tok, stream[0]) end else raise "invalid next state: #{next_state.inspect}" end rules << Rule.new(re, callback) close! if matches_empty && !context_sensitive?(re) end
Define a new rule for this state. @overload rule(re, token, next_state=nil) @overload rule(re, &callback) @param [Regexp] re a regular expression for this rule to test. @param [String] tok the token type to yield if `re` matches. @param [#to_s] next_state (optional) a state to push onto the stack if `re` matches. If `next_state` is `:pop!`, the state stack will be popped instead. @param [Proc] callback a block that will be evaluated in the context of the lexer if `re` matches. This block has access to a number of lexer methods, including {RegexLexer#push}, {RegexLexer#pop!}, {RegexLexer#token}, and {RegexLexer#delegate}. The first argument can be used to access the match groups.
rule
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def mixin(state) rules << state.to_s end
Mix in the rules from another state into this state. The rules from the mixed-in state will be tried in order before moving on to the rest of the rules in this state.
mixin
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def stack @stack ||= [get_state(:root)] end
The state stack. This is initially the single state `[:root]`. It is an error for this stack to be empty. @see #state
stack
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def state stack.last or raise 'empty stack!' end
The current state - i.e. one on top of the state stack. NB: if the state stack is empty, this will throw an error rather than returning nil.
state
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def reset! @stack = nil @current_stream = nil puts "start blocks" if @debug && self.class.start_procs.any? self.class.start_procs.each do |pr| instance_eval(&pr) end end
reset this lexer to its initial state. This runs all of the start_procs.
reset!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def stream_tokens(str, &b) stream = StringScanner.new(str) @current_stream = stream @output_stream = b @states = self.class.states @null_steps = 0 until stream.eos? if @debug puts puts "lexer: #{self.class.tag}" puts "stack: #{stack.map(&:name).map(&:to_sym).inspect}" puts "stream: #{stream.peek(20).inspect}" end success = step(state, stream) if !success puts " no match, yielding Error" if @debug b.call(Token::Tokens::Error, stream.getch) end end end
This implements the lexer protocol, by yielding [token, value] pairs. The process for lexing works as follows, until the stream is empty: 1. We look at the state on top of the stack (which by default is `[:root]`). 2. Each rule in that state is tried until one is successful. If one is found, that rule's callback is evaluated - which may yield tokens and manipulate the state stack. Otherwise, one character is consumed with an `'Error'` token, and we continue at (1.) @see #step #step (where (2.) is implemented)
stream_tokens
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def step(state, stream) state.rules.each do |rule| if rule.is_a?(State) puts " entering: mixin :#{rule.name}" if @debug return true if step(rule, stream) puts " exiting: mixin :#{rule.name}" if @debug else puts " trying: #{rule.inspect}" if @debug # XXX HACK XXX # StringScanner's implementation of ^ is b0rken. # see http://bugs.ruby-lang.org/issues/7092 # TODO: this doesn't cover cases like /(a|^b)/, but it's # the most common, for now... next if rule.beginning_of_line && !stream.beginning_of_line? if (size = stream.skip(rule.re)) puts " got: #{stream[0].inspect}" if @debug instance_exec(stream, &rule.callback) if size.zero? @null_steps += 1 if @null_steps > MAX_NULL_SCANS puts " warning: too many scans without consuming the string!" if @debug return false end else @null_steps = 0 end return true end end end false end
Runs one step of the lex. Rules in the current state are tried until one matches, at which point its callback is called. @return true if a rule was tried successfully @return false otherwise.
step
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def token(tok, val=@current_stream[0]) yield_token(tok, val) end
Yield a token. @param tok the token type @param val (optional) the string value to yield. If absent, this defaults to the entire last match.
token
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def group(tok) raise "RegexLexer#group is deprecated: use #groups instead" end
@deprecated Yield a token with the next matched group. Subsequent calls to this method will yield subsequent groups.
group
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def groups(*tokens) tokens.each_with_index do |tok, i| yield_token(tok, @current_stream[i+1]) end end
Yield tokens corresponding to the matched groups of the current match.
groups
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def delegate(lexer, text=nil) puts " delegating to: #{lexer.inspect}" if @debug text ||= @current_stream[0] lexer.continue_lex(text) do |tok, val| puts " delegated token: #{tok.inspect}, #{val.inspect}" if @debug yield_token(tok, val) end end
Delegate the lex to another lexer. We use the `continue_lex` method so that #reset! will not be called. In this way, a single lexer can be repeatedly delegated to while maintaining its own internal state stack. @param [#lex] lexer The lexer or lexer class to delegate to @param [String] text The text to delegate. This defaults to the last matched string.
delegate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def push(state_name=nil, &b) push_state = if state_name get_state(state_name) elsif block_given? StateDSL.new(b.inspect, &b).to_state(self.class) else # use the top of the stack by default self.state end puts " pushing: :#{push_state.name}" if @debug stack.push(push_state) end
Push a state onto the stack. If no state name is given and you've passed a block, a state will be dynamically created using the {StateDSL}.
push
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def pop!(times=1) raise 'empty stack!' if stack.empty? puts " popping stack: #{times}" if @debug stack.pop(times) nil end
Pop the state stack. If a number is passed in, it will be popped that number of times.
pop!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def goto(state_name) raise 'empty stack!' if stack.empty? puts " going to: state :#{state_name} " if @debug stack[-1] = get_state(state_name) end
replace the head of the stack with the given state
goto
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def reset_stack puts ' resetting stack' if @debug stack.clear stack.push get_state(:root) end
reset the stack back to `[:root]`.
reset_stack
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def in_state?(state_name) state_name = state_name.to_sym stack.any? do |state| state.name == state_name.to_sym end end
Check if `state_name` is in the state stack.
in_state?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def state?(state_name) state_name.to_sym == state.name end
Check if `state_name` is the state on top of the state stack.
state?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/regex_lexer.rb
Apache-2.0
def parent return @parent if instance_variable_defined? :@parent @parent = lexer_option(:parent) || Lexers::HTML.new(@options) end
the parent lexer - the one being templated.
parent
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/template_lexer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/template_lexer.rb
Apache-2.0
def shebang return @shebang if instance_variable_defined? :@shebang self =~ /\A\s*#!(.*)$/ @shebang = $1 end
Find a shebang. Returns nil if no shebang is present.
shebang
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
Apache-2.0
def shebang?(match) return false unless shebang match = /\b#{match}(\s|$)/ match === shebang end
Check if the given shebang is present. This normalizes things so that `text.shebang?('bash')` will detect `#!/bash`, '#!/bin/bash', '#!/usr/bin/env bash', and '#!/bin/bash -x'
shebang?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
Apache-2.0
def doctype return @doctype if instance_variable_defined? :@doctype self =~ %r(\A\s* (?:<\?.*?\?>\s*)? # possible <?xml...?> tag <!DOCTYPE\s+(.+?)> )xm @doctype = $1 end
Return the contents of the doctype tag if present, nil otherwise.
doctype
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
Apache-2.0
def doctype?(type=//) type === doctype end
Check if the doctype matches a given regexp or string
doctype?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
Apache-2.0
def lexes_cleanly?(lexer) lexer.lex(self) do |(tok, _)| return false if tok.name == 'Error' end true end
Return true if the result of lexing with the given lexer contains no error tokens.
lexes_cleanly?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/text_analyzer.rb
Apache-2.0
def render(&b) yield <<'END'.gsub('RG', @prefix) \makeatletter \def\RG#1#2{\csname RG@tok@#1\endcsname{#2}}% \newenvironment{RG*}{\ttfamily}{\relax}% END base = @theme.class.base_style yield "\\definecolor{#{@prefix}@fgcolor}{HTML}{#{inline_name(base.fg || '#000000')}}" yield "\\definecolor{#{@prefix}@bgcolor}{HTML}{#{inline_name(base.bg || '#FFFFFF')}}" render_palette(@theme.palette, &b) @theme.styles.each do |tok, style| render_inline_pallete(style, &b) end Token.each_token do |tok| style = @theme.class.get_own_style(tok) style ? render_style(tok, style, &b) : render_blank(tok, &b) end yield '\makeatother' end
Our general strategy is this: * First, define the \RG{tokname}{content} command, which will expand into \RG@tok@tokname{content}. We use \csname...\endcsname to interpolate into a command. * Define the default RG* environment, which will enclose the whole thing. By default this will simply set \ttfamily (select monospace font) but it can be overridden with \renewcommand by the user to be any other formatting. * Define all the colors using xcolors \definecolor command. First we define every palette color with a name such as RG@palette@themneame@colorname. Then we find all foreground and background colors that have literal html colors embedded in them and define them with names such as RG@palette@themename@000000. While html allows three-letter colors such as #FFF, xcolor requires all six characters to be present, so we make sure to normalize that as well as the case convention in #inline_name. * Define the token commands RG@tok@xx. These will take the content as the argument and format it according to the theme, referring to the color in the palette.
render
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/tex_theme_renderer.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/tex_theme_renderer.rb
Apache-2.0
def inflate_token(tok, &b) return enum_for(:inflate_token, tok) unless block_given? yield tok tok.sub_tokens.each do |(_, st)| next if styles[st] inflate_token(st, &b) end end
yield all of the tokens that should be styled the same as the given token. Essentially this recursively all of the subtokens, except those which are more specifically styled.
inflate_token
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/theme.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/theme.rb
Apache-2.0
def starts_block(block_state) @block_state = block_state @block_indentation = @last_indentation || '' puts " starts_block: #{block_state.inspect}" if @debug puts " block_indentation: #{@block_indentation.inspect}" if @debug end
push a state for the next indented block
starts_block
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/util.rb
Apache-2.0
def escape_special_html_chars(value) escape_regex = /[&<>]/ return value unless value =~ escape_regex value.gsub(escape_regex, TABLE_FOR_ESCAPE_HTML) end
A performance-oriented helper method to escape `&`, `<` and `>` for the rendered HTML from this formatter. `String#gsub` will always return a new string instance irrespective of whether a substitution occurs. This method however invokes `String#gsub` only if a substitution is imminent. Returns either the given `value` argument string as is or a new string with the special characters replaced with their escaped counterparts.
escape_special_html_chars
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/html.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/html.rb
Apache-2.0
def initialize(opts={}) @formatter = opts[:inline_theme] ? HTMLInline.new(opts[:inline_theme]) : HTML.new @formatter = HTMLTable.new(@formatter, opts) if opts[:line_numbers] if opts.fetch(:wrap, true) @formatter = HTMLPygments.new(@formatter, opts.fetch(:css_class, 'codehilite')) end end
@option opts [String] :css_class ('highlight') @option opts [true/false] :line_numbers (false) @option opts [Rouge::CSSTheme] :inline_theme (nil) @option opts [true/false] :wrap (true) Initialize with options. If `:inline_theme` is given, then instead of rendering the tokens as <span> tags with CSS classes, the styles according to the given theme will be inlined in "style" attributes. This is useful for formats in which stylesheets are not available. Content will be wrapped in a tag (`div` if tableized, `pre` if not) with the given `:css_class` unless `:wrap` is set to `false`.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/html_legacy.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/html_legacy.rb
Apache-2.0
def initialize(formatter, opts={}) @formatter = formatter @start_line = opts.fetch :start_line, 1 @table_class = opts.fetch :table_class, 'rouge-line-table' @gutter_class = opts.fetch :gutter_class, 'rouge-gutter' @code_class = opts.fetch :code_class, 'rouge-code' @line_class = opts.fetch :line_class, 'lineno' @line_id = opts.fetch :line_id, 'line-%i' end
@param [Rouge::Formatters::Formatter] formatter An instance of a `Rouge::Formatters::HTML` or `Rouge::Formatters::HTMLInline` @param [Hash] opts options for HTMLLineTable instance. @option opts [Integer] :start_line line number to start from. Defaults to `1`. @option opts [String] :table_class Class name for the table. Defaults to `"rouge-line-table"`. @option opts [String] :line_id a `sprintf` template for generating an `id` attribute for each table row corresponding to current line number. Defaults to `"line-%i"`. @option opts [String] :line_class Class name for each table row. Defaults to `"lineno"`. @option opts [String] :gutter_class Class name for rendered line-number cell. Defaults to `"rouge-gutter"`. @option opts [String] :code_class Class name for rendered code cell. Defaults to `"rouge-code"`.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/html_line_table.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/html_line_table.rb
Apache-2.0
def initialize(theme = Themes::ThankfulEyes.new) if theme.is_a?(Rouge::Theme) @theme = theme elsif theme.is_a?(Hash) @theme = theme[:theme] || Themes::ThankfulEyes.new else raise ArgumentError, "invalid theme: #{theme.inspect}" end end
@param [Hash,Rouge::Theme] theme the theme to render with.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/terminal256.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/terminal256.rb
Apache-2.0
def hphantom_tag(tok, val) leading = nil val.sub!(/^[ ]+/) { leading = $&.size; '' } yield "\\hphantom{#{'x' * leading}}" if leading yield tag(tok, val) unless val.empty? end
Special handling for leading spaces, since they may be gobbled by a previous command. We replace all initial spaces with \hphantom{xxxx}, which renders an empty space equal to the size of the x's.
hphantom_tag
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/tex.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/formatters/tex.rb
Apache-2.0
def filter(lexers) mapping = {} lexers.each do |lexer| mapping[lexer.name] = lexer.filenames || [] end GlobMapping.new(mapping, @filename).filter(lexers) end
returns a list of lexers that match the given filename with equal specificity (i.e. number of wildcards in the pattern). This helps disambiguate between, e.g. the Nginx lexer, which matches `nginx.conf`, and the Conf lexer, which matches `*.conf`. In this case, nginx will win because the pattern has no wildcards, while `*.conf` has one.
filter
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/guessers/filename.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/guessers/filename.rb
Apache-2.0
def get_source(source) if source.respond_to?(:to_str) SourceNormalizer.normalize(source.to_str) elsif source.respond_to?(:read) SourceNormalizer.normalize(source.read) else raise ArgumentError, "Invalid source: #{source.inspect}" end end
@param [String,IO] source @return [String]
get_source
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/guessers/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/guessers/util.rb
Apache-2.0
def allow_comments? case @comments when :guess @prompt && [email protected]? && !end_chars.include?('#') else @comments end end
whether to allow comments. if manually specifying a prompt that isn't simply "#", we flag this to on
allow_comments?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/console.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/console.rb
Apache-2.0
def initialize(opts={}) super default_filters = { 'javascript' => Javascript.new(options), 'css' => CSS.new(options), 'ruby' => ruby, 'erb' => ERB.new(options), 'markdown' => Markdown.new(options), 'sass' => Sass.new(options), # TODO # 'textile' => Textile.new(options), # 'maruku' => Maruku.new(options), } @filters = hash_option(:filters, default_filters) do |v| as_lexer(v) || PlainText.new(@options) end end
@option opts :filters A hash of filter name to lexer of how various filters should be highlighted. By default, :javascript, :css, :ruby, and :erb are supported.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/haml.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/haml.rb
Apache-2.0
def reset_indent puts " yaml: reset_indent" if @debug @indent_stack = [0] @next_indent = 0 @block_scalar_indent = nil end
NB: Tabs are forbidden in YAML, which is why you see things like /[ ]+/. reset the indentation levels
reset_indent
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/yaml.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/yaml.rb
Apache-2.0
def rouge_formatter(lexer) Formatters::HTMLLegacy.new(:css_class => "highlight #{lexer.tag}") end
override this method for custom formatting behavior
rouge_formatter
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/plugins/redcarpet.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/plugins/redcarpet.rb
Apache-2.0