@@ -58,6 +58,12 @@ var tags = [
58
58
"formatter" : function ( part1 , part2 ) {
59
59
return "<i>Yes? No. Or is it?</i>" ;
60
60
}
61
+ } ,
62
+ {
63
+ "name" : "help" ,
64
+ "help" : true ,
65
+ "src" : "https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/icons/Development/bug-line.svg" ,
66
+ "ignore" : true
61
67
}
62
68
]
63
69
@@ -67,7 +73,10 @@ var tags = [
67
73
setTimeout ( function ( ) {
68
74
var textareaFinder = "[name=compose-comment],[name=content]" ;
69
75
70
- document . querySelectorAll ( textareaFinder ) [ 0 ] . placeholder = "Click here to activate ScratchFormat" ;
76
+ var findFirst = document . querySelectorAll ( textareaFinder ) ;
77
+ if ( findFirst . length > 0 ) {
78
+ findFirst [ 0 ] . placeholder = "Click here to activate ScratchFormat" ;
79
+ }
71
80
72
81
formatter = document . createElement ( "div" ) ;
73
82
formatter . id = "formatter" ;
@@ -78,6 +87,18 @@ setTimeout(function() {
78
87
79
88
var icon = document . createElement ( "img" ) ;
80
89
icon . src = tags [ t ] . src ;
90
+
91
+ // Help icon
92
+ if ( tags [ t ] . help ) {
93
+ icon . style . float = "right" ;
94
+ icon . onclick = function ( ) {
95
+ window . open ( "https://github.com/ScratchFormat/ScratchFormat2/issues" ) ;
96
+ }
97
+
98
+ formatter . appendChild ( icon ) ;
99
+ continue ;
100
+ }
101
+
81
102
icon . fillers = tags [ t ] . fillers ;
82
103
83
104
// This may look janky, but with Chrome extensions,
@@ -136,12 +157,15 @@ function format() {
136
157
return ;
137
158
}
138
159
139
- oldComments = comments . length
160
+ oldComments = comments . length ;
140
161
141
162
for ( var c = 0 ; c < comments . length ; c ++ ) {
142
163
comments [ c ] . style . whiteSpace = "pre-line" ;
143
- comments [ c ] . style . marginLeft = "5px" ;
144
- comments [ c ] . innerHTML = parse ( comments [ c ] . innerHTML ) ;
164
+ if ( comments [ c ] . className == "emoji-text" ) {
165
+ comments [ c ] . style . marginLeft = "5px" ;
166
+ }
167
+
168
+ comments [ c ] . innerHTML = parse ( comments [ c ] . innerText ) ;
145
169
}
146
170
}
147
171
@@ -154,6 +178,9 @@ function parse(text) {
154
178
var endBracket = "[\\)|\\]]" ;
155
179
156
180
for ( var t = 0 ; t < tags . length ; t ++ ) {
181
+ if ( tags [ t ] . ignore ) {
182
+ continue ;
183
+ }
157
184
158
185
// First part of tag
159
186
var regex = "" ;
@@ -164,8 +191,7 @@ function parse(text) {
164
191
165
192
// If just 1 tag (Ex [br])
166
193
if ( tags [ t ] . fillers . length > 1 ) {
167
- // Regex statement to parse anything but (), []
168
- regex += "([^\\)\\]\\[\\(]*)" ;
194
+ regex += "(.*)" ;
169
195
170
196
// Second part of tag
171
197
regex += startBracket ;
@@ -178,6 +204,7 @@ function parse(text) {
178
204
text = text . replace ( regex , tags [ t ] . formatter ( "$2" , "$3" ) ) ;
179
205
}
180
206
207
+ // Format trailing breaklines and spaces
181
208
text = text . replace ( / ^ ( \n | ) + / gm, "" ) ;
182
209
183
210
return text ;
0 commit comments