diff --git a/main.js b/main.js index 494c4e9..7b51fe5 100644 --- a/main.js +++ b/main.js @@ -65,9 +65,12 @@ function escHtml(s) { return String(s).replace(/&/g, '&').replace(/\s?/.test(line)) cls += ' tg-quote'; + // CommonMark: a heading counts at line start, after ≤3 leading spaces, OR inside a list item. hm[1] swallows the + // optional indent + bullet/checkbox prefix so `- ### x` / `- [ ] ### x` / ` ### x` all size+colour as headings; + // hm[2] is the # run (→ level). It's ADDITIVE with tg-li/tg-task — a heading can also be a list/task line. + const hm = /^(\s*(?:[-*]\s(?:\[[ xX]\]\s)?)?)(#{1,6})\s/.exec(line); + if (hm) cls += ' tg-h tg-h' + hm[2].length; + if (/^>\s?/.test(line)) cls += ' tg-quote'; else if (/^\s*[-*]\s/.test(line)) cls += ' tg-li'; // Each syntax marker (## , > , - , [ ], **, *, ~~, `, [[ ]], @{}) is wrapped in its own // so a host can hide JUST the markers via CSS (.tugtile-preview .tg-mk{display:none}) while the styling stays — @@ -76,7 +79,7 @@ function highlightLineParts(line) { // markers stay visible there (their 調味/原味 cycle is unchanged); only a host that opts in hides them. escHtml // has already turned a leading > into > (the quote marker), so match that form. const h = escHtml(line) - .replace(/^(#{1,6}\s)/, '$1') // heading marker + .replace(/^(\s*(?:[-*]\s(?:\[[ xX]\]\s)?)?)(#{1,6}\s)/, (m, pre, hashes) => pre + '' + hashes + '') // heading marker — wraps only the # run, leaving any indent/bullet/checkbox prefix for the rules below to wrap .replace(/^(>\s?)/, '$1') // blockquote marker .replace(/^(\s*[-*]\s)(\[[ xX]\])/, (m, p, box) => '' + p + '' + box + '') .replace(/^(\s*[-*]\s)/, '$1') // plain bullet (heading/quote/checkbox lines already start with a , so this won't match them) diff --git a/manifest.json b/manifest.json index 61f2e3b..a96dbd5 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "marktile", "name": "marktile", - "version": "0.0.63", + "version": "0.0.64", "minAppVersion": "1.4.0", "description": "A Markdown editor where the markers never hide — headings grow while ## stays put. Pairs with tugtile. CJK-friendly.", "author": "CVER Inc.", diff --git a/versions.json b/versions.json index cb8e1ae..8bbbb62 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "0.0.63": "1.4.0" + "0.0.64": "1.4.0" }