Class: Jekyll::DatabaseTables::Converter
- Inherits:
-
Object
- Object
- Jekyll::DatabaseTables::Converter
- Defined in:
- lib/jekyll-database-tables/converter.rb
Overview
Scans document content and replaces Markdown pipe tables with database-style terminal table HTML.
Lines inside fenced blocks (+“‘+ or ~~~) are never treated as tables, regardless of whether they contain pipe characters.
Constant Summary collapse
- FENCE_PATTERN =
/^\s*(`{3,}|~{3,})/
Class Method Summary collapse
-
.call(content, formatter: 'psql') ⇒ String
Convenience method - equivalent to Converter.new(formatter:).call(content).
Instance Method Summary collapse
- #call(content) ⇒ String
-
#initialize(formatter: 'psql') ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(formatter: 'psql') ⇒ Converter
Returns a new instance of Converter.
22 23 24 |
# File 'lib/jekyll-database-tables/converter.rb', line 22 def initialize(formatter: 'psql') @formatter = formatter end |
Class Method Details
.call(content, formatter: 'psql') ⇒ String
Convenience method - equivalent to Converter.new(formatter:).call(content).
18 19 20 |
# File 'lib/jekyll-database-tables/converter.rb', line 18 def self.call(content, formatter: 'psql') new(formatter:).call(content) end |
Instance Method Details
#call(content) ⇒ String
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jekyll-database-tables/converter.rb', line 32 def call(content) lines = content.lines result = +'' buffer = [] fenced = false lines.each do |line| if fenced || !line.include?('|') flush_buffer(result, buffer, line) fenced = !fenced if fence_line?(line) else buffer << line end end flush_buffer(result, buffer) result end |