Fix leading spaces being collapsed in descriptions

Fixes #1954
This commit is contained in:
Samantaz Fox 2021-12-07 05:40:19 +01:00
parent 1769b0fdce
commit 6c8a5a1e7f
No known key found for this signature in database
GPG key ID: F42821059186176E
7 changed files with 11 additions and 16 deletions

View file

@ -540,7 +540,8 @@ p,
} }
#descriptionWrapper { #descriptionWrapper {
max-width: 600px; max-width: 600px;
white-space: pre-wrap;
} }
/* Center the "invidious" logo on the search page */ /* Center the "invidious" logo on the search page */

View file

@ -59,7 +59,7 @@ def get_about_info(ucid, locale)
banner = banners.try &.[-1]?.try &.["url"].as_s? banner = banners.try &.[-1]?.try &.["url"].as_s?
description = initdata["header"]["interactiveTabbedHeaderRenderer"]["description"]["simpleText"].as_s description = initdata["header"]["interactiveTabbedHeaderRenderer"]["description"]["simpleText"].as_s
description_html = HTML.escape(description).gsub("\n", "<br>") description_html = HTML.escape(description)
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s) allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s)
@ -81,7 +81,7 @@ def get_about_info(ucid, locale)
# end # end
description = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?.try &.as_s? || "" description = initdata["metadata"]["channelMetadataRenderer"]?.try &.["description"]?.try &.as_s? || ""
description_html = HTML.escape(description).gsub("\n", "<br>") description_html = HTML.escape(description)
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s) allowed_regions = initdata["microformat"]["microformatDataRenderer"]["availableCountries"].as_a.map(&.as_s)

View file

@ -550,12 +550,12 @@ end
def parse_content(content : JSON::Any) : String def parse_content(content : JSON::Any) : String
content["simpleText"]?.try &.as_s.rchop('\ufeff').try { |b| HTML.escape(b) }.to_s || content["simpleText"]?.try &.as_s.rchop('\ufeff').try { |b| HTML.escape(b) }.to_s ||
content["runs"]?.try &.as_a.try { |r| content_to_comment_html(r).try &.to_s } || "" content["runs"]?.try &.as_a.try { |r| content_to_comment_html(r).try &.to_s.gsub("\n", "<br>") } || ""
end end
def content_to_comment_html(content) def content_to_comment_html(content)
comment_html = content.map do |run| comment_html = content.map do |run|
text = HTML.escape(run["text"].as_s).gsub("\n", "<br>") text = HTML.escape(run["text"].as_s)
if run["bold"]? if run["bold"]?
text = "<b>#{text}</b>" text = "<b>#{text}</b>"

View file

@ -242,7 +242,7 @@ struct InvidiousPlaylist
end end
def description_html def description_html
HTML.escape(self.description).gsub("\n", "<br>") HTML.escape(self.description)
end end
end end

View file

@ -945,7 +945,7 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
# Description # Description
description_html = video_secondary_renderer.try &.dig?("description", "runs") description_html = video_secondary_renderer.try &.dig?("description", "runs")
.try &.as_a.try { |t| content_to_comment_html(t).gsub("\n", "<br/>") } .try &.as_a.try { |t| content_to_comment_html(t) }
params["descriptionHtml"] = JSON::Any.new(description_html || "<p></p>") params["descriptionHtml"] = JSON::Any.new(description_html || "<p></p>")

View file

@ -74,9 +74,7 @@
</div> </div>
<div class="h-box"> <div class="h-box">
<div id="descriptionWrapper"> <div id="descriptionWrapper"><%= playlist.description_html %></div>
<p><%= playlist.description_html %></p>
</div>
</div> </div>
<% if playlist.is_a?(InvidiousPlaylist) && playlist.author == user.try &.email %> <% if playlist.is_a?(InvidiousPlaylist) && playlist.author == user.try &.email %>

View file

@ -257,14 +257,10 @@ we're going to need to do it here in order to allow for translations.
<div id="description-box"> <!-- Description --> <div id="description-box"> <!-- Description -->
<% if video.description.size < 200 || params.extend_desc %> <% if video.description.size < 200 || params.extend_desc %>
<div id="descriptionWrapper"> <div id="descriptionWrapper"><%= video.description_html %></div>
<%= video.description_html %>
</div>
<% else %> <% else %>
<input id="descexpansionbutton" type="checkbox"/> <input id="descexpansionbutton" type="checkbox"/>
<div id="descriptionWrapper"> <div id="descriptionWrapper"><%= video.description_html %></div>
<%= video.description_html %>
</div>
<label for="descexpansionbutton"> <label for="descexpansionbutton">
<a></a> <a></a>
</label> </label>