Better ActionText plain text output for nested lists by swanson · Pull Request #...
source link: https://github.com/rails/rails/pull/37976
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Summary
When using to_plain_text
on action text content, nested lists are not rendering in an expected way. Out of the box, the rich text editor allows arbitrary nesting of lists using the "Increase" and "Decrease Level" buttons.
Basic case with one nested item:
ActionText::Content.new("<ul><li>Item 1<ul><li>Item a</li></ul></li></ul>").to_plain_text => "• Item 1• Item a"
Expected:
• Item 1
• Item a
Complex case with multi-level nested and mixed list types:
ActionText::Content.new("<ul><li>Item 0</li><li>Item 1<ul><li>Item A<ol><li>Item i</li><li>Item ii</li></ol></li><li>Item B<ul><li>Item i</li></ul></li></ul></li><li>Item 2</li></ul>").to_plain_text => "• Item 0 • Item 1• Item A1. Item i 2. Item ii • Item B• Item i • Item 2"
Expected:
• Item 0
• Item 1
• Item A
1. Item i
2. Item ii
• Item B
• Item i
• Item 2
Other Information
This PR adds two-space indentation per nested level for ul
and ol
when using to_plain_text
on action text content.
Test case included. All tests passing locally.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK