-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
[meta] Add findModeByFileName, let all meta functions accept uppercase #3027
Conversation
This looks interesting but a couple of the filetypes shouldn't be there? GitHub Flavored Markdown - isn't just README.md but could be anything with a .md extension such as CONTRIBUTING.md or HISTORY.md The other filetype values (Asterisk etc) I'm not sure on but the above I am. |
README.md is the only one rendered by default on Github as far as I know. I could see adding others here, but I wonder if these are just loosely based on convention or if there's a defininte list.
I first thought of allowing paths and using regexp pattern to match stuff like the common names for vhosts files, but decided against it for simplicty. I could easily extend it if requested. |
GitHub will render any file ending with the .md extension. See examples here: https://github.com/icetbr/markdown-examples You also couldn't list Nginx conf files as they too could be any name with the extension .conf Just don't think you can name specific filenames for either of these languages. |
Yeah, but what I meant is, only a README.md is displayed below a directory's root, making it kind of special. I just went ahead and added your suggested filenames to
If there's path support, I could possibly use Paths would probably a very rare use case, and probably not worth the extra weigth it adds to CM. While I could myself use it, most commonly you only have a filename available in a web app. |
598472a
to
5e23be1
Compare
Just wanted to voice that I also think you should just add the .md extension instead of specific filenames. Nothing about the filename describes the flavor of Markdown, and .md files will always be Markdown. I like this patch overall, thanks for it! Means we can simplify some of our own code that worked similarly. |
I would if i could, but the extension is already mapped to the vanilla |
Ah in that case, I'm the opposite. :) Idremove the added filenames entirely. There is really nothing about those filenames that says their flavor. |
fb49ac0
to
1aa5d82
Compare
Reduced the function a bit. Filenames are defined by a single regexp now. |
I think this looks good as-is, except that I don't think case-insensitivity should be hard-coded into the function. Rather, add an |
Will do later today. For the case of Markdown (if you agree), I think it's the best possible guess we can make. GitHub-based filenames are pretty common, and (if I remember correctly) the difference between regular and GitHub markdown are subtle enough, so it will render mostly correct in the wrong mode too. |
2698144
to
9fe7aef
Compare
Updated and squashed the commits. Case sensitivity now depends entirely on the regexp. Also changed |
Thank you! Merged as 78e06ac. I've removed the line that downcases extensions by default. I understand the rationale, but I've seen people use uppercase letters in extensions in a significant way, so I don't think this is a decision that should be forced on all users of the library. |
Awesome, thanks! |
Replaces `CodeMirror.findModeByExtension` with `findModeByFileName` to detect nginx config files properly. If `CodeMirror.findModeByFileName` doesn't match anything it automatically tries to find a match via `findModeByExtension`. If that fails to return info as well, we try to determine a mode by calling `CodeMirror.findModeByMIME`. This is the discussion + pr in the CodeMirror repo: * codemirror/codemirror5#2940 * codemirror/codemirror5#3027 Fixes #187
As discussed in #2940, this adds
findModeByFileName
which takes a filename and checks each mode inmodeInfo
for a new propertyfile
, which contains a regexp to test against the given filename. If no filename matches, it tries to extract a extension and fall back tofindModeByExtension
.I also saw the opportunity to let all four meta functions accept data in upper and mixed case too.
Finally, the modeInfo has been extended with filenames, and extensions.This is the result of me googling up modes with no extension associated. There are still modes with no mime or extension, but adding some to these would've been plain guessing.