mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 18:39:45 +00:00
Add RTL support for markdown files
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
This commit is contained in:

committed by
ema

parent
a4d118e11f
commit
4840a87858
@@ -16,10 +16,12 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using QuickLook.Common.Helpers;
|
||||
using QuickLook.Plugin.HtmlViewer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -78,7 +80,33 @@ public class MarkdownPanel : WebpagePanel
|
||||
var content = encoding.GetString(bytes);
|
||||
|
||||
var template = ReadString("/md2html.html");
|
||||
var html = template.Replace("{{content}}", content);
|
||||
|
||||
// Check for RTL support similar to TextViewer
|
||||
bool isRtl = false;
|
||||
var extension = Path.GetExtension(path);
|
||||
|
||||
// Apply RTL support to all markdown-like extensions handled by this plugin
|
||||
var supportedExtensions = new[]
|
||||
{
|
||||
".md", ".markdown", ".mdx", ".mmd", ".mkd", ".mdwn", ".mdown",
|
||||
".mdc", ".qmd", ".rmd", ".rmarkdown", ".apib", ".mdtxt", ".mdtext"
|
||||
};
|
||||
|
||||
if (supportedExtensions.Any(ext => extension.Equals(ext, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
|
||||
{
|
||||
string isSupportRTL = TranslationHelper.Get("IsSupportRTL",
|
||||
failsafe: bool.TrueString,
|
||||
domain: Assembly.GetExecutingAssembly().GetName().Name);
|
||||
|
||||
if (bool.TrueString.Equals(isSupportRTL, StringComparison.OrdinalIgnoreCase))
|
||||
isRtl = true;
|
||||
}
|
||||
}
|
||||
|
||||
var html = template.Replace("{{content}}", content)
|
||||
.Replace("{{rtl}}", isRtl ? "rtl" : "ltr");
|
||||
|
||||
return html;
|
||||
}
|
||||
|
Reference in New Issue
Block a user