Class: Inkpen::Extensions::Preformatted

Inherits:
Base
  • Object
show all
Defined in:
lib/inkpen/extensions/preformatted.rb

Overview

Preformatted text extension for TipTap.

Plain text block that preserves whitespace exactly as typed. Perfect for ASCII art, ASCII tables, diagrams, and any content that requires precise character alignment.

Unlike CodeBlock, this has NO syntax highlighting - just pure monospace text with preserved whitespace.

Examples:

Basic usage

extension = Inkpen::Extensions::Preformatted.new

With custom options

extension = Inkpen::Extensions::Preformatted.new(
  show_line_numbers: false,
  wrap_lines: false
)

See Also:

Author:

  • Inkpen Team

Since:

  • 0.3.0

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#enabled?, #initialize, #to_h, #to_json

Constructor Details

This class inherits a constructor from Inkpen::Extensions::Base

Instance Method Details

#label_textString

Custom label text.

Returns:

  • (String)

    the label text

Since:

  • 0.3.0



79
80
81
# File 'lib/inkpen/extensions/preformatted.rb', line 79

def label_text
  options.fetch(:label_text, "Plain Text")
end

#nameSymbol

The unique name of this extension.

Returns:

  • (Symbol)

    :preformatted

Since:

  • 0.3.0



34
35
36
# File 'lib/inkpen/extensions/preformatted.rb', line 34

def name
  :preformatted
end

#show_label?Boolean

Whether to show a label/badge.

Returns:

  • (Boolean)

    true to show label

Since:

  • 0.3.0



70
71
72
# File 'lib/inkpen/extensions/preformatted.rb', line 70

def show_label?
  options.fetch(:show_label, true)
end

#show_line_numbers?Boolean

Whether to show line numbers.

Returns:

  • (Boolean)

    true to show line numbers

Since:

  • 0.3.0



43
44
45
# File 'lib/inkpen/extensions/preformatted.rb', line 43

def show_line_numbers?
  options.fetch(:show_line_numbers, false)
end

#tab_sizeInteger

Tab size in spaces.

Returns:

  • (Integer)

    number of spaces per tab

Since:

  • 0.3.0



61
62
63
# File 'lib/inkpen/extensions/preformatted.rb', line 61

def tab_size
  options.fetch(:tab_size, 4)
end

#to_configHash

Convert to configuration hash for JavaScript.

Returns:

  • (Hash)

    configuration for the TipTap extension

Since:

  • 0.3.0



88
89
90
91
92
93
94
95
96
# File 'lib/inkpen/extensions/preformatted.rb', line 88

def to_config
  {
    showLineNumbers: show_line_numbers?,
    wrapLines: wrap_lines?,
    tabSize: tab_size,
    showLabel: show_label?,
    labelText: label_text
  }
end

#wrap_lines?Boolean

Whether to wrap long lines.

Returns:

  • (Boolean)

    true to wrap lines

Since:

  • 0.3.0



52
53
54
# File 'lib/inkpen/extensions/preformatted.rb', line 52

def wrap_lines?
  options.fetch(:wrap_lines, false)
end