@@ -5,22 +5,30 @@ import XcodeInspector
55struct CustomCommandTemplateProcessor {
66 func process( _ text: String ) -> String {
77 let info = getEditorInformation ( )
8- if let editorContent = info. editorContent {
9- let updatedText = text. replacingOccurrences ( of: " {{selected_code}} " , with: """
10- ``` \( info. language. rawValue)
11- \( editorContent. selectedContent. trimmingCharacters ( in: [ " \n " ] ) )
12- ```
8+ let editorContent = info. editorContent
9+ let updatedText = text
10+ . replacingOccurrences ( of: " {{selected_code}} " , with: """
11+ \( editorContent? . selectedContent. trimmingCharacters ( in: . whitespacesAndNewlines) ?? " " )
1312 """ )
14- return updatedText
15- } else {
16- let updatedText = text. replacingOccurrences ( of: " {{selected_code}} " , with: " " )
17- return updatedText
18- }
13+ . replacingOccurrences (
14+ of: " {{active_editor_language}} " ,
15+ with: info. language. rawValue
16+ )
17+ . replacingOccurrences (
18+ of: " {{active_editor_file_url}} " ,
19+ with: info. documentURL? . path ?? " "
20+ )
21+ . replacingOccurrences (
22+ of: " {{active_editor_file_name}} " ,
23+ with: info. documentURL? . lastPathComponent ?? " "
24+ )
25+ return updatedText
1926 }
2027
2128 struct EditorInformation {
2229 let editorContent : SourceEditor . Content ?
2330 let language : CodeLanguage
31+ let documentURL : URL ?
2432 }
2533
2634 func getEditorInformation( ) -> EditorInformation {
@@ -30,7 +38,8 @@ struct CustomCommandTemplateProcessor {
3038
3139 return . init(
3240 editorContent: editorContent,
33- language: language
41+ language: language,
42+ documentURL: documentURL
3443 )
3544 }
3645}
0 commit comments