ibs-format 1.4.10 → 1.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +210 -210
- package/index.js +320 -320
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,210 +1,210 @@
|
|
|
1
|
-
# Description
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
- [Online Demo](#
|
|
7
|
-
- [Supported browsers](#browsers)
|
|
8
|
-
- [Installation](#installation)
|
|
9
|
-
- [Usage](#usage)
|
|
10
|
-
- [Text Formatting](#text-formatting)
|
|
11
|
-
- [Links Detecting](#links-detecting)
|
|
12
|
-
- [Cross Site Scripting (XSS)](#cross-site-scripting
|
|
13
|
-
- [Format the text at run time using custom Pipe](#
|
|
14
|
-
- [Use the external 'ngx-linkifyjs' library for detecting the links](#
|
|
15
|
-
- [Precautions](#precautions)
|
|
16
|
-
|
|
17
|
-
<a name="
|
|
18
|
-
|
|
19
|
-
# Online Demo
|
|
20
|
-
|
|
21
|
-
<a href="https://stackblitz.com/edit/angular-ivy-up1fwx?file=src%2Fapp%2Fcustom-pipe.pipe.ts" target='_blank'>CLICK HERE</a>
|
|
22
|
-
|
|
23
|
-
<a name="browsers"/>
|
|
24
|
-
|
|
25
|
-
# Supported browsers
|
|
26
|
-
|
|
27
|
-
Fully supported and tested, over Google Chrome, Microsoft Edge, Mozilla Firefox and Internet Explorer 11.
|
|
28
|
-
|
|
29
|
-
<a name="installation"/>
|
|
30
|
-
|
|
31
|
-
# Installation
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
npm i ibs-format --save
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
<a name="usage"/>
|
|
38
|
-
|
|
39
|
-
# Usage
|
|
40
|
-
|
|
41
|
-
<a name="text-formatting"/>
|
|
42
|
-
|
|
43
|
-
## Text Formatting
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
import { ibsFormat } from 'ibs-format';
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
For formatting the function 'ibsFormat' needs two arguments.
|
|
50
|
-
1) the text with identifiers in the first argument, in the form of string.
|
|
51
|
-
2) tags and identifiers in the second argument, in the form of string array.
|
|
52
|
-
|
|
53
|
-
```js
|
|
54
|
-
var myText = "Once upon a time, there was a *thristy* ~_crow_~."
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
In the array, the tag symbols in the first index and their identifier in the second index.
|
|
58
|
-
|
|
59
|
-
```js
|
|
60
|
-
var tagArray = [['b','*'],['i','_'],['strike','~'],["mark","!"]];
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
* Here symbol, 'b' is using for 'bold', 'i' for 'italic', 'strike' for 'strike' and 'mark' for 'mark' tag with their respective Identifiers.
|
|
64
|
-
* The user can use as many tags and their identifiers of his own choice.
|
|
65
|
-
* Some special characters can't be used as identifiers for example, dollar sign '$'.
|
|
66
|
-
* Now the function will look like.
|
|
67
|
-
|
|
68
|
-
```js
|
|
69
|
-
myText = ibsFormat(myText, tagArray);
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### The function will return the result with tags
|
|
73
|
-
|
|
74
|
-
`Once upon a time, there was a <b>thristy</b> <strike><i>crow</i></strike>.`
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
### HTML
|
|
78
|
-
|
|
79
|
-
`<p [innerHTML]="myText"></p>`
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
### The result will
|
|
83
|
-
|
|
84
|
-
Once upon a time, there was a <b>thristy</b> <strike><i>crow</i></strike>.
|
|
85
|
-
|
|
86
|
-
<a name="links-detecting"/>
|
|
87
|
-
|
|
88
|
-
# Links Detecting
|
|
89
|
-
|
|
90
|
-
For auto detecting links in to the text and converting them to HTML `<a>` tags, the function 'ibsFormat' needs three arguments
|
|
91
|
-
* To enable auto detecting links create an object and set its 'detectLinks' property to true.
|
|
92
|
-
* You can also specify the target of the links by creating a property 'target' in the object, it is optional with default value '_self'.
|
|
93
|
-
* The value of 'target' property can be set to, '_blank', '_self', '_parent', '_top'.
|
|
94
|
-
* Put the object in the third argument.
|
|
95
|
-
Like:
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
var myText = "The *best* website for learning _JS_ is https://www.w3schools.com/ and my email is info@myemail.com."
|
|
99
|
-
|
|
100
|
-
var tagArray = [['b','*'],['i','_'],['strike','~'],["mark","!"]];
|
|
101
|
-
|
|
102
|
-
var obj = {detectLinks: true, target: '_blank'};
|
|
103
|
-
|
|
104
|
-
myText = ibsFormat(myText, tagArray, obj);
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### The function will return
|
|
108
|
-
|
|
109
|
-
````
|
|
110
|
-
The <b>best</b> website for learning <i>JS</i> is <a href='https://www.w3schools.com/' target='_blank'>https://www.w3schools.com/</a>
|
|
111
|
-
and my email is <a href='mailto:info@myemail.com' target='_blank'>info@myemail.com</a>.
|
|
112
|
-
````
|
|
113
|
-
|
|
114
|
-
### The result will
|
|
115
|
-
|
|
116
|
-
The <b>best</b> website for learning <i>JS</i> is <a href='https://www.w3schools.com/' target='_blank'>https://www.w3schools.com/</a>
|
|
117
|
-
and my email is <a href='mailto:info@myemail.com' target='_blank'>info@myemail.com</a>.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
### In order to skip the text formatting set the second argument null, like:
|
|
121
|
-
|
|
122
|
-
```js
|
|
123
|
-
myText = ibsFormat(myText, null, obj);
|
|
124
|
-
```
|
|
125
|
-
<a name="cross-site-scripting
|
|
126
|
-
|
|
127
|
-
# Cross Site Scripting (XSS).
|
|
128
|
-
|
|
129
|
-
XSS attacks enable attackers to inject client-side scripts into web pages viewed by other users. In order to prevent those scripts, the
|
|
130
|
-
client side tags are converted into nonexecutable through escaping. These security checks are enabled by default and it is recommended to
|
|
131
|
-
keep them enabled, but in order to bypass these security checks place a forth argument in the function.
|
|
132
|
-
|
|
133
|
-
### In order to skip the XSS security checking:
|
|
134
|
-
|
|
135
|
-
Place a JSON object in the forth argument and set it's value to false, if the forth argument is missing then it's value will be true by default.
|
|
136
|
-
|
|
137
|
-
```js
|
|
138
|
-
myText = ibsFormat(myText, tagArray, obj, { allowXssEscaping : false });
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
<a name="
|
|
142
|
-
|
|
143
|
-
# Format the text at run time using custom Pipe.
|
|
144
|
-
|
|
145
|
-
In order to format the text at run time in HTML, create a custom pipe and use the function there.
|
|
146
|
-
|
|
147
|
-
### Create a custom pipe, 'custom-pipe.pipe.ts'.
|
|
148
|
-
|
|
149
|
-
```js
|
|
150
|
-
import { Pipe, PipeTransform } from '@angular/core';
|
|
151
|
-
import { ibsFormat } from "ibs-format";
|
|
152
|
-
|
|
153
|
-
@Pipe({ name: 'ibsformat' })
|
|
154
|
-
export class ibsformatPipe implements PipeTransform {
|
|
155
|
-
transform(value: any, args?: any): any {
|
|
156
|
-
|
|
157
|
-
value = ibsFormat(value, [["b", "*"], ["i", "_"], ["strike", "~"],["mark","!"]],{ detectLinks: true, target: "_blank" });
|
|
158
|
-
|
|
159
|
-
return value;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### Make its entry in 'module.ts'.
|
|
165
|
-
|
|
166
|
-
```js
|
|
167
|
-
import { ibsformatPipe } from './custom-pipe.pipe';
|
|
168
|
-
|
|
169
|
-
// also add in declarations array
|
|
170
|
-
@NgModule({
|
|
171
|
-
declarations: [ AppComponent, ibsformatPipe ],
|
|
172
|
-
})
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Now use the pipe directly in HTMl
|
|
176
|
-
|
|
177
|
-
`<p [innerHTML]="myText | ibsformat"></p>`
|
|
178
|
-
|
|
179
|
-
<a name="
|
|
180
|
-
|
|
181
|
-
# Use the external 'ngx-linkifyjs' library for detecting the links
|
|
182
|
-
|
|
183
|
-
If you do not want to use the built-in 'detectLinks' functionality and want to use any other library for detecting the links, like 'ngx-linkifyjs', so after installing and configuring the 'ngx-linkifyjs' you can use the 'linkify' pipe before the 'ibsFormat' pipe,
|
|
184
|
-
and set the library's 'detectLinks' and 'allowXssEscaping' properties to false.
|
|
185
|
-
|
|
186
|
-
`<p [innerHTML]="myText | linkify | ibsformat"></p>`
|
|
187
|
-
|
|
188
|
-
```js
|
|
189
|
-
value = ibsFormat(
|
|
190
|
-
value,
|
|
191
|
-
[["b", "*"], ["i", "_"], ["strike", "~"], ["mark", "!"]],
|
|
192
|
-
{ detectLinks: false, target: "_blank" },
|
|
193
|
-
{ allowXssEscaping: false }
|
|
194
|
-
)
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
For full example of custom pipe, see the live demo mention above.
|
|
199
|
-
|
|
200
|
-
### Feel free to report any bugs or improvements.
|
|
201
|
-
|
|
202
|
-
<a name="precautions"/>
|
|
203
|
-
|
|
204
|
-
# Precautions
|
|
205
|
-
|
|
206
|
-
* Don't change the index positioning.
|
|
207
|
-
* The function does not supports double or multiple identifiers rather than double asterisks '**'.
|
|
208
|
-
* Don't use same identifiers for multiple tags.
|
|
209
|
-
* Some special characters can't be used as identifiers for example, dollar sign '$'.
|
|
210
|
-
|
|
1
|
+
# Description
|
|
2
|
+
|
|
3
|
+
Detect the user-defined identifiers in the text and convert them into HTML tags like bold, italic, strike, and many more having XSS (Cross-site scripting) security with escaping functionality, also detect the links like URLs, email, and IP addresses and wrap them into Anchor tag `<a>`.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- [Online Demo](#demo)
|
|
7
|
+
- [Supported browsers](#browsers)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Usage](#usage)
|
|
10
|
+
- [Text Formatting](#text-formatting)
|
|
11
|
+
- [Links Detecting](#links-detecting)
|
|
12
|
+
- [Cross Site Scripting (XSS)](#cross-site-scripting)
|
|
13
|
+
- [Format the text at run time using custom Pipe](#pipe)
|
|
14
|
+
- [Use the external 'ngx-linkifyjs' library for detecting the links](#linkifyjs)
|
|
15
|
+
- [Precautions](#precautions)
|
|
16
|
+
|
|
17
|
+
<a name="demo"/>
|
|
18
|
+
|
|
19
|
+
# Online Demo
|
|
20
|
+
|
|
21
|
+
<a href="https://stackblitz.com/edit/angular-ivy-up1fwx?file=src%2Fapp%2Fcustom-pipe.pipe.ts" target='_blank'>CLICK HERE</a>
|
|
22
|
+
|
|
23
|
+
<a name="browsers"/>
|
|
24
|
+
|
|
25
|
+
# Supported browsers
|
|
26
|
+
|
|
27
|
+
Fully supported and tested, over Google Chrome, Microsoft Edge, Mozilla Firefox and Internet Explorer 11.
|
|
28
|
+
|
|
29
|
+
<a name="installation"/>
|
|
30
|
+
|
|
31
|
+
# Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm i ibs-format --save
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
<a name="usage"/>
|
|
38
|
+
|
|
39
|
+
# Usage
|
|
40
|
+
|
|
41
|
+
<a name="text-formatting"/>
|
|
42
|
+
|
|
43
|
+
## Text Formatting
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import { ibsFormat } from 'ibs-format';
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For formatting the function 'ibsFormat' needs two arguments.
|
|
50
|
+
1) the text with identifiers in the first argument, in the form of string.
|
|
51
|
+
2) tags and identifiers in the second argument, in the form of string array.
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
var myText = "Once upon a time, there was a *thristy* ~_crow_~."
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
In the array, the tag symbols in the first index and their identifier in the second index.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
var tagArray = [['b','*'],['i','_'],['strike','~'],["mark","!"]];
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
* Here symbol, 'b' is using for 'bold', 'i' for 'italic', 'strike' for 'strike' and 'mark' for 'mark' tag with their respective Identifiers.
|
|
64
|
+
* The user can use as many tags and their identifiers of his own choice.
|
|
65
|
+
* Some special characters can't be used as identifiers for example, dollar sign '$'.
|
|
66
|
+
* Now the function will look like.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
myText = ibsFormat(myText, tagArray);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### The function will return the result with tags
|
|
73
|
+
|
|
74
|
+
`Once upon a time, there was a <b>thristy</b> <strike><i>crow</i></strike>.`
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### HTML
|
|
78
|
+
|
|
79
|
+
`<p [innerHTML]="myText"></p>`
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### The result will
|
|
83
|
+
|
|
84
|
+
Once upon a time, there was a <b>thristy</b> <strike><i>crow</i></strike>.
|
|
85
|
+
|
|
86
|
+
<a name="links-detecting"/>
|
|
87
|
+
|
|
88
|
+
# Links Detecting
|
|
89
|
+
|
|
90
|
+
For auto detecting links in to the text and converting them to HTML `<a>` tags, the function 'ibsFormat' needs three arguments
|
|
91
|
+
* To enable auto detecting links create an object and set its 'detectLinks' property to true.
|
|
92
|
+
* You can also specify the target of the links by creating a property 'target' in the object, it is optional with default value '_self'.
|
|
93
|
+
* The value of 'target' property can be set to, '_blank', '_self', '_parent', '_top'.
|
|
94
|
+
* Put the object in the third argument.
|
|
95
|
+
Like:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
var myText = "The *best* website for learning _JS_ is https://www.w3schools.com/ and my email is info@myemail.com."
|
|
99
|
+
|
|
100
|
+
var tagArray = [['b','*'],['i','_'],['strike','~'],["mark","!"]];
|
|
101
|
+
|
|
102
|
+
var obj = {detectLinks: true, target: '_blank'};
|
|
103
|
+
|
|
104
|
+
myText = ibsFormat(myText, tagArray, obj);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### The function will return
|
|
108
|
+
|
|
109
|
+
````
|
|
110
|
+
The <b>best</b> website for learning <i>JS</i> is <a href='https://www.w3schools.com/' target='_blank'>https://www.w3schools.com/</a>
|
|
111
|
+
and my email is <a href='mailto:info@myemail.com' target='_blank'>info@myemail.com</a>.
|
|
112
|
+
````
|
|
113
|
+
|
|
114
|
+
### The result will
|
|
115
|
+
|
|
116
|
+
The <b>best</b> website for learning <i>JS</i> is <a href='https://www.w3schools.com/' target='_blank'>https://www.w3schools.com/</a>
|
|
117
|
+
and my email is <a href='mailto:info@myemail.com' target='_blank'>info@myemail.com</a>.
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### In order to skip the text formatting set the second argument null, like:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
myText = ibsFormat(myText, null, obj);
|
|
124
|
+
```
|
|
125
|
+
<a name="cross-site-scripting"/>
|
|
126
|
+
|
|
127
|
+
# Cross Site Scripting (XSS).
|
|
128
|
+
|
|
129
|
+
XSS attacks enable attackers to inject client-side scripts into web pages viewed by other users. In order to prevent those scripts, the
|
|
130
|
+
client side tags are converted into nonexecutable through escaping. These security checks are enabled by default and it is recommended to
|
|
131
|
+
keep them enabled, but in order to bypass these security checks place a forth argument in the function.
|
|
132
|
+
|
|
133
|
+
### In order to skip the XSS security checking:
|
|
134
|
+
|
|
135
|
+
Place a JSON object in the forth argument and set it's value to false, if the forth argument is missing then it's value will be true by default.
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
myText = ibsFormat(myText, tagArray, obj, { allowXssEscaping : false });
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
<a name="pipe"/>
|
|
142
|
+
|
|
143
|
+
# Format the text at run time using custom Pipe.
|
|
144
|
+
|
|
145
|
+
In order to format the text at run time in HTML, create a custom pipe and use the function there.
|
|
146
|
+
|
|
147
|
+
### Create a custom pipe, 'custom-pipe.pipe.ts'.
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
151
|
+
import { ibsFormat } from "ibs-format";
|
|
152
|
+
|
|
153
|
+
@Pipe({ name: 'ibsformat' })
|
|
154
|
+
export class ibsformatPipe implements PipeTransform {
|
|
155
|
+
transform(value: any, args?: any): any {
|
|
156
|
+
|
|
157
|
+
value = ibsFormat(value, [["b", "*"], ["i", "_"], ["strike", "~"],["mark","!"]],{ detectLinks: true, target: "_blank" });
|
|
158
|
+
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Make its entry in 'module.ts'.
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
import { ibsformatPipe } from './custom-pipe.pipe';
|
|
168
|
+
|
|
169
|
+
// also add in declarations array
|
|
170
|
+
@NgModule({
|
|
171
|
+
declarations: [ AppComponent, ibsformatPipe ],
|
|
172
|
+
})
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Now use the pipe directly in HTMl
|
|
176
|
+
|
|
177
|
+
`<p [innerHTML]="myText | ibsformat"></p>`
|
|
178
|
+
|
|
179
|
+
<a name="linkifyjs"/>
|
|
180
|
+
|
|
181
|
+
# Use the external 'ngx-linkifyjs' library for detecting the links
|
|
182
|
+
|
|
183
|
+
If you do not want to use the built-in 'detectLinks' functionality and want to use any other library for detecting the links, like 'ngx-linkifyjs', so after installing and configuring the 'ngx-linkifyjs' you can use the 'linkify' pipe before the 'ibsFormat' pipe,
|
|
184
|
+
and set the library's 'detectLinks' and 'allowXssEscaping' properties to false.
|
|
185
|
+
|
|
186
|
+
`<p [innerHTML]="myText | linkify | ibsformat"></p>`
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
value = ibsFormat(
|
|
190
|
+
value,
|
|
191
|
+
[["b", "*"], ["i", "_"], ["strike", "~"], ["mark", "!"]],
|
|
192
|
+
{ detectLinks: false, target: "_blank" },
|
|
193
|
+
{ allowXssEscaping: false }
|
|
194
|
+
)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
For full example of custom pipe, see the live demo mention above.
|
|
199
|
+
|
|
200
|
+
### Feel free to report any bugs or improvements.
|
|
201
|
+
|
|
202
|
+
<a name="precautions"/>
|
|
203
|
+
|
|
204
|
+
# Precautions
|
|
205
|
+
|
|
206
|
+
* Don't change the index positioning.
|
|
207
|
+
* The function does not supports double or multiple identifiers rather than double asterisks '**'.
|
|
208
|
+
* Don't use same identifiers for multiple tags.
|
|
209
|
+
* Some special characters can't be used as identifiers for example, dollar sign '$'.
|
|
210
|
+
|
package/index.js
CHANGED
|
@@ -1,320 +1,320 @@
|
|
|
1
|
-
function ibsFormat(value, arr, linky, escaping) {
|
|
2
|
-
let output = null;
|
|
3
|
-
escaping = escaping && escaping.allowXssEscaping == false ? false : true;
|
|
4
|
-
if (value) {
|
|
5
|
-
if (escaping) {
|
|
6
|
-
value = value.replace(/</g, "<");
|
|
7
|
-
value = value.replace(/>/g, ">");
|
|
8
|
-
}
|
|
9
|
-
value = value.replace(/\n/g, " <br> ");
|
|
10
|
-
}
|
|
11
|
-
if (value != "" && value != null && value != undefined && arr && arr.length > 0) {
|
|
12
|
-
if (arr[0].constructor === Array) {
|
|
13
|
-
arr.map(function (e) {
|
|
14
|
-
e[2] = (e[0].length + 1).toString();
|
|
15
|
-
if (e[1] == "*") {
|
|
16
|
-
value = astericHandler(value, e[0], e[1], parseInt(e[2]), " ");
|
|
17
|
-
} else if (e[1] == '**') {
|
|
18
|
-
value = doubleAstericHandler(value, e[0], e[1], parseInt(e[2]), " ");
|
|
19
|
-
} else {
|
|
20
|
-
value = getFormat(value, e[0], e[1], parseInt(e[2]), " ");
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
} else {
|
|
24
|
-
arr[2] = (arr[0].length + 1).toString();
|
|
25
|
-
if (arr[1] == "*") {
|
|
26
|
-
value = astericHandler(value, arr[0], arr[1], parseInt(arr[2]), " ");
|
|
27
|
-
} else if (arr[1] == '**') {
|
|
28
|
-
value = doubleAstericHandler(value, arr[0], arr[1], parseInt(arr[2]), " ");
|
|
29
|
-
} else {
|
|
30
|
-
value = getFormat(value, arr[0], arr[1], parseInt(arr[2]), " ");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
output = value;
|
|
34
|
-
} else {
|
|
35
|
-
output = null;
|
|
36
|
-
}
|
|
37
|
-
if (value != "" && value != null && value != undefined && linky && linky.detectLinks == true) {
|
|
38
|
-
let targ;
|
|
39
|
-
if (linky.target != null && linky.target != "") {
|
|
40
|
-
targ = linky.target;
|
|
41
|
-
} else {
|
|
42
|
-
targ = "_self";
|
|
43
|
-
}
|
|
44
|
-
output = linkfy(value, targ);
|
|
45
|
-
}
|
|
46
|
-
if (output) {
|
|
47
|
-
output = output.replace(/ <br> /g, "<br>");
|
|
48
|
-
}
|
|
49
|
-
return output ? output.trim() : "";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function doubleAstericHandler(text, tag, iden, trim, space) {
|
|
53
|
-
let box = [];
|
|
54
|
-
let arr = [];
|
|
55
|
-
let finalText = "";
|
|
56
|
-
let a = text.split(" ");
|
|
57
|
-
let singleStericCounter = 0;
|
|
58
|
-
a.forEach(function (e) {
|
|
59
|
-
if (
|
|
60
|
-
e.length > 1 &&
|
|
61
|
-
e.includes(iden) &&
|
|
62
|
-
(e.match(/\*\*/g) || []).length == 1
|
|
63
|
-
) {
|
|
64
|
-
++singleStericCounter;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
singleStericCounter = singleStericCounter - 1;
|
|
68
|
-
let flag = "1";
|
|
69
|
-
let loopCounter = 0;
|
|
70
|
-
a.forEach(function (e) {
|
|
71
|
-
if (
|
|
72
|
-
e.length > 1 &&
|
|
73
|
-
e.includes(iden) &&
|
|
74
|
-
(e.match(/\*\*/g) || []).length == 1
|
|
75
|
-
) {
|
|
76
|
-
if (loopCounter == singleStericCounter && loopCounter % 2 == 0) {
|
|
77
|
-
} else {
|
|
78
|
-
if (flag == "1") {
|
|
79
|
-
e = e.replace(/\*\*/g, "<" + tag + ">");
|
|
80
|
-
flag = "2";
|
|
81
|
-
} else {
|
|
82
|
-
e = e.replace(/\*\*/g, "</" + tag + ">");
|
|
83
|
-
flag = "1";
|
|
84
|
-
}
|
|
85
|
-
++loopCounter;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (e.length > 1 && (e.match(/\*\*/g) || []).length > 1) {
|
|
89
|
-
const n = (e.match(/\*\*/g) || []).length;
|
|
90
|
-
|
|
91
|
-
for (let i = 0; i < n; i++) {
|
|
92
|
-
if (i == 0) {
|
|
93
|
-
box.push(e.indexOf(iden, i));
|
|
94
|
-
} else {
|
|
95
|
-
let len = box.length - 1;
|
|
96
|
-
let v = box[len];
|
|
97
|
-
v = v + 1;
|
|
98
|
-
box.push(e.indexOf(iden, v));
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
e = e.replace('**', "<" + tag + ">");
|
|
102
|
-
e = e.replace('**', "</" + tag + ">");
|
|
103
|
-
box = [];
|
|
104
|
-
}
|
|
105
|
-
arr.push(e);
|
|
106
|
-
});
|
|
107
|
-
arr.forEach(function (e) {
|
|
108
|
-
if (e == "") {
|
|
109
|
-
finalText = finalText + space;
|
|
110
|
-
} else {
|
|
111
|
-
finalText = finalText + e + space;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
return finalText;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
function astericHandler(text, tag, iden, trim, space) {
|
|
120
|
-
let box = [];
|
|
121
|
-
let arr = [];
|
|
122
|
-
let finalText = "";
|
|
123
|
-
let a = text.split(" ");
|
|
124
|
-
let singleStericCounter = 0;
|
|
125
|
-
a.forEach(function (e) {
|
|
126
|
-
if (
|
|
127
|
-
e.length > 1 &&
|
|
128
|
-
e.includes(iden) &&
|
|
129
|
-
(e.match(/\x2a/g) || []).length == 1
|
|
130
|
-
) {
|
|
131
|
-
++singleStericCounter;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
singleStericCounter = singleStericCounter - 1;
|
|
135
|
-
let flag = "1";
|
|
136
|
-
let loopCounter = 0;
|
|
137
|
-
a.forEach(function (e) {
|
|
138
|
-
if (
|
|
139
|
-
e.length > 1 &&
|
|
140
|
-
e.includes(iden) &&
|
|
141
|
-
(e.match(/\x2a/g) || []).length == 1
|
|
142
|
-
) {
|
|
143
|
-
if (loopCounter == singleStericCounter && loopCounter % 2 == 0) {
|
|
144
|
-
} else {
|
|
145
|
-
if (flag == "1") {
|
|
146
|
-
e = e.replace(/\x2a/g, "<" + tag + ">");
|
|
147
|
-
flag = "2";
|
|
148
|
-
} else {
|
|
149
|
-
e = e.replace(/\x2a/g, "</" + tag + ">");
|
|
150
|
-
flag = "1";
|
|
151
|
-
}
|
|
152
|
-
++loopCounter;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (e.length > 1 && (e.match(/\x2a/g) || []).length > 1) {
|
|
157
|
-
const n = (e.match(/\x2a/g) || []).length;
|
|
158
|
-
|
|
159
|
-
for (let i = 0; i < n; i++) {
|
|
160
|
-
if (i == 0) {
|
|
161
|
-
box.push(e.indexOf(iden, i));
|
|
162
|
-
} else {
|
|
163
|
-
let len = box.length - 1;
|
|
164
|
-
let v = box[len];
|
|
165
|
-
v = v + 1;
|
|
166
|
-
box.push(e.indexOf(iden, v));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
let firstIndex = box[0];
|
|
170
|
-
let lastIndex = box[box.length - 1];
|
|
171
|
-
e = replaceChar(e, "<" + tag + ">", firstIndex);
|
|
172
|
-
e = replaceChar(e, "</" + tag + ">", lastIndex + trim);
|
|
173
|
-
box = [];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
arr.push(e);
|
|
177
|
-
});
|
|
178
|
-
arr.forEach(function (e) {
|
|
179
|
-
if (e == "") {
|
|
180
|
-
finalText = finalText + space;
|
|
181
|
-
} else {
|
|
182
|
-
finalText = finalText + e + space;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
function replaceChar(origString, replaceChar, index) {
|
|
186
|
-
let firstPart = origString.substr(0, index);
|
|
187
|
-
let lastPart = origString.substr(index + 1);
|
|
188
|
-
|
|
189
|
-
let newString = firstPart + replaceChar + lastPart;
|
|
190
|
-
return newString;
|
|
191
|
-
}
|
|
192
|
-
return finalText;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
function getFormat(text, tag, iden, trim, space) {
|
|
197
|
-
let box = [];
|
|
198
|
-
let arr = [];
|
|
199
|
-
let finalText = "";
|
|
200
|
-
let a = text.split(" ");
|
|
201
|
-
let singleStericCounter = 0;
|
|
202
|
-
a.forEach(function (e) {
|
|
203
|
-
if (
|
|
204
|
-
e.length > 1 &&
|
|
205
|
-
e.includes(iden) &&
|
|
206
|
-
(e.match(new RegExp(iden, "g")) || []).length == 1
|
|
207
|
-
) {
|
|
208
|
-
++singleStericCounter;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
singleStericCounter = singleStericCounter - 1;
|
|
212
|
-
let flag = "1";
|
|
213
|
-
let loopCounter = 0;
|
|
214
|
-
a.forEach(function (e) {
|
|
215
|
-
if (
|
|
216
|
-
e.length > 1 &&
|
|
217
|
-
e.includes(iden) &&
|
|
218
|
-
(e.match(new RegExp(iden, "g")) || []).length == 1
|
|
219
|
-
) {
|
|
220
|
-
if (loopCounter == singleStericCounter && loopCounter % 2 == 0) {
|
|
221
|
-
} else {
|
|
222
|
-
if (flag == "1") {
|
|
223
|
-
e = e.replace(new RegExp(iden, "g"), "<" + tag + ">");
|
|
224
|
-
flag = "2";
|
|
225
|
-
} else {
|
|
226
|
-
e = e.replace(new RegExp(iden, "g"), "</" + tag + ">");
|
|
227
|
-
flag = "1";
|
|
228
|
-
}
|
|
229
|
-
++loopCounter;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (e.length > 1 && (e.match(new RegExp(iden, "g")) || []).length > 1) {
|
|
233
|
-
const n = (e.match(new RegExp(iden, "g")) || []).length;
|
|
234
|
-
|
|
235
|
-
for (let i = 0; i < n; i++) {
|
|
236
|
-
if (i == 0) {
|
|
237
|
-
box.push(e.indexOf(iden, i));
|
|
238
|
-
} else {
|
|
239
|
-
let len = box.length - 1;
|
|
240
|
-
let v = box[len];
|
|
241
|
-
v = v + 1;
|
|
242
|
-
box.push(e.indexOf(iden, v));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
let firstIndex = box[0];
|
|
246
|
-
let lastIndex = box[box.length - 1];
|
|
247
|
-
|
|
248
|
-
e = replaceChar(e, "<" + tag + ">", firstIndex);
|
|
249
|
-
e = replaceChar(e, "</" + tag + ">", lastIndex + trim);
|
|
250
|
-
|
|
251
|
-
box = [];
|
|
252
|
-
}
|
|
253
|
-
arr.push(e);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
arr.forEach(function (e) {
|
|
257
|
-
if (e == "") {
|
|
258
|
-
finalText = finalText + space;
|
|
259
|
-
} else {
|
|
260
|
-
finalText = finalText + e + space;
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
function replaceChar(origString, replaceChar, index) {
|
|
264
|
-
let firstPart = origString.substr(0, index);
|
|
265
|
-
let lastPart = origString.substr(index + 1);
|
|
266
|
-
|
|
267
|
-
let newString = firstPart + replaceChar + lastPart;
|
|
268
|
-
return newString;
|
|
269
|
-
}
|
|
270
|
-
return finalText;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function linkfy(text, target) {
|
|
274
|
-
let strictUrlExpression = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/gi;
|
|
275
|
-
let looseUrlExpression = /^https?\:\/\/[^\/\s]+(\/.*)?$/;
|
|
276
|
-
let ip4Expression = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9]+\b(\/[-a-zA-Z0-9@:%_\+.~#?&\/=]*)?/g;
|
|
277
|
-
let emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
278
|
-
let httpVerify = /^((http|https|ftp):\/\/)/;
|
|
279
|
-
let strictUrlRegex = new RegExp(strictUrlExpression);
|
|
280
|
-
let looseUrlRegex = new RegExp(looseUrlExpression);
|
|
281
|
-
let ip4Regex = new RegExp(ip4Expression);
|
|
282
|
-
let emailRegexx = new RegExp(emailRegex);
|
|
283
|
-
let a = text.split(" ");
|
|
284
|
-
let finalText = "";
|
|
285
|
-
a.map(function (part, index) {
|
|
286
|
-
if (part != " " && part != "" && part != undefined && part != "<br>") {
|
|
287
|
-
if (part.match(emailRegexx)) {
|
|
288
|
-
let ref = part;
|
|
289
|
-
ref = ref.replace(/<[^>]*>?/gm, "");
|
|
290
|
-
a[index] = "<a href='mailto:" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
291
|
-
} else if (part.match(looseUrlRegex)) {
|
|
292
|
-
let ref = part;
|
|
293
|
-
ref = ref.replace(/<[^>]*>?/gm, "");
|
|
294
|
-
a[index] = "<a href='" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
295
|
-
} else if (part.match(strictUrlRegex)) {
|
|
296
|
-
let ref = part;
|
|
297
|
-
ref = ref.replace(/<[^>]*>?/gm, "");
|
|
298
|
-
if (ref.match(httpVerify)) {
|
|
299
|
-
a[index] = "<a href='" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
300
|
-
} else {
|
|
301
|
-
a[index] = "<a href='http://" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
302
|
-
}
|
|
303
|
-
} else if (part.match(ip4Regex)) {
|
|
304
|
-
let ref = part;
|
|
305
|
-
ref = ref.replace(/<[^>]*>?/gm, "");
|
|
306
|
-
a[index] = "<a href='http://" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
a.forEach(function (e) {
|
|
311
|
-
if (e == "") {
|
|
312
|
-
finalText = finalText + " ";
|
|
313
|
-
} else {
|
|
314
|
-
finalText = finalText + e + " ";
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
return finalText;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
module.exports.ibsFormat = ibsFormat;
|
|
1
|
+
function ibsFormat(value, arr, linky, escaping) {
|
|
2
|
+
let output = null;
|
|
3
|
+
escaping = escaping && escaping.allowXssEscaping == false ? false : true;
|
|
4
|
+
if (value) {
|
|
5
|
+
if (escaping) {
|
|
6
|
+
value = value.replace(/</g, "<");
|
|
7
|
+
value = value.replace(/>/g, ">");
|
|
8
|
+
}
|
|
9
|
+
value = value.replace(/\n/g, " <br> ");
|
|
10
|
+
}
|
|
11
|
+
if (value != "" && value != null && value != undefined && arr && arr.length > 0) {
|
|
12
|
+
if (arr[0].constructor === Array) {
|
|
13
|
+
arr.map(function (e) {
|
|
14
|
+
e[2] = (e[0].length + 1).toString();
|
|
15
|
+
if (e[1] == "*") {
|
|
16
|
+
value = astericHandler(value, e[0], e[1], parseInt(e[2]), " ");
|
|
17
|
+
} else if (e[1] == '**') {
|
|
18
|
+
value = doubleAstericHandler(value, e[0], e[1], parseInt(e[2]), " ");
|
|
19
|
+
} else {
|
|
20
|
+
value = getFormat(value, e[0], e[1], parseInt(e[2]), " ");
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
arr[2] = (arr[0].length + 1).toString();
|
|
25
|
+
if (arr[1] == "*") {
|
|
26
|
+
value = astericHandler(value, arr[0], arr[1], parseInt(arr[2]), " ");
|
|
27
|
+
} else if (arr[1] == '**') {
|
|
28
|
+
value = doubleAstericHandler(value, arr[0], arr[1], parseInt(arr[2]), " ");
|
|
29
|
+
} else {
|
|
30
|
+
value = getFormat(value, arr[0], arr[1], parseInt(arr[2]), " ");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
output = value;
|
|
34
|
+
} else {
|
|
35
|
+
output = null;
|
|
36
|
+
}
|
|
37
|
+
if (value != "" && value != null && value != undefined && linky && linky.detectLinks == true) {
|
|
38
|
+
let targ;
|
|
39
|
+
if (linky.target != null && linky.target != "") {
|
|
40
|
+
targ = linky.target;
|
|
41
|
+
} else {
|
|
42
|
+
targ = "_self";
|
|
43
|
+
}
|
|
44
|
+
output = linkfy(value, targ);
|
|
45
|
+
}
|
|
46
|
+
if (output) {
|
|
47
|
+
output = output.replace(/ <br> /g, "<br>");
|
|
48
|
+
}
|
|
49
|
+
return output ? output.trim() : "";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function doubleAstericHandler(text, tag, iden, trim, space) {
|
|
53
|
+
let box = [];
|
|
54
|
+
let arr = [];
|
|
55
|
+
let finalText = "";
|
|
56
|
+
let a = text.split(" ");
|
|
57
|
+
let singleStericCounter = 0;
|
|
58
|
+
a.forEach(function (e) {
|
|
59
|
+
if (
|
|
60
|
+
e.length > 1 &&
|
|
61
|
+
e.includes(iden) &&
|
|
62
|
+
(e.match(/\*\*/g) || []).length == 1
|
|
63
|
+
) {
|
|
64
|
+
++singleStericCounter;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
singleStericCounter = singleStericCounter - 1;
|
|
68
|
+
let flag = "1";
|
|
69
|
+
let loopCounter = 0;
|
|
70
|
+
a.forEach(function (e) {
|
|
71
|
+
if (
|
|
72
|
+
e.length > 1 &&
|
|
73
|
+
e.includes(iden) &&
|
|
74
|
+
(e.match(/\*\*/g) || []).length == 1
|
|
75
|
+
) {
|
|
76
|
+
if (loopCounter == singleStericCounter && loopCounter % 2 == 0) {
|
|
77
|
+
} else {
|
|
78
|
+
if (flag == "1") {
|
|
79
|
+
e = e.replace(/\*\*/g, "<" + tag + ">");
|
|
80
|
+
flag = "2";
|
|
81
|
+
} else {
|
|
82
|
+
e = e.replace(/\*\*/g, "</" + tag + ">");
|
|
83
|
+
flag = "1";
|
|
84
|
+
}
|
|
85
|
+
++loopCounter;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (e.length > 1 && (e.match(/\*\*/g) || []).length > 1) {
|
|
89
|
+
const n = (e.match(/\*\*/g) || []).length;
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < n; i++) {
|
|
92
|
+
if (i == 0) {
|
|
93
|
+
box.push(e.indexOf(iden, i));
|
|
94
|
+
} else {
|
|
95
|
+
let len = box.length - 1;
|
|
96
|
+
let v = box[len];
|
|
97
|
+
v = v + 1;
|
|
98
|
+
box.push(e.indexOf(iden, v));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
e = e.replace('**', "<" + tag + ">");
|
|
102
|
+
e = e.replace('**', "</" + tag + ">");
|
|
103
|
+
box = [];
|
|
104
|
+
}
|
|
105
|
+
arr.push(e);
|
|
106
|
+
});
|
|
107
|
+
arr.forEach(function (e) {
|
|
108
|
+
if (e == "") {
|
|
109
|
+
finalText = finalText + space;
|
|
110
|
+
} else {
|
|
111
|
+
finalText = finalText + e + space;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return finalText;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
function astericHandler(text, tag, iden, trim, space) {
|
|
120
|
+
let box = [];
|
|
121
|
+
let arr = [];
|
|
122
|
+
let finalText = "";
|
|
123
|
+
let a = text.split(" ");
|
|
124
|
+
let singleStericCounter = 0;
|
|
125
|
+
a.forEach(function (e) {
|
|
126
|
+
if (
|
|
127
|
+
e.length > 1 &&
|
|
128
|
+
e.includes(iden) &&
|
|
129
|
+
(e.match(/\x2a/g) || []).length == 1
|
|
130
|
+
) {
|
|
131
|
+
++singleStericCounter;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
singleStericCounter = singleStericCounter - 1;
|
|
135
|
+
let flag = "1";
|
|
136
|
+
let loopCounter = 0;
|
|
137
|
+
a.forEach(function (e) {
|
|
138
|
+
if (
|
|
139
|
+
e.length > 1 &&
|
|
140
|
+
e.includes(iden) &&
|
|
141
|
+
(e.match(/\x2a/g) || []).length == 1
|
|
142
|
+
) {
|
|
143
|
+
if (loopCounter == singleStericCounter && loopCounter % 2 == 0) {
|
|
144
|
+
} else {
|
|
145
|
+
if (flag == "1") {
|
|
146
|
+
e = e.replace(/\x2a/g, "<" + tag + ">");
|
|
147
|
+
flag = "2";
|
|
148
|
+
} else {
|
|
149
|
+
e = e.replace(/\x2a/g, "</" + tag + ">");
|
|
150
|
+
flag = "1";
|
|
151
|
+
}
|
|
152
|
+
++loopCounter;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (e.length > 1 && (e.match(/\x2a/g) || []).length > 1) {
|
|
157
|
+
const n = (e.match(/\x2a/g) || []).length;
|
|
158
|
+
|
|
159
|
+
for (let i = 0; i < n; i++) {
|
|
160
|
+
if (i == 0) {
|
|
161
|
+
box.push(e.indexOf(iden, i));
|
|
162
|
+
} else {
|
|
163
|
+
let len = box.length - 1;
|
|
164
|
+
let v = box[len];
|
|
165
|
+
v = v + 1;
|
|
166
|
+
box.push(e.indexOf(iden, v));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let firstIndex = box[0];
|
|
170
|
+
let lastIndex = box[box.length - 1];
|
|
171
|
+
e = replaceChar(e, "<" + tag + ">", firstIndex);
|
|
172
|
+
e = replaceChar(e, "</" + tag + ">", lastIndex + trim);
|
|
173
|
+
box = [];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
arr.push(e);
|
|
177
|
+
});
|
|
178
|
+
arr.forEach(function (e) {
|
|
179
|
+
if (e == "") {
|
|
180
|
+
finalText = finalText + space;
|
|
181
|
+
} else {
|
|
182
|
+
finalText = finalText + e + space;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
function replaceChar(origString, replaceChar, index) {
|
|
186
|
+
let firstPart = origString.substr(0, index);
|
|
187
|
+
let lastPart = origString.substr(index + 1);
|
|
188
|
+
|
|
189
|
+
let newString = firstPart + replaceChar + lastPart;
|
|
190
|
+
return newString;
|
|
191
|
+
}
|
|
192
|
+
return finalText;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
function getFormat(text, tag, iden, trim, space) {
|
|
197
|
+
let box = [];
|
|
198
|
+
let arr = [];
|
|
199
|
+
let finalText = "";
|
|
200
|
+
let a = text.split(" ");
|
|
201
|
+
let singleStericCounter = 0;
|
|
202
|
+
a.forEach(function (e) {
|
|
203
|
+
if (
|
|
204
|
+
e.length > 1 &&
|
|
205
|
+
e.includes(iden) &&
|
|
206
|
+
(e.match(new RegExp(iden, "g")) || []).length == 1
|
|
207
|
+
) {
|
|
208
|
+
++singleStericCounter;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
singleStericCounter = singleStericCounter - 1;
|
|
212
|
+
let flag = "1";
|
|
213
|
+
let loopCounter = 0;
|
|
214
|
+
a.forEach(function (e) {
|
|
215
|
+
if (
|
|
216
|
+
e.length > 1 &&
|
|
217
|
+
e.includes(iden) &&
|
|
218
|
+
(e.match(new RegExp(iden, "g")) || []).length == 1
|
|
219
|
+
) {
|
|
220
|
+
if (loopCounter == singleStericCounter && loopCounter % 2 == 0) {
|
|
221
|
+
} else {
|
|
222
|
+
if (flag == "1") {
|
|
223
|
+
e = e.replace(new RegExp(iden, "g"), "<" + tag + ">");
|
|
224
|
+
flag = "2";
|
|
225
|
+
} else {
|
|
226
|
+
e = e.replace(new RegExp(iden, "g"), "</" + tag + ">");
|
|
227
|
+
flag = "1";
|
|
228
|
+
}
|
|
229
|
+
++loopCounter;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (e.length > 1 && (e.match(new RegExp(iden, "g")) || []).length > 1) {
|
|
233
|
+
const n = (e.match(new RegExp(iden, "g")) || []).length;
|
|
234
|
+
|
|
235
|
+
for (let i = 0; i < n; i++) {
|
|
236
|
+
if (i == 0) {
|
|
237
|
+
box.push(e.indexOf(iden, i));
|
|
238
|
+
} else {
|
|
239
|
+
let len = box.length - 1;
|
|
240
|
+
let v = box[len];
|
|
241
|
+
v = v + 1;
|
|
242
|
+
box.push(e.indexOf(iden, v));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
let firstIndex = box[0];
|
|
246
|
+
let lastIndex = box[box.length - 1];
|
|
247
|
+
|
|
248
|
+
e = replaceChar(e, "<" + tag + ">", firstIndex);
|
|
249
|
+
e = replaceChar(e, "</" + tag + ">", lastIndex + trim);
|
|
250
|
+
|
|
251
|
+
box = [];
|
|
252
|
+
}
|
|
253
|
+
arr.push(e);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
arr.forEach(function (e) {
|
|
257
|
+
if (e == "") {
|
|
258
|
+
finalText = finalText + space;
|
|
259
|
+
} else {
|
|
260
|
+
finalText = finalText + e + space;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
function replaceChar(origString, replaceChar, index) {
|
|
264
|
+
let firstPart = origString.substr(0, index);
|
|
265
|
+
let lastPart = origString.substr(index + 1);
|
|
266
|
+
|
|
267
|
+
let newString = firstPart + replaceChar + lastPart;
|
|
268
|
+
return newString;
|
|
269
|
+
}
|
|
270
|
+
return finalText;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function linkfy(text, target) {
|
|
274
|
+
let strictUrlExpression = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/gi;
|
|
275
|
+
let looseUrlExpression = /^https?\:\/\/[^\/\s]+(\/.*)?$/;
|
|
276
|
+
let ip4Expression = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9]+\b(\/[-a-zA-Z0-9@:%_\+.~#?&\/=]*)?/g;
|
|
277
|
+
let emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
278
|
+
let httpVerify = /^((http|https|ftp):\/\/)/;
|
|
279
|
+
let strictUrlRegex = new RegExp(strictUrlExpression);
|
|
280
|
+
let looseUrlRegex = new RegExp(looseUrlExpression);
|
|
281
|
+
let ip4Regex = new RegExp(ip4Expression);
|
|
282
|
+
let emailRegexx = new RegExp(emailRegex);
|
|
283
|
+
let a = text.split(" ");
|
|
284
|
+
let finalText = "";
|
|
285
|
+
a.map(function (part, index) {
|
|
286
|
+
if (part != " " && part != "" && part != undefined && part != "<br>") {
|
|
287
|
+
if (part.match(emailRegexx)) {
|
|
288
|
+
let ref = part;
|
|
289
|
+
ref = ref.replace(/<[^>]*>?/gm, "");
|
|
290
|
+
a[index] = "<a href='mailto:" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
291
|
+
} else if (part.match(looseUrlRegex)) {
|
|
292
|
+
let ref = part;
|
|
293
|
+
ref = ref.replace(/<[^>]*>?/gm, "");
|
|
294
|
+
a[index] = "<a href='" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
295
|
+
} else if (part.match(strictUrlRegex)) {
|
|
296
|
+
let ref = part;
|
|
297
|
+
ref = ref.replace(/<[^>]*>?/gm, "");
|
|
298
|
+
if (ref.match(httpVerify)) {
|
|
299
|
+
a[index] = "<a href='" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
300
|
+
} else {
|
|
301
|
+
a[index] = "<a href='http://" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
302
|
+
}
|
|
303
|
+
} else if (part.match(ip4Regex)) {
|
|
304
|
+
let ref = part;
|
|
305
|
+
ref = ref.replace(/<[^>]*>?/gm, "");
|
|
306
|
+
a[index] = "<a href='http://" + ref + "' target='" + target + "'>" + part + "</a>";
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
a.forEach(function (e) {
|
|
311
|
+
if (e == "") {
|
|
312
|
+
finalText = finalText + " ";
|
|
313
|
+
} else {
|
|
314
|
+
finalText = finalText + e + " ";
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
return finalText;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
module.exports.ibsFormat = ibsFormat;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ibs-format",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.11",
|
|
4
4
|
"description": "Detect the user-defined identifiers in the text and convert them into HTML tags like bold, italic, strike, and many more having XSS (Cross-site scripting) security with escaping functionality, also detect the links like URLs, email, and IP addresses and wrap them into Anchor tag `<a>`.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|