confluence-md-sync 0.8.2 → 0.8.3

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.
@@ -1472,8 +1472,32 @@ function escapeMdText(raw, ctx, readable = false) {
1472
1472
  out += escapePlain(collapsed.slice(last), ctx, readable);
1473
1473
  return out;
1474
1474
  }
1475
+ const ESCAPE_SPECIALS = '\\`*[]{}~';
1476
+ // Буква/цифра любого алфавита (вкл. кириллицу). Внутрисловное `_` между двумя
1477
+ // такими символами по CommonMark не открывает и не закрывает акцент, поэтому
1478
+ // экранировать его НЕ нужно.
1479
+ const WORDCHAR_RE = /[\p{L}\p{N}]/u;
1475
1480
  function escapePlain(s, _ctx, readable = false) {
1476
- const esc = s.replace(/[\\`*_[\]{}~]/g, (c) => '\\' + c);
1481
+ let esc = '';
1482
+ for (let i = 0; i < s.length; i++) {
1483
+ const c = s[i];
1484
+ if (c === '_') {
1485
+ // Экранируем `_` только на границе слова (snake_case НЕ трогаем — иначе
1486
+ // выходят уродливые `BA\_M1\_…`). Внутрисловное `_` литерально и в
1487
+ // CommonMark, round-trip остаётся канонически эквивалентным.
1488
+ const prev = s[i - 1];
1489
+ const next = s[i + 1];
1490
+ const intraword = prev !== undefined && next !== undefined &&
1491
+ WORDCHAR_RE.test(prev) && WORDCHAR_RE.test(next);
1492
+ esc += intraword ? '_' : '\\_';
1493
+ }
1494
+ else if (ESCAPE_SPECIALS.includes(c)) {
1495
+ esc += '\\' + c;
1496
+ }
1497
+ else {
1498
+ esc += c;
1499
+ }
1500
+ }
1477
1501
  // Пайпы здесь НЕ трогаем — они экранируются один раз на границе ячейки
1478
1502
  // (cellMd / readableTable), иначе плейсхолдеры {{img:…|…}} двоились бы.
1479
1503
  // readable: неразрывный пробел → обычный; faithful: → entity (переживает
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "confluence-md-sync",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Publish Markdown to Confluence (Data Center & Cloud): idempotent page sync, attachment dedup, tables and a pluggable macro system",
5
5
  "keywords": [
6
6
  "confluence",