Skip to content
This repository was archived by the owner on Oct 28, 2022. It is now read-only.

Commit 2439632

Browse files
committed
Allow tags within tags
1 parent 5d1eb25 commit 2439632

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

ScratchFormat.zip

23.4 KB
Binary file not shown.

javascript.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ var tags = [
5858
"formatter": function(part1, part2) {
5959
return "<i>Yes? No. Or is it?</i>";
6060
}
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
6167
}
6268
]
6369

@@ -67,7 +73,10 @@ var tags = [
6773
setTimeout(function() {
6874
var textareaFinder = "[name=compose-comment],[name=content]";
6975

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+
}
7180

7281
formatter = document.createElement("div");
7382
formatter.id = "formatter";
@@ -78,6 +87,18 @@ setTimeout(function() {
7887

7988
var icon = document.createElement("img");
8089
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+
81102
icon.fillers = tags[t].fillers;
82103

83104
// This may look janky, but with Chrome extensions,
@@ -136,12 +157,15 @@ function format() {
136157
return;
137158
}
138159

139-
oldComments = comments.length
160+
oldComments = comments.length;
140161

141162
for (var c = 0; c < comments.length; c++) {
142163
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);
145169
}
146170
}
147171

@@ -154,6 +178,9 @@ function parse(text) {
154178
var endBracket = "[\\)|\\]]";
155179

156180
for (var t = 0; t < tags.length; t++) {
181+
if (tags[t].ignore) {
182+
continue;
183+
}
157184

158185
// First part of tag
159186
var regex = "";
@@ -164,8 +191,7 @@ function parse(text) {
164191

165192
// If just 1 tag (Ex [br])
166193
if (tags[t].fillers.length > 1) {
167-
// Regex statement to parse anything but (), []
168-
regex += "([^\\)\\]\\[\\(]*)";
194+
regex += "(.*)";
169195

170196
// Second part of tag
171197
regex += startBracket;
@@ -178,6 +204,7 @@ function parse(text) {
178204
text = text.replace(regex, tags[t].formatter("$2", "$3"));
179205
}
180206

207+
// Format trailing breaklines and spaces
181208
text = text.replace(/^(\n| )+/gm, "");
182209

183210
return text;

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ScratchFormat",
33
"description": "Rich text editing in Scratch.",
4-
"version": "2.0",
4+
"version": "20.0",
55
"content_scripts": [
66
{
77
"matches": ["https://scratch.mit.edu/users*","https://scratch.mit.edu/studios*", "https://scratch.mit.edu/projects*"],

popup.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ <h2>ScratchFormat 2.0</h2>
2424
background-color: lightblue;
2525
}
2626
</style>
27+
<script type="text/javascript" src="javascript.js"></script>

0 commit comments

Comments
 (0)