From 212c68f20c43d738c860dc67096e1d847b1dbeb3 Mon Sep 17 00:00:00 2001 From: Joe Woodward Date: Wed, 10 Nov 2021 10:45:49 +0700 Subject: [PATCH] Allow withHeadings for tables --- lib/editor_js/blocks/table_block.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/editor_js/blocks/table_block.rb b/lib/editor_js/blocks/table_block.rb index 99f87c6..b9c0498 100644 --- a/lib/editor_js/blocks/table_block.rb +++ b/lib/editor_js/blocks/table_block.rb @@ -9,6 +9,8 @@ def schema type: object additionalProperties: false properties: + withHeadings: + type: boolean content: type: array items: @@ -21,15 +23,20 @@ def schema def render(_options = {}) content_tag(:div, class: css_name) do content_tag(:table) do - data['content'].map do |row| + data['content'].map.with_index do |row, row_index| + col_tag = with_headings? && row_index.zero? ? :th : :td content_tag(:tr) do - row.map { |col| content_tag :td, col.html_safe }.join().html_safe + row.map { |c| content_tag(col_tag, c.html_safe) }.join.html_safe end - end.join().html_safe + end.join.html_safe end end end + def with_headings? + !!data['withHeadings'] + end + def safe_tags { 'b' => nil,