wp2txt 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/utils_spec.rb CHANGED
@@ -59,6 +59,135 @@ RSpec.describe "Wp2txt Utils" do
59
59
  end
60
60
  end
61
61
 
62
+ # Regression: process_external_links used to strip the brackets of the
63
+ # [ref]/[/ref] markers (contents "ref" / "/ref" take the parts.size == 1
64
+ # branch), so remove_ref could no longer find them and the tag names plus
65
+ # reference body leaked into the extracted text. These tests exercise the
66
+ # composed make_reference -> format_wiki path, since testing remove_ref in
67
+ # isolation passes even with the bug.
68
+ describe "reference markers through format_wiki" do
69
+ it "removes <ref>...</ref> including the body" do
70
+ input = "Paris was founded.<ref>Patrick Boucheron, France in the World (2019) pp 81-86.</ref> The city grew."
71
+ result = format_wiki(make_reference(input))
72
+ expect(result).to eq "Paris was founded. The city grew."
73
+ end
74
+
75
+ it "removes named <ref name=\"x\">...</ref> including the body" do
76
+ input = "Fine dining.<ref name=\"lemonde\">Le Monde, 2 February 2015</ref> Paris has."
77
+ result = format_wiki(make_reference(input))
78
+ expect(result).to eq "Fine dining. Paris has."
79
+ end
80
+
81
+ it "removes self-closing <ref name=\"x\"/>" do
82
+ input = "An asteroid,<ref name=\"x\"/> and a building."
83
+ result = format_wiki(make_reference(input))
84
+ expect(result).to eq "An asteroid, and a building."
85
+ end
86
+
87
+ it "removes consecutive <ref>A</ref><ref>B</ref> without joining tag names" do
88
+ input = "Text<ref>A</ref><ref>B</ref> more."
89
+ result = format_wiki(make_reference(input))
90
+ expect(result).to eq "Text more."
91
+ end
92
+
93
+ it "keeps [ref]...[/ref] markers when config[:ref] is true" do
94
+ input = "Paris was founded.<ref>Patrick Boucheron, France in the World (2019) pp 81-86.</ref> The city grew."
95
+ result = format_wiki(make_reference(input), ref: true)
96
+ expect(result).to eq "Paris was founded.[ref]Patrick Boucheron, France in the World (2019) pp 81-86.[/ref] The city grew."
97
+ end
98
+
99
+ # Guards against the rejected fix of returning "[ref]" from the scanner
100
+ # block: that makes process_nested_single_pass re-detect the same spot
101
+ # until MAX_NESTING_ITERATIONS, leaving external links unprocessed.
102
+ it "still processes external links outside [ref] markers" do
103
+ input = "Claim.<ref>See [http://example.com the site] for detail.</ref> Next [http://foo.com Foo] end."
104
+ expect(format_wiki(make_reference(input))).to eq "Claim. Next Foo end."
105
+ expect(format_wiki(make_reference(input), ref: true)).to eq "Claim.[ref]See the site for detail.[/ref] Next Foo end."
106
+ end
107
+ end
108
+
109
+ # Regression: element splitting (Article#parse) breaks paragraphs at
110
+ # newlines, so a reference written across lines landed in separate elements
111
+ # with [ref] and [/ref] never visible to remove_ref at the same time. This
112
+ # also meant --extract-citations never fired for multi-line cite templates.
113
+ # These tests go through Article.new -> format_wiki per element, since
114
+ # passing a string to format_wiki directly skips element splitting and does
115
+ # not reproduce the bug.
116
+ describe "multi-line references through element splitting" do
117
+ def render_elements(wikitext, config = {})
118
+ Wp2txt::Article.new(wikitext).elements.map { |e| format_wiki(e[1], config) }.join
119
+ end
120
+
121
+ it "removes an empty reference spanning a blank line" do
122
+ result = render_elements("...in the Super League.<ref>\n\n</ref> In 2006, Catalans Dragons became...")
123
+ expect(result).not_to include("[ref]")
124
+ expect(result).not_to include("[/ref]")
125
+ expect(result).to include("Super League. In 2006,")
126
+ end
127
+
128
+ it "removes a named empty reference spanning a blank line" do
129
+ result = render_elements("Claim.<ref name=\"x\">\n\n</ref> Next.")
130
+ expect(result).not_to include("[ref]")
131
+ expect(result).not_to include("[/ref]")
132
+ expect(result).to include("Claim. Next.")
133
+ end
134
+
135
+ it "removes a non-empty reference spanning a blank line" do
136
+ result = render_elements("Claim.<ref>Author\n\nPublisher</ref> Next.")
137
+ expect(result).not_to include("[ref]")
138
+ expect(result).not_to include("[/ref]")
139
+ expect(result).to include("Claim. Next.")
140
+ end
141
+
142
+ it "removes a multi-line cite template reference (with and without leading space)" do
143
+ ["Claim.<ref> {{cite book\n |title=Foo\n |year=2019}}</ref> Next.",
144
+ "Claim.<ref>{{cite book\n|title=Foo\n|year=2019}}</ref> Next."].each do |input|
145
+ result = render_elements(input)
146
+ expect(result).not_to include("[ref]")
147
+ expect(result).not_to include("[/ref]")
148
+ expect(result).not_to include("cite book")
149
+ expect(result).to include("Claim. Next.")
150
+ end
151
+ end
152
+
153
+ # The core of this fix: before, only the multi-line form leaked raw
154
+ # markup, so --extract-citations silently did nothing for it.
155
+ it "extracts citations identically from single-line and multi-line cite templates" do
156
+ config = { extract_citations: true, ref: true }
157
+ single = render_elements("Claim.<ref>{{cite book|title=Foo|year=2019}}</ref> Next.", config)
158
+ multi = render_elements("Claim.<ref>{{cite book\n|title=Foo\n|year=2019}}</ref> Next.", config)
159
+ expect(multi).to eq single
160
+ expect(single).to include("[ref]\"Foo\". 2019.[/ref]")
161
+ end
162
+
163
+ # Control: newlines outside references must still split paragraphs.
164
+ it "still splits ordinary paragraph boundaries at blank lines" do
165
+ elements = Wp2txt::Article.new("First para.\n\nSecond para.").elements
166
+ paragraphs = elements.select { |e| e[0] == :mw_paragraph }
167
+ expect(paragraphs.size).to eq 2
168
+ expect(paragraphs[0][1]).to include("First para.")
169
+ expect(paragraphs[1][1]).to include("Second para.")
170
+ end
171
+
172
+ # An unclosed <ref> must not pair with a later </ref> across paragraphs;
173
+ # the body text stays (a floating [ref] is the pre-existing behavior for
174
+ # this malformed markup).
175
+ it "does not swallow paragraphs when a <ref> is left unclosed" do
176
+ wikitext = "First para with <ref>unclosed reference.\n\nSecond para here.\n\n" \
177
+ "Third para with <ref>closed</ref> end."
178
+ result = render_elements(wikitext)
179
+ expect(result).to include("Second para here.")
180
+ expect(result).to include("First para with")
181
+ end
182
+
183
+ it "handles a multi-line reference with a group attribute" do
184
+ result = render_elements("Claim.<ref group=\"note\">Author\nTitle 2019</ref> Next.")
185
+ expect(result).not_to include("[ref]")
186
+ expect(result).not_to include("[/ref]")
187
+ expect(result).to include("Claim. Next.")
188
+ end
189
+ end
190
+
62
191
  describe "remove_table" do
63
192
  it "removes table formated parts" do
64
193
  str_before = "{| ... \n{| ... \n ...|}\n ...|}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wp2txt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoichiro Hasebe
@@ -217,7 +217,7 @@ files:
217
217
  - Rakefile
218
218
  - bin/wp2txt
219
219
  - bin/wp2txt-mcp
220
- - docs/RESEARCH.md
220
+ - docs/INDEXES.md
221
221
  - image/wp2txt-logo.svg
222
222
  - image/wp2txt.svg
223
223
  - lib/wp2txt.rb
@@ -276,6 +276,7 @@ files:
276
276
  - spec/config_spec.rb
277
277
  - spec/constants_spec.rb
278
278
  - spec/corpus_spec.rb
279
+ - spec/docs_sync_spec.rb
279
280
  - spec/file_utils_spec.rb
280
281
  - spec/fixtures/samples.rb
281
282
  - spec/formatter_sections_spec.rb
@@ -341,6 +342,7 @@ test_files:
341
342
  - spec/config_spec.rb
342
343
  - spec/constants_spec.rb
343
344
  - spec/corpus_spec.rb
345
+ - spec/docs_sync_spec.rb
344
346
  - spec/file_utils_spec.rb
345
347
  - spec/fixtures/samples.rb
346
348
  - spec/formatter_sections_spec.rb