Skip to content

Commit edd480a

Browse files
authored
Merge pull request #378 from CodeMyst/feature/autodetect-ext
checking for extensions when autodetecting
2 parents 0a092d3 + 3182946 commit edd480a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

source/pastemyst/paste/create.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,24 @@ public EncryptedPaste createEncryptedPaste(string title, string expiresIn, Pasty
169169
return paste;
170170
}
171171

172+
/++
173+
+ tries to autodetect a language, will try and get the language from the pasty title first
174+
+/
172175
private string autodetectLanguage(string pasteId, Pasty pasty) @safe
173176
{
174177
import std.file : write, remove, exists, mkdir;
178+
import std.path : extension;
175179
import std.process : execute;
176180
import std.string : strip;
181+
import pastemyst.data : languages;
182+
183+
// check if the language can be gotten from the extension
184+
auto ext = extension(pasty.title);
185+
if (ext !is null)
186+
{
187+
auto extLang = getLanguageName(ext[1..$]);
188+
if (extLang !is null) return extLang;
189+
}
177190

178191
if (!exists("tmp/"))
179192
{

0 commit comments

Comments
 (0)