Skip to content

Advanced Editor: .md files not detected as Markdown – requires manual mapping #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
elektrischerwalfisch opened this issue Apr 7, 2025 · 2 comments

Comments

@elektrischerwalfisch
Copy link

Hi there,

I noticed that when editing .md (Markdown) files in TinyFileManager, the Ace Editor (Advanced editor view) does not activate Markdown syntax highlighting by default. Instead, it falls back to plain text, while other file types like .js or .php are highlighted correctly.

Upon checking the code, I found that the editor mode is set using this line:

editor.getSession().setMode({
    path: "ace/mode/<?php echo $ext; ?>",
    inline: true
});

However, $ext resolves to 'md' for Markdown files, and Ace does not have a mode called md — it expects 'markdown'. As a result, syntax highlighting doesn't work out of the box for .md files.

Suggested Fix:

A simple conditional mapping like this solves the problem:

if ($ext === 'md') {
    $ext = 'markdown';
}

You could either:

  • Add this line near where $ext is defined,
  • Or apply it just before the editor is initialized.

Why this matters:

Markdown is a very common format for README files, notes, and static content, so it would be great if it worked with proper highlighting by default.

Thanks for your great work on this project! TinyFileManager is incredibly useful and lightweight — really appreciated. 😊

@yucho123987
Copy link

Maybe path: "ace/mode/<?php echo $ext == 'md' ? 'markdown' : $ext; ?>", is better, I think.😁

@elektrischerwalfisch
Copy link
Author

Basically a good idea as it requires less code! But I wonder if eventually ace-editor might become able to recognize md-files correctly in some future releases, which would make this modification obsolete again.
So it might be more sustainable to mark this modification as a temporay fix to be easily found & removed again in the future. Currently I use this:

            <?php 
                /***********************************************
                 * Fix for ace editor:
                 * map .md extension to markdown mode
                 * needed because currently (2025/04/09) ace editor doesn't recognize 'md')
                 ***********************************************/
                if ($ext === 'md') {
                    $ext = 'markdown';
                }
            ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants