From 5c3449d6c2e05fd3280dfe3f4907cd3fa3b36618 Mon Sep 17 00:00:00 2001 From: Nick Shirokov Date: Thu, 6 Aug 2026 21:01:45 +0300 Subject: [PATCH] =?UTF-8?q?feat(mxl-compile):=20=D0=BE=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0?= =?UTF-8?q?=20+=20xmlns:pal=20=D0=B2=202.21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit У корня нет атрибута version, поэтому версия берётся из конфигурации, в дерево которой пишется макет (подъём до Configuration.xml, как в остальных навыках); вне конфигурации остаётся прежнее поведение — 2.17. Платформа 8.5 объявляет палитру и в теле MXL: в выгрузке УНФ 8.5 xmlns:pal стоит у всех 3471 файлов с корнем document. Co-Authored-By: Claude Opus 5 (1M context) --- .../mxl-compile/scripts/mxl-compile.ps1 | 42 ++++++++++++++++++- .../skills/mxl-compile/scripts/mxl-compile.py | 41 +++++++++++++++++- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/.claude/skills/mxl-compile/scripts/mxl-compile.ps1 b/.claude/skills/mxl-compile/scripts/mxl-compile.ps1 index 3cfe20a0..fb8a4275 100644 --- a/.claude/skills/mxl-compile/scripts/mxl-compile.ps1 +++ b/.claude/skills/mxl-compile/scripts/mxl-compile.ps1 @@ -1,4 +1,4 @@ -# mxl-compile v1.8 — Compile 1C spreadsheet from JSON +# mxl-compile v1.9 — Compile 1C spreadsheet from JSON # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills param( [Parameter(Mandatory)] @@ -142,6 +142,38 @@ function Assert-EditAllowed([string]$targetPath, [string]$require) { } catch { return } } +# --- Detect XML format version --- +# У корня нет атрибута version, поэтому версию берём из конфигурации, в дерево +# которой пишем макет. Вне конфигурации (автономный .xml, исходники EPF) остаётся 2.17. + +function Detect-FormatVersion([string]$dir) { + $d = $dir + while ($d) { + $cfgPath = Join-Path $d "Configuration.xml" + if (Test-Path $cfgPath) { + $cfgText = [System.IO.File]::ReadAllText($cfgPath, [System.Text.Encoding]::UTF8) + # Длину среза берём по СТРОКЕ, а не по размеру файла: размер в БАЙТАХ, Substring считает + # СИМВОЛЫ, и на кириллице байт больше — короткий Configuration.xml ронял навык исключением. + $head = $cfgText.Substring(0, [Math]::Min(2000, $cfgText.Length)) + if ($head -match ']+version="(\d+\.\d+)"') { return $Matches[1] } + } + $parent = Split-Path $d -Parent + if ($parent -eq $d) { break } + $d = $parent + } + return "2.17" +} + +# Версия формата как число для сравнений: "2.20" → 220, "2.9" → 209. +# Строковое сравнение здесь неверно ("2.9" > "2.17" лексикографически) — известная ловушка. +function Get-FormatRank([string]$ver) { + if ($ver -match '^(\d+)\.(\d+)$') { return [int]$Matches[1] * 100 + [int]$Matches[2] } + return 0 +} + +$script:outPathResolved = if ([System.IO.Path]::IsPathRooted($OutputPath)) { $OutputPath } else { Join-Path (Get-Location) $OutputPath } +$script:formatVersion = Detect-FormatVersion ([System.IO.Path]::GetDirectoryName($script:outPathResolved)) + # --- 1. Load and validate JSON --- if (-not (Test-Path $JsonPath)) { @@ -512,8 +544,14 @@ function X { } # 7a. Header +$docNsDecl = 'xmlns="http://v8.1c.ru/8.2/data/spreadsheet" xmlns:style="http://v8.1c.ru/8.1/data/ui/style" xmlns:v8="http://v8.1c.ru/8.1/data/core" xmlns:v8ui="http://v8.1c.ru/8.1/data/ui" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +# 2.21 (8.5) добавила в шапку пространство палитры. Вставляем НА МЕСТО (перед style): +# платформа держит объявления по алфавиту, дописать в конец нельзя. +if ((Get-FormatRank $script:formatVersion) -ge 221) { + $docNsDecl = $docNsDecl -replace ' xmlns:style=', ' xmlns:pal="http://v8.1c.ru/8.1/data/ui/colors/palette" xmlns:style=' +} X '' -X '' +X "" # 7b. Language settings X "`t" diff --git a/.claude/skills/mxl-compile/scripts/mxl-compile.py b/.claude/skills/mxl-compile/scripts/mxl-compile.py index 6996a0c0..9971d66b 100644 --- a/.claude/skills/mxl-compile/scripts/mxl-compile.py +++ b/.claude/skills/mxl-compile/scripts/mxl-compile.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# mxl-compile v1.8 — Compile 1C spreadsheet from JSON +# mxl-compile v1.9 — Compile 1C spreadsheet from JSON # Source: https://github.com/Nikolay-Shirokov/cc-1c-skills import argparse import json @@ -198,6 +198,28 @@ def write_utf8_bom(path, content): f.write(content) +def detect_format_version(d): + while d: + cfg_path = os.path.join(d, "Configuration.xml") + if os.path.isfile(cfg_path): + with open(cfg_path, "r", encoding="utf-8-sig") as f: + head = f.read(2000) + m = re.search(r']+version="(\d+\.\d+)"', head) + if m: + return m.group(1) + parent = os.path.dirname(d) + if parent == d: + break + d = parent + return "2.17" + + +def format_rank(ver): + """"2.20" → 220, "2.9" → 209. Строковое сравнение неверно ("2.9" > "2.17").""" + m = re.match(r'^(\d+)\.(\d+)$', ver or '') + return int(m.group(1)) * 100 + int(m.group(2)) if m else 0 + + def main(): sys.stdout.reconfigure(encoding="utf-8") sys.stderr.reconfigure(encoding="utf-8") @@ -206,6 +228,12 @@ def main(): parser.add_argument('-OutputPath', type=str, required=True) args = parser.parse_args() + # --- Detect XML format version --- + # У корня нет атрибута version, поэтому версию берём из конфигурации, в дерево + # которой пишем макет. Вне конфигурации (автономный .xml, исходники EPF) остаётся 2.17. + out_path_resolved = args.OutputPath if os.path.isabs(args.OutputPath) else os.path.join(os.getcwd(), args.OutputPath) + format_version = detect_format_version(os.path.dirname(out_path_resolved)) + # --- 1. Load and validate JSON --- json_path = args.JsonPath if not os.path.exists(json_path): @@ -496,7 +524,16 @@ def main(): # 7a. Header lines.append('') - lines.append('') + doc_ns_decl = ('xmlns="http://v8.1c.ru/8.2/data/spreadsheet" xmlns:style="http://v8.1c.ru/8.1/data/ui/style"' + ' xmlns:v8="http://v8.1c.ru/8.1/data/core" xmlns:v8ui="http://v8.1c.ru/8.1/data/ui"' + ' xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"') + # 2.21 (8.5) добавила в шапку пространство палитры. Вставляем НА МЕСТО (перед style): + # платформа держит объявления по алфавиту, дописать в конец нельзя. + if format_rank(format_version) >= 221: + doc_ns_decl = doc_ns_decl.replace( + ' xmlns:style=', + ' xmlns:pal="http://v8.1c.ru/8.1/data/ui/colors/palette" xmlns:style=') + lines.append(f'') # 7b. Language settings lines.append('\t')