Sha256: f2518d625d1855a1318f897bbc3bb1e57f5fbd491f6b029a7bbe0b18ae5cfd66

Contents?: true

Size: 463 Bytes

Versions: 3

Compression:

Stored size: 463 Bytes

Contents

# frozen_string_literal: true

module Components
  class CodeBlock < Phlex::Component
    FORMATTER = Rouge::Formatters::HTML.new

    def initialize(code, syntax:)
      @code = code
      @syntax = syntax
    end

    def template
      pre(class: "highlight p-5 whitespace-pre-wrap bg-stone-50") {
        raw FORMATTER.format(
          lexer.lex(@code)
        )
      }
    end

    private

    def lexer
      Rouge::Lexer.find(@syntax)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
phlex-0.2.2 docs/components/code_block.rb
phlex-0.2.1 docs/components/code_block.rb
phlex-0.2.0 docs/components/code_block.rb