Explorar o código

Unescape HTML for title in jsonfeed

Thomas Dy %!s(int64=3) %!d(string=hai) anos
pai
achega
a222f41fe1
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      format.ts

+ 10 - 1
format.ts

@@ -29,6 +29,15 @@ function escapeHTML(unsafe: string): StringLike {
   );
 }
 
+function unescapeHTML(safe: string): string {
+  return safe
+    .replace(/&/g, "&")
+    .replace(/&lt;/g, "<")
+    .replace(/&gt;/g, ">")
+    .replace(/"/g, "&quot;")
+    .replace(/'/g, "&#039;");
+}
+
 function joinChildren(children: StringLike[]): SafeString {
   return new SafeString(children
     .map(child => typeof child === 'string' ? escapeHTML(child) : child)
@@ -250,7 +259,7 @@ export function timelineAsJSON(username: string, tweets: Tweet[]): string {
     const html = joinChildren(children);
     return {
       id: tweet.id_str,
-      title: tweet.full_text.split('\n')[0],
+      title: unescapeHTML(tweet.full_text.split('\n')[0]),
       url: buildTwitterUrl(`/${tweet.user.screen_name}/status/${tweet.id_str}`),
       content_html: html,
       date_published: new Date(tweet.created_at).toISOString(),