fix(YouTube - Overlay buttons): Gemini summary could use the wrong markdown for titles

This commit is contained in:
Aaron Veil 2026-03-16 09:45:12 +03:00
parent ecee8d8421
commit aac78fdb7c

View file

@ -1,3 +1,43 @@
/*
* Copyright (C) 2026 anddea
*
* This file is part of the revanced-patches project:
* https://github.com/anddea/revanced-patches
*
* Original author(s):
* - anddea (https://github.com/anddea)
*
* Licensed under the GNU General Public License v3.0.
*
* ------------------------------------------------------------------------
* GPLv3 Section 7 Attribution Notice
* ------------------------------------------------------------------------
*
* This file contains substantial original work by the author(s) listed above.
*
* In accordance with Section 7 of the GNU General Public License v3.0,
* the following additional terms apply to this file:
*
* 1. Attribution (Section 7(b)): This specific copyright notice and the
* list of original authors above must be preserved in any copy or
* derivative work. You may add your own copyright notice below it,
* but you may not remove the original one.
*
* 2. Origin (Section 7(c)): Modified versions must be clearly marked as
* such (e.g., by adding a "Modified by" line or a new copyright notice).
* They must not be misrepresented as the original work.
*
* ------------------------------------------------------------------------
* Version Control Acknowledgement (Non-binding Request)
* ------------------------------------------------------------------------
*
* While not a legal requirement of the GPLv3, the original author(s)
* respectfully request that ports or substantial modifications retain
* historical authorship credit in version control systems (e.g., Git),
* listing original author(s) appropriately and modifiers as committers
* or co-authors.
*/
package app.morphe.extension.youtube.utils;
import android.graphics.Canvas;
@ -72,7 +112,7 @@ public class MarkdownUtils {
html = listMatcher.replaceAll("<li>$1</li>");
// Remove newlines after block elements to prevent double padding before converting remaining \n to <br>
html = html.replaceAll("</li>\\n", "</li>").replaceAll("</h\\d>\\n", "");
html = html.replaceAll("</li>\\r?\\n", "</li>").replaceAll("(</h\\d>)\\r?\\n", "$1");
// Newlines to <br>
html = html.replace("\n", "<br/>");
@ -89,7 +129,8 @@ public class MarkdownUtils {
while (headerMatcher.find()) {
int level = Objects.requireNonNull(headerMatcher.group(1)).length();
String content = headerMatcher.group(2);
headerMatcher.appendReplacement(headerBuffer, "<h" + level + ">" + content + "</h" + level + ">");
// Wrap 'content' in quoteReplacement to safely escape $ and \ characters
headerMatcher.appendReplacement(headerBuffer, "<h" + level + ">" + Matcher.quoteReplacement(Objects.requireNonNull(content)) + "</h" + level + ">");
}
headerMatcher.appendTail(headerBuffer);