Skip to content

Commit 9f4cb4b

Browse files
committed
[hotfix] fixed tag_with_html_regexp_array in case of span styles
1 parent 80ba97a commit 9f4cb4b

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

lib/doc_template/tags/base_tag.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def self.tag_with_html_regexp
2424
#
2525
# There can be situations when Google Document is exported
2626
# in a broken way:
27-
# <span>[imag</span><span>e: OP.LE.L1.004</span><span>]
27+
# <span>[imag</span><span style='font-family:"Montserrat"'>e: OP.LE.L1.004</span><span>]
2828
# In this case we need to guess the part which should be substituted
2929
#
3030
# As a result for the tag with name `image` will be the following
3131
# [
32-
# /\[[^\]]*image[[^:,;.]]*(<\/span><span\s?[^>]>)?:?\s?[^\]]*\]/i,
33-
# /\[[^\]]*imag[[^:,;.]]*(<\/span><span\s?[^>]>)?e:?\s?[^\]]*\]/i,
34-
# /\[[^\]]*ima[[^:,;.]]*(<\/span><span\s?[^>]>)?ge:?\s?[^\]]*\]/i
32+
# /\[[^\]]*image[[^:,;.]]*(<\/span>\s*<span\s?[^>]*>)?:?\s?[^\]]*\]/i,
33+
# /\[[^\]]*imag[[^:,;.]]*(<\/span>\s*<span\s?[^>]*>)?e:?\s?[^\]]*\]/i,
34+
# /\[[^\]]*ima[[^:,;.]]*(<\/span>\s*<span\s?[^>]*>)?ge:?\s?[^\]]*\]/i
3535
# ]
3636
#
3737
# @param [Integer] min_char Minimum number of character by which we guess the tag
@@ -46,7 +46,7 @@ def self.tag_with_html_regexp_array(min_char = 3)
4646
first_part = tag_name[0..idx]
4747
last_part = tag_name[(idx + 1)..]
4848

49-
%r{\[[^\]]*#{first_part}[[^:,;.]]*(</span><span\s?[^>]>)?#{last_part}:?\s?[^\]]*\]}i
49+
%r{\[[^\]]*#{first_part}[[^:,;.]]*(</span>\s*<span\s?[^>]*>)?#{last_part}:?\s?[^\]]*\]}i
5050
end
5151
end
5252
end

spec/lib/doc_template/tags/base_tag_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class BaseSpecTag < DocTemplate::Tags::BaseTag
88
def self.clean_tag_with_html_regexp
99
@tag_with_html_regexp = nil
1010
end
11+
12+
def self.clean_tag_with_html_regexp_array
13+
@tag_with_html_regexp_array = nil
14+
end
1115
end
1216

1317
describe DocTemplate::Tags::BaseTag do
@@ -33,10 +37,36 @@ def self.clean_tag_with_html_regexp
3337

3438
context 'when TAG_NAME is not defined' do
3539
before { BaseSpecTag.send :remove_const, :TAG_NAME }
40+
after { BaseSpecTag.const_set(:TAG_NAME, 'image') }
3641

3742
it 'raises an error' do
3843
expect { subject }.to raise_error(StandardError, 'TAG_NAME is not specified')
3944
end
4045
end
46+
47+
describe '.tag_with_html_regexp_array' do
48+
before { BaseSpecTag.clean_tag_with_html_regexp_array }
49+
50+
subject { BaseSpecTag.tag_with_html_regexp_array }
51+
52+
let(:content) do
53+
<<~HTML
54+
<p style='padding:0;font-size:11pt;font-family:"Arial";line-height:1.5;text-align:left'><span style='
55+
vertical-align:baseline;font-size:11pt;font-family:"Cabin";'><span>[i</span><span
56+
style='font-family:"Montserrat"'>mage:OP.PT.L13.014, 50, Esta imagen muestra ruedas de carretas que han sido
57+
enterradas por la tierra movida por el viento durante una tormenta de polvo.] Los Estados Unidos tienen una
58+
historia trágica con sedimentos en movimiento por el viento Durante la década de 1930, gran parte de los
59+
Estados Unidos estaba pasando por una sequía.</span></span></p>
60+
HTML
61+
end
62+
63+
subject { BaseSpecTag.tag_with_html_regexp_array(1) }
64+
65+
it 'returns array of RegExp' do
66+
expect(subject).to all(be_a(Regexp))
67+
expect(subject.size).to eq 5
68+
expect(subject.detect { _1.match(content) }).not_to be_nil
69+
end
70+
end
4171
end
4272
end

0 commit comments

Comments
 (0)