@@ -33,7 +33,7 @@ export class Sender {
33
33
34
34
post . text += `[**Открыть запись ВКонтакте**](https://vk.com/wall${ longpoll ? postData . authorId : postData . from_id } _${ postData . id } )\n\n` ;
35
35
36
- if ( postData . text ) post . text += `${ this . FixLinks ( await this . FixHashtags ( postData . text ) ) } \n\n` ;
36
+ if ( postData . text ) post . text += `${ await this . FixMarkdown ( this . FixLinks ( postData . text ) ) } \n\n` ;
37
37
38
38
if ( postData . attachments ) post . attachments += await this . ParseAttachments ( postData . attachments ) ;
39
39
@@ -45,7 +45,7 @@ export class Sender {
45
45
if ( Repost ) {
46
46
repost . text += `\n\n>>> [**Репост записи**](https://vk.com/wall${ longpoll ? Repost . authorId : Repost . from_id } _${ Repost . id } )\n\n` ;
47
47
48
- if ( Repost . text ) repost . text += `${ this . FixLinks ( await this . FixHashtags ( Repost . text ) ) } \n\n` ;
48
+ if ( Repost . text ) repost . text += `${ await this . FixMarkdown ( this . FixLinks ( Repost . text ) ) } \n\n` ;
49
49
50
50
if ( Repost . attachments ) repost . attachments += await this . ParseAttachments ( Repost . attachments ) ;
51
51
}
@@ -144,27 +144,38 @@ export class Sender {
144
144
return text . replace ( / (?: \[ ( h t t p s : \/ \/ v k .c o m \/ [ ^ ] + ?) \| ( [ ^ ] + ?) ] ) / g, "[$2]($1)" ) . replace ( / (?: \[ ( [ ^ ] + ?) \| ( [ ^ ] + ?) ] ) / g, "[$2](https://vk.com/$1)" ) ;
145
145
}
146
146
147
- async FixHashtags ( text ) {
147
+ async FixMarkdown ( text ) {
148
148
let fixedText = text ;
149
149
150
150
const regExp = / # ( [ ^ \s ] + ) @ ( [ a - z A - Z _ ] + ) / g;
151
151
152
152
const matches = regExp . exec ( text ) ;
153
153
154
+ fixedText = fixedText
155
+ . replace ( / # ( [ ^ \s ] + ) / g, ( match , p1 ) => {
156
+ if ( match . match ( regExp ) ) return match ;
157
+
158
+ return `[#${ p1 } ](https://vk.com/feed?section=search&q=%23${ p1 } )` ;
159
+ } ) ;
160
+
154
161
if ( matches ) {
155
162
const resource = await snippets . resolveResource ( matches [ 2 ] )
156
163
. catch ( ( ) => null ) ;
157
164
158
- if ( resource && resource . type === "group" ) fixedText = text . replace ( regExp , "[#$1@$2](https://vk.com/$2/$1)" ) ;
159
- }
160
-
161
- fixedText = fixedText . replace ( / # ( [ ^ \s ] + ) / g, ( match , p1 ) => {
162
- if ( match . match ( regExp ) ) return match ;
165
+ if ( resource && resource . type === "group" ) {
166
+ fixedText = text . replace ( regExp , ( match , p1 , p2 ) => {
167
+ if ( p1 . match ( / [ a - z A - Z ] + / ) ) return `[#${ p1 } @${ p2 } ](https://vk.com/${ p2 } /${ p1 } )` ;
163
168
164
- return `[#${ p1 } ](https://vk.com/feed?section=search&q=%23${ p1 } )` ;
165
- } ) ;
169
+ return `[#${ p1 } @${ p2 } ](https://vk.com/wall-${ resource . id } ?q=%23${ p1 } )` ;
170
+ } ) ;
171
+ }
172
+ }
166
173
167
- return fixedText ;
174
+ try {
175
+ return decodeURI ( fixedText ) ;
176
+ } catch {
177
+ return fixedText ;
178
+ }
168
179
}
169
180
170
181
async Send ( createdAt ) {
0 commit comments