Class: Payday::Markup

Inherits:
Object
  • Object
show all
Defined in:
lib/payday/markup.rb

Overview

Converts the Prawn inline_format markup Payday used to accept in notes and line item descriptions into structured runs that the Typst template can style.

We deliberately produce data rather than Typst source. The template renders each run's text as a literal string, so a customer-supplied description can never become Typst code. Never change this to emit markup.

Constant Summary collapse

FLAGS =

Tags that simply switch a style on, mapped to the key they set on a run.

{'b' => :bold, 'i' => :italic, 'u' => :underline, 'strikethrough' => :strike,
'sub' => :sub, 'sup' => :sup}.freeze
TAG =
%r{<(?<name>b|i|u|strikethrough|sub|sup|font|color|link)(?<attrs>[^>]*)>(?<body>.*?)</\k<name>>}m
LINE_BREAK =
%r{<br\s*/?>}

Class Method Summary collapse

Class Method Details

.to_runs(text) ⇒ Object

Returns an Array of Hashes, each with a :text key and any of :bold, :italic, :underline, :strike, :sub, :sup, :size, :color and :link. Returns nil when there is nothing to render.



22
23
24
25
26
# File 'lib/payday/markup.rb', line 22

def self.to_runs(text)
  return nil if text.nil?

  runs(text.to_s.gsub(LINE_BREAK, "\n"), {})
end