Module: LlmLogs::FormattingHelper
- Defined in:
- app/helpers/llm_logs/formatting_helper.rb
Constant Summary collapse
- MARKDOWN_TAGS =
%w[ a blockquote br code del em h1 h2 h3 h4 h5 h6 hr li ol p pre strong table tbody td th thead tr ul ].freeze
- MARKDOWN_ATTRIBUTES =
%w[href title].freeze
Instance Method Summary collapse
Instance Method Details
#format_duration_ms(ms) ⇒ Object
12 13 14 15 16 |
# File 'app/helpers/llm_logs/formatting_helper.rb', line 12 def format_duration_ms(ms) return "—" if ms.nil? "#{number_with_delimiter(sprintf('%.0f', ms))} ms" end |
#pretty_json(data) ⇒ Object
29 30 31 32 33 |
# File 'app/helpers/llm_logs/formatting_helper.rb', line 29 def pretty_json(data) JSON.pretty_generate(deep_parse_json(data)) rescue data.to_s end |
#render_markdown(text) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/llm_logs/formatting_helper.rb', line 18 def render_markdown(text) html = Kramdown::Document.new( text.to_s, input: "GFM", hard_wrap: true, syntax_highlighter: nil ).to_html sanitize html, tags: MARKDOWN_TAGS, attributes: MARKDOWN_ATTRIBUTES end |