changeset 1054:cf0e33324a12 draft default tip

FIX: summary/detail not fired after table
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 06 Jun 2024 22:59:12 +0900
parents 1d1ee66d88ae
children
files s4-funcs.sh s4-main.js
diffstat 2 files changed, 31 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/s4-funcs.sh	Sun Jun 02 07:25:49 2024 +0900
+++ b/s4-funcs.sh	Thu Jun 06 22:59:12 2024 +0900
@@ -689,6 +689,8 @@
       -e 's,~~\([^~][^~]*\)~~,<s>\1</s>,g' \
       -e 's,\([^\\]\);;;,\1<br>,g;s,\\;;;,;;;,g' \
       -e 's,  $,<br>,' \
+      -e 's,\^{\([^\}]*\)},<sup>\1</sup>,g' \
+      -e 's,_{\([^\}]*\)},<sub>\1</sub>,g' \
       -e "s,- \[  *\]\([^|-]*\),${checkboxOFF}<label>\\1</label>,g" \
       -e "s,- \[[^ ]\]\([^|-]*\),${checkboxON}<label>\\1</label>,g" \
       
@@ -814,8 +816,8 @@
   foldprefix="<<<"
   f=`echo "$foldprefix"|htmlescape`
   sed -E \
-      -e "/^$f *(.+)/ {
-      	   s,,<details><summary>\\1</summary><div class=\"detail-content\">,
+      -e "/(^|>)$f *(.+)/ {
+      	   s,,\\1<details><summary>\\2</summary><div class=\"detail-content\">,
 	   \$ q
 	   N
 	   s/\\n//
--- a/s4-main.js	Sun Jun 02 07:25:49 2024 +0900
+++ b/s4-main.js	Thu Jun 06 22:59:12 2024 +0900
@@ -738,25 +738,42 @@
 	    e.preventDefault();
 	}
     }
-    function helpMarkdownLT(e) {
+    function helpMarkdownTriple(e, mark, defSuffix, tooltip) {
 	let area = e.target, pos=area.selectionStart, text=area.value,
 	    last = text.lastIndexOf("\n", pos-1),
 	    line = last ? text.substring(last+1, pos) : text,
 	    prev = text.substring(0, last),
-	    add1 = "< See more...",
-	    add2 = `\n\n<<<\n`;
-	if (line == "<<") {
-	    let r = prev.match(/(?<=^|\n)<<< *.*(?=\n|$)/g);
-	    if (r && r.pop() != "<<<") return; // If recent <<< is header
+	    triple = mark+mark+mark,
+	    add1 = mark+defSuffix,
+	    add2 = `\n\n${mark}${mark}${mark}`;
+	if (line == mark+mark) {		// is like "<<"
+	    let oprx = RegExp(`(?<=^|\n)${triple} *.*(?=\n|$)`, "g"),
+		clrx = RegExp(`(?<=\n)${triple} *.*(?=\n|$)`, "g"),
+		r = prev.match(oprx);
+	    if (r && r.pop() != triple) return;	// If recent <<< is header
+	    r = text.substring(pos).match(clrx);
+	    if (r && r[0] == triple) return;	// If already closed
 	    e.preventDefault();
 	    if (!document.execCommand("insertText", false, add1+add2)) {
-		// XXX: Think later...
+		//To enable undo, use deperecated function once.
+		
 	    } else {
-		area.selectionStart = area.selectionEnd = pos+add1.length+1;
-		console.log(`as=${area.selectionStart}`);
+		// setRangeText breaks undo ring...
+		area.setRangeText(add1+add2, pos, pos);
+		area.selectionStart = pos+1;
+		area.selectionEnd = pos+1+defSuffix.length;
+		if (tooltip) {
+		    dispInfoMomentary(tooltip, area.parentNode);
+		}
 	    }
 	}
     }
+    function helpMarkdownLT(e) {
+	helpMarkdownTriple(e, "<", " See more...");
+    }
+    function helpMarkdownExclamation(e) {
+	helpMarkdownTriple(e, "!", "info", "!!!info  /  !!!warn  /  !!!alert");
+    }
     function helpMarkdown(e) {
 	switch (e.key) {
 	case "Backspace": helpMarkdownBS(e); break;
@@ -767,6 +784,7 @@
 	case "}":  helpMarkdownBraceClose(e); break;
 	case "@":  helpMarkdownAt(e); break;
 	case "<":  helpMarkdownLT(e); break;
+	case "!":  helpMarkdownExclamation(e); break;
 	}
     }
     /* Init event listeners */
@@ -940,7 +958,6 @@
 	    for (i of document.querySelectorAll('input#c[value="送信"]')) {
 		let b = document.createElement("button");
 		b.textContent = "送信!";
-		console.log("b="+b+", tc="+b.textContent);
 		b.addEventListener("click", ajaxPost, false);
 		// i.insertAdjacentElement('afterend', b);
 		b.setAttribute("class", i.getAttribute("class"))

yatex.org