-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coradoc::Input::HTML: Fix complex list items
This commit fixes handling of complex list items. Before Coradoc refactor, reverse_adoc used to treat all children of list elements as inline elements (if I recall correctly) After Coradoc refactor, we treat all children of list elements as non-online elements (necessitating line break). This broke certain assumptions we have while dealing with BIPM incoming documents. In particular, whenever there was a subscript involved, we get unexpected line breaks. This PR aims to correctly handle all inline and non-inline list children, according to AsciiDoc specification[1]. Since this is quite a large refactor of a crucial part of documents, this may break a couple of assumptions, so I would really appreciate some testing before merging that. [1] https://docs.asciidoctor.org/asciidoc/latest/lists/continuation/
- Loading branch information
Showing
3 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
spec/coradoc/input/html/components/lists/complex_children_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require "spec_helper" | ||
|
||
describe Coradoc::Element::ListItem do | ||
def input(input, should_convert_to:) | ||
Coradoc::Input::HTML.convert(input).should be == should_convert_to | ||
end | ||
|
||
it "should work with simple blocks" do | ||
input "<ul><li>abc</li></ul>", should_convert_to: "* abc\n" | ||
end | ||
|
||
it "should not expand inline elements" do | ||
input "<ul><li>abc<b>def</b>ghi</li></ul>", | ||
should_convert_to: "* abc**def**ghi\n" | ||
input "<ul><li>abc<a href='c'>ddd</a>ghi</li></ul>", | ||
should_convert_to: "* abc link:c[ddd]ghi\n" | ||
end | ||
|
||
it "should expand non-inline elements like tables" do | ||
input "<ul><li>xx<table><tr><td>test</td></tr></table></li></ul>", | ||
should_convert_to: <<~ADOC | ||
* xx | ||
+ | ||
[cols=1] | ||
|=== | ||
| test | ||
|=== | ||
ADOC | ||
end | ||
|
||
it "should prefix non-inline elements with {empty}" do | ||
input "<ul><li><pre>abc</pre></li></ul>", | ||
should_convert_to: <<~ADOC | ||
* {empty} | ||
+ | ||
.... | ||
abc | ||
.... | ||
ADOC | ||
end | ||
|
||
it "should not prefix inline elements with {empty}" do | ||
input "<ul><li><b>abc</b></li></ul>", | ||
should_convert_to: <<~ADOC | ||
* *abc* | ||
ADOC | ||
end | ||
|
||
it "should replace empty elements with {empty}" do | ||
input "<ul><li></li><li></li><li></li></ul>", | ||
should_convert_to: <<~ADOC | ||
* {empty} | ||
* {empty} | ||
* {empty} | ||
ADOC | ||
end | ||
|
||
it "should handle linebreaks like paragraphs" do | ||
input "<ul><li>test<br>test<br>test</li></ul>", | ||
should_convert_to: <<~ADOC | ||
* test | ||
+ | ||
test | ||
+ | ||
test | ||
ADOC | ||
|
||
input "<ul><li><p>test<p>test<p>test</li></ul>", | ||
should_convert_to: <<~ADOC | ||
* {empty} | ||
+ | ||
test | ||
+ | ||
test | ||
+ | ||
test | ||
ADOC | ||
end | ||
end |