Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 23, 2025

This PR adds comprehensive Right-to-Left (RTL) alignment support for markdown files in QuickLook, following the same pattern used in the TextViewer plugin for *.txt files.

Features Added

  • Automatic RTL detection based on system UI culture (Arabic, Hebrew)
  • Translation-based configuration via IsSupportRTL setting
  • Manual RTL/LTR switching with keyboard shortcuts (Ctrl+RightShift for RTL, Ctrl+LeftShift for LTR)
  • Complete layout adaptation including table of contents positioning
  • Support for all markdown extensions (.md, .markdown, .mdx, .mmd, .mkd, .mdwn, .mdown, .mdc, .qmd, .rmd, .rmarkdown, .apib, .mdtxt, .mdtext)

Technical Implementation

Files Modified:

  1. Translations.config (NEW) - Added RTL configuration for Arabic and Hebrew locales
  2. MarkdownPanel.cs - Added RTL detection logic similar to TextViewer
  3. md2html.html - Updated HTML template with RTL support and CSS
  4. QuickLook.Plugin.MarkdownViewer.csproj - Include translations as embedded resource

Key Changes:

The implementation follows the existing pattern from TextViewer:

// Check current UI culture and IsSupportRTL translation setting
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;
}

The HTML template now includes:

  • dir="{{rtl}}" attribute on the <html> element
  • RTL-specific CSS for proper table of contents positioning
  • JavaScript keyboard shortcuts for manual RTL/LTR switching

Visual Demo

RTL Mode (Arabic/Hebrew Systems) LTR Mode (Manual/Default)
RTL Mode LTR Mode

The screenshots demonstrate:

  • ✅ Table of contents repositioning (left↔right)
  • ✅ Hebrew/Arabic text proper RTL alignment
  • ✅ English text follows document direction
  • ✅ Interactive RTL/LTR switching
  • ✅ Keyboard shortcuts functionality

Behavior

Automatic RTL Activation:

  • Triggered when system UI culture is RTL (Arabic ar, Hebrew he)
  • Controlled by IsSupportRTL=True translation setting
  • Applies to all supported markdown file extensions

Manual Control:

  • RTL: Ctrl + Right Shift
  • LTR: Ctrl + Left Shift

This implementation provides seamless RTL support for markdown files, automatically adapting to user's language preferences while maintaining full manual control options, consistent with the existing TextViewer RTL functionality.

Fixes #1705.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 23, 2025

🧙 Sourcery has finished reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Copilot AI changed the title [WIP] Preview for RTL *.md files Add RTL support for markdown files Jul 23, 2025
Copilot AI requested a review from emako July 23, 2025 15:04
Copilot finished work on behalf of emako July 23, 2025 15:05
Copy link
Member

@emako emako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not need to create this file.
Just use the code like:

// Check current UI culture and IsSupportRTL translation setting
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;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the unnecessary Translations.config file and simplified the RTL detection to use TranslationHelper.Get() with failsafe value directly, matching the TextViewer pattern exactly. Fixed in c5f6000.

".mdc", ".qmd", ".rmd", ".rmarkdown", ".apib", ".mdtxt", ".mdtext"
};

if (supportedExtensions.Any(ext => extension.Equals(ext, StringComparison.OrdinalIgnoreCase)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to check the extension again in protected string GenerateMarkdownHtml(string path) method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the redundant extension check in GenerateMarkdownHtml method since it only processes markdown files. Simplified the RTL detection logic. Fixed in c5f6000.

Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Copilot AI requested a review from emako July 23, 2025 15:20
Copilot finished work on behalf of emako July 23, 2025 15:20
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile error, lost the using System.Linq; here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the missing using System.Linq; statement to fix the compile error. Fixed in 7485b8c.

Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Copilot AI requested a review from emako July 23, 2025 15:49
Copilot finished work on behalf of emako July 23, 2025 15:49
}

var html = template.Replace("{{content}}", content)
.Replace("{{rtl}}", isRtl ? "rtl" : "ltr");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a sapce to align the previous line of .Replace code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the alignment by adding a space to properly align the .Replace method calls. The code now has consistent indentation. Fixed in f2c8273.

Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Copilot AI requested a review from emako July 23, 2025 15:54
Copilot finished work on behalf of emako July 23, 2025 15:54
@emako emako marked this pull request as ready for review July 23, 2025 15:56
@emako emako merged commit a38b7a4 into master Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview for RTL *.md files

2 participants