Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed list parsing #52

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[v#.#.#] ([month] [YYYY])
- Add support for nested items in lists

v4.10.0 (September 2023)
- Update gemspec links

Expand Down
26 changes: 26 additions & 0 deletions lib/acunetix/concerns/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def cleanup_html(source)
result = source.dup

format_table(result)
result = format_list(result)

result.gsub!(/"/, '"')
result.gsub!(/&/, '&')
Expand Down Expand Up @@ -34,6 +35,11 @@ def cleanup_html(source)

result.gsub!(/<strong>(.*?)<\/strong>/) { "*#{$1.strip}*" }
result.gsub!(/<span.*?>(.*?)<\/span>/m){"#{$1.strip}\n"}
result.gsub!(/<span.*?>|<\/span>/, '') #repeating again to deal with nested/empty/incomplete span tags
result.gsub!(/(&#x\d{0,3};)/m) { "==#{$1.strip}==" }

# Cleanup lingering <p></p>
result.gsub!(/<p.*?>(.*?)<\/p>/m) { $1 }

result
end
Expand All @@ -45,6 +51,26 @@ def cleanup_decimals(source)
result
end

def format_list(str)
return str unless str.include?('</ul>') || str.include?('</ol>')
deep = 0
text = str.split(/<(?<tag>\/?(ul|ol|li)).*?>/)
result = ""
text.each do |string|
string.strip!
if (string == 'ul' || string == 'ol')
deep = deep + 1
elsif (string == '/ul' || string == '/ol')
deep = deep - 1
elsif (string == 'li')
result += "".ljust(deep, "*")
elsif (string != '/li' && string.strip != "")
result += " " + string + "\n"
end
end
return result
end

def format_table(str)
return unless str.include?('</table>')

Expand Down
Loading