mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Strip more forms of comments from CSS before parsing/inlining. (#2014)
Handle if ExCSS throws an exception during inlining and attempt to fallback to scoping css instead of inlining. I still cannot update past ExCSS v4.1.0 else NPEs for common css will be thrown.
This commit is contained in:
parent
016cd7448f
commit
4b3bc11589
@ -231,7 +231,16 @@ public class BookService : IBookService
|
|||||||
}
|
}
|
||||||
styleRule.Text = $"{CssScopeClass} " + styleRule.Text;
|
styleRule.Text = $"{CssScopeClass} " + styleRule.Text;
|
||||||
}
|
}
|
||||||
return RemoveWhiteSpaceFromStylesheets(stylesheet.ToCss());
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return RemoveWhiteSpaceFromStylesheets(stylesheet.ToCss());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "There was an issue escaping css, likely due to an unsupported css rule");
|
||||||
|
}
|
||||||
|
return RemoveWhiteSpaceFromStylesheets($"{CssScopeClass} {styleContent}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void EscapeCssImportReferences(ref string stylesheetHtml, string apiBase, string prepend)
|
private static void EscapeCssImportReferences(ref string stylesheetHtml, string apiBase, string prepend)
|
||||||
@ -396,7 +405,8 @@ public class BookService : IBookService
|
|||||||
{
|
{
|
||||||
var cssFile = book.Content.Css.GetLocalFileRefByKey(key);
|
var cssFile = book.Content.Css.GetLocalFileRefByKey(key);
|
||||||
|
|
||||||
var styleContent = await ScopeStyles(await cssFile.ReadContentAsync(), apiBase,
|
var stylesheetHtml = await cssFile.ReadContentAsync();
|
||||||
|
var styleContent = await ScopeStyles(stylesheetHtml, apiBase,
|
||||||
cssFile.FilePath, book);
|
cssFile.FilePath, book);
|
||||||
if (styleContent != null)
|
if (styleContent != null)
|
||||||
{
|
{
|
||||||
@ -1263,6 +1273,13 @@ public class BookService : IBookService
|
|||||||
body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty, RegexOptions.None, Parser.RegexTimeout);
|
body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty, RegexOptions.None, Parser.RegexTimeout);
|
||||||
body = Regex.Replace(body, @"\s+", " ", RegexOptions.None, Parser.RegexTimeout);
|
body = Regex.Replace(body, @"\s+", " ", RegexOptions.None, Parser.RegexTimeout);
|
||||||
body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1", RegexOptions.None, Parser.RegexTimeout);
|
body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1", RegexOptions.None, Parser.RegexTimeout);
|
||||||
|
|
||||||
|
// Handle <!-- which some books use (but shouldn't)
|
||||||
|
body = Regex.Replace(body, "<!--.*?-->", string.Empty, RegexOptions.None, Parser.RegexTimeout);
|
||||||
|
|
||||||
|
// Handle /* */
|
||||||
|
body = Regex.Replace(body, @"/\*.*?\*/", string.Empty, RegexOptions.None, Parser.RegexTimeout);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
body = body.Replace(";}", "}");
|
body = body.Replace(";}", "}");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user