ponkotsu-md-editor 0.1.34 → 0.1.36
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/markdown_editor.js +30 -55
- data/lib/ponkotsu/md/editor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f9abdf49ca94ffd0c36c71abcfddbb6f7a0f0717620b01930e8795546501c1d
|
|
4
|
+
data.tar.gz: 653a957629e983ee7fd9087fe0fa6af62bb634eed6a6c8147eca5bc0d762fb31
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f905adc11cc36ec45f45b036881fed68aa8639054fba7d6e0b00394cea95d6e7cce14d9b225e34156c95fe34771adc0dee121804ab5e3883cdc9258ad229f87
|
|
7
|
+
data.tar.gz: ae80ec886bc51492859e2a698dd9320078ed384b186f151508184d5df69c15115d5d08ff7c4a44434b28a4aef7df4ae49e673a5ca66aba895f1dc37f4a331811
|
|
@@ -288,63 +288,14 @@
|
|
|
288
288
|
(textarea.innerText || textarea.textContent || '') :
|
|
289
289
|
textarea.value;
|
|
290
290
|
|
|
291
|
-
// Bold
|
|
291
|
+
// Bold(**)の場合のみ、選択範囲の両端に余分な空白・改行・文末記号があれば除外
|
|
292
292
|
if (before === '**' && after === '**' && selectedText.length > 0) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
while (true) {
|
|
297
|
-
if (selectedText.startsWith('\n ')) {
|
|
298
|
-
left += 2;
|
|
299
|
-
selectedText = selectedText.substring(2);
|
|
300
|
-
} else if (selectedText.startsWith('\n')) {
|
|
301
|
-
left += 1;
|
|
302
|
-
selectedText = selectedText.substring(1);
|
|
303
|
-
} else if (selectedText.startsWith(' ')) {
|
|
304
|
-
// 直前が改行なら除去
|
|
305
|
-
if (start + left > 0 && fullText[start + left - 1] === '\n') {
|
|
306
|
-
left += 1;
|
|
307
|
-
selectedText = selectedText.substring(1);
|
|
308
|
-
} else {
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
} else {
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
// 末尾: 連続する「スペース+改行」をすべて除去
|
|
316
|
-
while (true) {
|
|
317
|
-
if (selectedText.endsWith(' \n')) {
|
|
318
|
-
right -= 2;
|
|
319
|
-
selectedText = selectedText.substring(0, selectedText.length - 2);
|
|
320
|
-
} else if (selectedText.endsWith('\n')) {
|
|
321
|
-
right -= 1;
|
|
322
|
-
selectedText = selectedText.substring(0, selectedText.length - 1);
|
|
323
|
-
} else if (selectedText.endsWith(' ')) {
|
|
324
|
-
// 直後が改行なら除去
|
|
325
|
-
if (end - (selectedText.length - right) < fullText.length && fullText[end - (selectedText.length - right)] === '\n') {
|
|
326
|
-
right -= 1;
|
|
327
|
-
selectedText = selectedText.substring(0, selectedText.length - 1);
|
|
328
|
-
} else {
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
} else {
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
// 既存の両端trimも併用(ただしスペース・改行のみ)
|
|
336
|
-
while (left < right && /[\s\n]/.test(selectedText[0])) {
|
|
337
|
-
left++;
|
|
338
|
-
selectedText = selectedText.substring(1);
|
|
293
|
+
// 両端の「改行・空白・文末記号」をすべて除去(複数連続も対応)
|
|
294
|
+
while (/^[\s\n.,;:!?]+/.test(selectedText)) {
|
|
295
|
+
selectedText = selectedText.replace(/^[\s\n.,;:!?]+/, '');
|
|
339
296
|
}
|
|
340
|
-
while (
|
|
341
|
-
|
|
342
|
-
selectedText = selectedText.substring(0, selectedText.length-1);
|
|
343
|
-
}
|
|
344
|
-
if (left !== 0 || right !== selectedText.length) {
|
|
345
|
-
start += left;
|
|
346
|
-
end -= (selectedText.length - right);
|
|
347
|
-
// selectedTextはすでにtrim済み
|
|
297
|
+
while (/[\s\n.,;:!?]+$/.test(selectedText)) {
|
|
298
|
+
selectedText = selectedText.replace(/[\s\n.,;:!?]+$/, '');
|
|
348
299
|
}
|
|
349
300
|
}
|
|
350
301
|
|
|
@@ -1487,4 +1438,28 @@
|
|
|
1487
1438
|
}
|
|
1488
1439
|
});
|
|
1489
1440
|
|
|
1441
|
+
// === テスト用関数群 ===
|
|
1442
|
+
// 1. 選択範囲検出
|
|
1443
|
+
window.testGetSelection = function(element) {
|
|
1444
|
+
return getContentEditableSelection(element);
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
// 2. Boldデコレーション(両端trim含む)
|
|
1448
|
+
window.testDecorateBold = function(text) {
|
|
1449
|
+
// 両端の「改行・空白・文末記号」をすべて除去(複数連続も対応)
|
|
1450
|
+
let trimmed = text;
|
|
1451
|
+
while (/^[\s\n.,;:!?]+/.test(trimmed)) {
|
|
1452
|
+
trimmed = trimmed.replace(/^[\s\n.,;:!?]+/, '');
|
|
1453
|
+
}
|
|
1454
|
+
while (/[\s\n.,;:!?]+$/.test(trimmed)) {
|
|
1455
|
+
trimmed = trimmed.replace(/[\s\n.,;:!?]+$/, '');
|
|
1456
|
+
}
|
|
1457
|
+
return `**${trimmed}**`;
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
// 3. テキスト上書き
|
|
1461
|
+
window.testReplaceTextAtRange = function(fullText, start, end, decoratedText) {
|
|
1462
|
+
return fullText.substring(0, start) + decoratedText + fullText.substring(end);
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1490
1465
|
})();
|