Skip to content

Commit da9351d

Browse files
authored
Merge pull request #29 from Apollo156156/master
issues#28 - fixed getting file extension
2 parents cdc75b0 + afb3bca commit da9351d

File tree

3 files changed

+29
-51
lines changed

3 files changed

+29
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@
3030
- Исправлена подсветка синтаксиса в Replit, [issue #21](https://github.com/devmanorg/github-copy-plugin/issues/21)
3131
- Исправлена инструкция для запуска в firefox, [issue #19](https://github.com/devmanorg/github-copy-plugin/issues/19)
3232
- Добавляет определения языка при копировании кода в gitlab, [issue #16](https://github.com/devmanorg/github-copy-plugin/issues/16)
33+
- Исправляет получение типа файла в ссылках с get параметрами, [issue #28](https://github.com/devmanorg/github-copy-plugin/issues/28)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ def serialize_post(post): Svg Vector Icons : http://www.onlinewebfonts.com/icon
4646
4. найти и кликнуть на ссылку "Этот Firefox".
4747
5. кликнуть на кнопку "Загрузить временое дополнение".
4848
6. выбрать файл manifest.json внутри папки скаченного проекта.
49+
50+
51+
### Возможные ошибки
52+
53+
1. Uncaught SyntaxError: Cannot use import statement outside a module - возникает из-за универсальности файла manifest.json, с этой ошибкой можно продолжать работу с плагином без проблем

text-tools.js

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -53,58 +53,30 @@ function prepareCodeSnippet(text){
5353
return preparedText;
5454
}
5555

56+
const FILES_TYPE = [
57+
{ path: '.py', type: 'python' },
58+
{ path: '.js', type: 'js' },
59+
{ path: '.html', type: 'html' },
60+
{ path: '.svg', type: 'markup' },
61+
{ path: '.xml', type: 'markup' },
62+
{ path: '.css', type: 'css' },
63+
{ path: '.sh', type: 'bash' },
64+
{ path: 'Dockerfile', type: 'dockerfile' },
65+
{ path: '.diff', type: 'diff' },
66+
{ path: '.json', type: 'json' },
67+
{ path: '.md', type: 'md' },
68+
{ path: '.yml', type: 'yaml' },
69+
{ path: '.yaml', type: 'yaml' },
70+
{ path: '.sql', type: 'sql' },
71+
{ path: '.editorconfig', type: 'editorconfig' },
72+
{ path: '.toml', type: 'toml' },
73+
{ path: '.ini', type: 'ini' },
74+
]
75+
5676
function detectSyntaxByFilename(filename){
57-
if (filename.endsWith('.py')){
58-
return 'python'
59-
}
60-
if (filename.endsWith('.js')){
61-
return 'js'
62-
}
63-
if (filename.endsWith('.html')){
64-
return 'html'
65-
}
66-
if (filename.endsWith('.svg')){
67-
return 'markup'
68-
}
69-
if (filename.endsWith('.xml')){
70-
return 'markup'
71-
}
72-
if (filename.endsWith('.css')){
73-
return 'css'
74-
}
75-
if (filename.endsWith('.sh')){
76-
return 'bash'
77-
}
78-
if (filename == 'Dockerfile' || filename.endsWith('/Dockerfile')){
79-
return 'dockerfile'
80-
}
81-
if (filename.endsWith('.diff')){
82-
return 'diff'
77+
const file = FILES_TYPE.find(fileType => filename.includes(fileType.path));
78+
if (file) {
79+
return file.type;
8380
}
84-
if (filename.endsWith('.json')){
85-
return 'json'
86-
}
87-
if (filename.endsWith('.md')){
88-
return 'md'
89-
}
90-
if (filename.endsWith('.yml')){
91-
return 'yaml'
92-
}
93-
if (filename.endsWith('.yaml')){
94-
return 'yaml'
95-
}
96-
if (filename.endsWith('.sql')){
97-
return 'sql'
98-
}
99-
if (filename.endsWith('.editorconfig')){
100-
return 'editorconfig'
101-
}
102-
if (filename.endsWith('.toml')){
103-
return 'toml'
104-
}
105-
if (filename.endsWith('.ini')){
106-
return 'ini'
107-
}
108-
10981
return '';
11082
}

0 commit comments

Comments
 (0)