Sha256: 4b081c6b231de38b2e9dbfaf332aa8c20771e2526872a60e93c6e0a4852d5d1d
Contents?: true
Size: 993 Bytes
Versions: 10
Compression:
Stored size: 993 Bytes
Contents
# frozen_string_literal: true module DocTemplate module Tags class TablePreserveAlignmentTag < BaseTag STYLE_RE = /text-align:(left|center|right)/i.freeze TAG_NAME = 'table-preserve-alignment' def parse(node, _options = {}) if (table = find_table node) # inside cells for each `p` with `text-align` css param we add specific class table.xpath('.//p').each do |el| if (m = STYLE_RE.match el['style']) el['style'] = el['style'].sub STYLE_RE, '' el['class'] = "text-#{m[1]}" end end @content = table.to_s replace_tag table end node.remove self end private def find_table(node) while (node = node.next_sibling) return node if node.name.casecmp('table').zero? end end end Template.register_tag(Tags::TablePreserveAlignmentTag::TAG_NAME, TablePreserveAlignmentTag) end end
Version data entries
10 entries across 10 versions & 1 rubygems