Skip to content

Commit 7f49f36

Browse files
committed
create get langague util
1 parent 5437096 commit 7f49f36

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

utils/get_lang.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
3+
4+
# this will read the file extension and return the correct langague
5+
def get_lexer_for_file(file_path):
6+
_, ext = os.path.splitext(file_path)
7+
8+
if ext == ".rb":
9+
return "ruby"
10+
11+
elif ext == ".py":
12+
from lexers.python.pythonlexer import PythonLexer
13+
return "python"
14+
15+
elif ext == ".js":
16+
return "javascript"
17+
18+
elif ext == ".go":
19+
return "go"
20+
21+
else:
22+
raise ValueError(f"Unsupported file extension: {ext}")

0 commit comments

Comments
 (0)