Class: Banzai::Filter::JsonTableFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Includes:
Concerns::OutputSafety
Defined in:
lib/banzai/filter/json_table_filter.rb

Overview

Prepares a json:table if it’s been tagged as supporting markdown

If the markdown option is not specfied or a boolean true, then we do nothing and allow the frontend to sanitize it and display it.

If ‘markdown: true` is included in the table, then we

  • extract the data from the JSON

  • build a markdown pipe table with the data

  • run the markdown pipe table through the MarkdownFilter

  • run the caption through markdown and add as <caption> to table

  • add the table options as data- attributes so the frontend can properly display

  • note that this filter is handled before the SanitizationFilter, which means the resulting HTML will get properly sanitized at that point.

Constant Summary collapse

CSS =
'[data-canonical-lang="json"][data-lang-params~="table"] > code:only-child'
XPATH =
Gitlab::Utils::Nokogiri.css_to_xpath(CSS).freeze

Instance Method Summary collapse

Methods included from Concerns::OutputSafety

#escape_once

Instance Method Details

#callObject



24
25
26
27
28
29
30
# File 'lib/banzai/filter/json_table_filter.rb', line 24

def call
  doc.xpath(XPATH).each do |node|
    process_json_table(node)
  end

  doc
end