Skip to content

Commit

Permalink
fix html2text
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Aug 22, 2024
1 parent b185354 commit 364a2ba
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WordCloud"
uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b"
authors = ["guoyongzhi <[email protected]>"]
version = "1.1.0"
version = "1.1.1"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
3 changes: 2 additions & 1 deletion src/textprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,10 @@ function processtext(counter::AbstractVector{<:Union{Pair,Tuple,AbstractVector}}
end
function html2text(content::AbstractString)
patterns = [
r"\"[\s\S]*?\"" => " ",
r"<[\s]*?script[^>]*?>[\s\S]*?<[\s]*?/[\s]*?script[\s]*?>" => " ",
r"<[\s]*?style[^>]*?>[\s\S]*?<[\s]*?/[\s]*?style[\s]*?>" => " ",
r"<!--[\s\S]*?-->" => " ",
r"<[\s\S]*?=\s*?\"[\s\S]*?\"\s*?>" => " ",
"<br>" => "\n",
r"<[\s\S]*?>" => " ",
]
Expand Down
2 changes: 2 additions & 0 deletions test/test_textprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@

htstr = """&pound;abcd<div x-component-name="DisasterSokuho" x-component-data="{&quot;earthquake&quot;:&quot;&lt;!-- 地震速報のメッセージを消しました (2024-04-25 12:00:08)-->\n&quot;,&quot;tsunami&quot;:&quot;&lt;!-- 津波速報のメッセージを消しました (2024-04-25 12:05:35)-->\n&quot;}"><div class="tYQVs"><div>"""
@test strip(html2text(htstr)) == "abcd"
htstr= """<span class="reference-text">"<a rel="nofollow" class="external text" href="不应该出现">something</a>." <i>"""
@test replace(html2text(htstr), r"\s"=>"") == "\"something.\""
end

2 comments on commit 364a2ba

@guo-yong-zhi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/113660

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.1 -m "<description of version>" 364a2ba06bd405fbfc3f67213919213eb0635e79
git push origin v1.1.1

Please sign in to comment.