md2gost 1.3.2 → 1.4.1
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.
- package/CHANGELOG.md +18 -0
- package/README.md +35 -9
- package/assets/run.ps1 +15 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +300 -41
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +302 -43
- package/dist/index.mjs.map +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
13
13
|
### Fixed
|
|
14
14
|
### Security
|
|
15
15
|
|
|
16
|
+
## [1.4.1] - 2026-09-07
|
|
17
|
+
### Fixed
|
|
18
|
+
- fix bug with image size (rem dev code from prev release)
|
|
19
|
+
|
|
20
|
+
## [1.4.0] - 2026-09-06
|
|
21
|
+
### Added
|
|
22
|
+
- totalPagesOffset property of Doc to modify TOTAL_PAGES field value (`!!rule` isn't implemented yet)
|
|
23
|
+
- make render process cancellable
|
|
24
|
+
- add `userInput` error code to `MDRenderError`
|
|
25
|
+
- add `abortSignal` property to `MDRenderConfig`
|
|
26
|
+
- add `allowExternalFiles` property to `MDRenderConfig`
|
|
27
|
+
- support page orientation (`landscape`/`portrait`) and disable numbering (`unpaged`) in `!!section` directive
|
|
28
|
+
### Changed
|
|
29
|
+
- `!!section` directive now accepts multiple optional parameters in any order (orientation and numbering)
|
|
30
|
+
### Fixed
|
|
31
|
+
- fix typos in readme
|
|
32
|
+
- fix `<br>` display in image title in preview
|
|
33
|
+
|
|
16
34
|
## [1.3.2] - 2026-07-12
|
|
17
35
|
### Added
|
|
18
36
|
* **Directory Output Support**: `renderMarkdown` now accepts directory paths for `config.output`, auto-generating the filename from the input file with the correct extension (`.pdf`/`.docx`).
|
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ md2gost report.md --format pdf
|
|
|
40
40
|
Specify an output path:
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
|
+
md2gost report.md -o dist/
|
|
43
44
|
md2gost report.md -o dist/report.docx
|
|
44
45
|
md2gost report.md -o dist/report.pdf
|
|
45
46
|
```
|
|
@@ -237,7 +238,7 @@ Without Microsoft Word, PDF export and several advanced Word-specific features a
|
|
|
237
238
|
```
|
|
238
239
|

|
|
239
240
|
|
|
240
|
-
Выделение с помощью обратных кавычек ``` `монотекст` ``` по умолчанию отображается как курсив. С помощью [правила](#правила) `backtick_mono` можно
|
|
241
|
+
Выделение с помощью обратных кавычек ``` `монотекст` ``` по умолчанию отображается как курсив. С помощью [правила](#правила) `backtick_mono` можно изменить отображение:
|
|
241
242
|
* `!!rule backtick_mono italic` - курсив (по умолчанию)
|
|
242
243
|
|
|
243
244
|

|
|
@@ -298,7 +299,7 @@ Without Microsoft Word, PDF export and several advanced Word-specific features a
|
|
|
298
299
|
![Рисунок 1.2 - С указанием ширины] (image.png){340}
|
|
299
300
|
![Рисунок 1.3 - С указанием высоты] (image.png){x265}
|
|
300
301
|
![Рисунок 1.4 - С указанием размера] (image.png){340x265}
|
|
301
|
-
![Рисунок 1.5 - Важные зарисовки, с очень длинным названием,
|
|
302
|
+
![Рисунок 1.5 - Важные зарисовки, с очень длинным названием, <br>которое не умещается в одну строку] (image.png){340}
|
|
302
303
|
```
|
|
303
304
|
|
|
304
305
|
|
|
@@ -386,19 +387,44 @@ Without Microsoft Word, PDF export and several advanced Word-specific features a
|
|
|
386
387
|
|
|
387
388
|
### Разрыв раздела
|
|
388
389
|
|
|
389
|
-
|
|
390
|
+
Вставляет разрыв раздела и задаёт параметры форматирования для следующей страницы: ориентацию листа и логику нумерации.
|
|
390
391
|
|
|
392
|
+
**Синтаксис:**
|
|
393
|
+
|
|
394
|
+
```text
|
|
395
|
+
!!section [ориентация] [нумерация]
|
|
391
396
|
```
|
|
397
|
+
|
|
398
|
+
Параметры не зависят от порядка следования и являются необязательными. Если параметр не указан, раздел сохраняет настройки предыдущей страницы.
|
|
399
|
+
|
|
400
|
+
**Параметры:**
|
|
401
|
+
|
|
402
|
+
| Параметр | Значения | Описание |
|
|
403
|
+
| --- | --- | --- |
|
|
404
|
+
| **Ориентация** | `landscape`<br>`portrait` | Устанавливает альбомную или книжную ориентацию листа. |
|
|
405
|
+
| **Нумерация** | `from <N>`<br>`unpaged` | Сбрасывает счетчик страниц на число `N` либо полностью отключает нумерацию на страницах раздела. |
|
|
406
|
+
|
|
407
|
+
**Примеры использования:**
|
|
408
|
+
|
|
409
|
+
```text
|
|
392
410
|
!!section
|
|
393
|
-
Раздел
|
|
411
|
+
Раздел с параметрами предыдущей страницы
|
|
412
|
+
|
|
413
|
+
!!section landscape
|
|
414
|
+
Альбомная ориентация (сквозная нумерация сохраняется)
|
|
415
|
+
|
|
416
|
+
!!section portrait
|
|
417
|
+
Возврат к книжной ориентации
|
|
394
418
|
|
|
395
419
|
!!section from 3
|
|
396
|
-
|
|
397
|
-
```
|
|
420
|
+
Нумерация страниц начинается заново с 3
|
|
398
421
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
422
|
+
!!section unpaged
|
|
423
|
+
Страницы раздела не нумеруются
|
|
424
|
+
|
|
425
|
+
!!section landscape from 3
|
|
426
|
+
Альбомная ориентация с нумерацией с 3-й страницы
|
|
427
|
+
```
|
|
402
428
|
|
|
403
429
|
### Автонумерация
|
|
404
430
|
Система автонумерации автоматически нумерует элементы документа (разделы, рисунки, таблицы, листинги, источники) и позволяет ссылаться на них из текста.
|
package/assets/run.ps1
CHANGED
|
@@ -27,10 +27,19 @@ $MacroTemplate = [System.IO.Path]::GetFullPath($MacroTemplate)
|
|
|
27
27
|
|
|
28
28
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;
|
|
29
29
|
|
|
30
|
+
# Take a snapshot of currently running Word instances
|
|
31
|
+
$existingPids = @(Get-Process WINWORD -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Id)
|
|
32
|
+
|
|
30
33
|
$word = New-Object -ComObject Word.Application
|
|
31
34
|
$word.Visible = $false
|
|
32
35
|
$word.DisplayAlerts = 0
|
|
33
36
|
|
|
37
|
+
# Find the new Word instance and print its PID for Node.js
|
|
38
|
+
$newWord = Get-Process WINWORD -ErrorAction SilentlyContinue | Where-Object { $_.Id -notin $existingPids }
|
|
39
|
+
if ($newWord) {
|
|
40
|
+
Write-Host "[WordPID:$($newWord[0].Id)]"
|
|
41
|
+
}
|
|
42
|
+
|
|
34
43
|
try {
|
|
35
44
|
# Подключаем глобальный шаблон
|
|
36
45
|
$word.AddIns.Add($MacroTemplate, $true)
|
|
@@ -56,6 +65,10 @@ try {
|
|
|
56
65
|
Write-Host "Done: $OutputDoc"
|
|
57
66
|
}
|
|
58
67
|
finally {
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
try {
|
|
69
|
+
$word.Quit()
|
|
70
|
+
} catch {}
|
|
71
|
+
try {
|
|
72
|
+
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null
|
|
73
|
+
} catch {}
|
|
61
74
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -29,12 +29,39 @@ export interface MDRenderConfig {
|
|
|
29
29
|
* @defaultValue `false`
|
|
30
30
|
*/
|
|
31
31
|
disableMacros?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* DOES NOT WORK!
|
|
34
|
+
* @experimental
|
|
35
|
+
*/
|
|
36
|
+
useLibreOffice?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Maps internal outputs to specific log levels:
|
|
39
|
+
* - **info**: Shadows {@link progress} and info in {@link MDRenderError.powershellLog}
|
|
40
|
+
* - **warn**: Shadows {@link MDRenderResult.warnings} (and {@link MDRenderError.warnings})
|
|
41
|
+
* - **error**: Shadows errors in {@link MDRenderError.powershellLog}
|
|
42
|
+
*/
|
|
43
|
+
logger?: {
|
|
44
|
+
info: (msg: string) => void;
|
|
45
|
+
warn: (msg: string) => void;
|
|
46
|
+
error: (msg: string) => void;
|
|
47
|
+
};
|
|
32
48
|
/**
|
|
33
49
|
* Optional callback function triggered periodically to report the total rendering progress.
|
|
34
50
|
* @param totalPercent - The total calculated completion progress, clamped between 0 and 100.
|
|
35
51
|
* @param message - A human-readable description of the active step.
|
|
36
52
|
*/
|
|
37
53
|
progress?: (totalPercent: number, message: string) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Optional `AbortSignal` used to cancel the rendering process.
|
|
56
|
+
*/
|
|
57
|
+
abortSignal?: AbortSignal;
|
|
58
|
+
/**
|
|
59
|
+
* When `true`, permits referencing external assets (e.g. images or `include` documents)
|
|
60
|
+
* that resolve outside the source file's working directory.
|
|
61
|
+
* @note When `false`, accessing any path outside the working directory throws a `userInput` error.
|
|
62
|
+
* @defaultValue `false`
|
|
63
|
+
*/
|
|
64
|
+
allowExternalFiles?: boolean;
|
|
38
65
|
}
|
|
39
66
|
/**
|
|
40
67
|
* The successful result of a Markdown rendering operation.
|
|
@@ -84,7 +111,7 @@ export interface MDRenderResult {
|
|
|
84
111
|
* if (error.cause)
|
|
85
112
|
* console.error("Root cause:", error.cause);
|
|
86
113
|
*
|
|
87
|
-
*
|
|
114
|
+
* error.warnings.forEach(w => console.warn(`[W] ${w}`));
|
|
88
115
|
*
|
|
89
116
|
* if (error.code.endsWith("PS") && error.powershellLog.length > 0)
|
|
90
117
|
* console.error("PowerShell Logs:\n", error.powershellLog.join(""));
|
|
@@ -96,7 +123,7 @@ export interface MDRenderResult {
|
|
|
96
123
|
*/
|
|
97
124
|
declare function renderMarkdown(config: MDRenderConfig): Promise<MDRenderResult>;
|
|
98
125
|
/** Error codes identifying unique failure points in the compilation. */
|
|
99
|
-
export type MDRenderErrorCode = "unknown" | "noPS" | "inPS" | "vba" | "pdf" | "noWin";
|
|
126
|
+
export type MDRenderErrorCode = "unknown" | "userInput" | "noPS" | "inPS" | "vba" | "pdf" | "noWin";
|
|
100
127
|
/**
|
|
101
128
|
* Custom error thrown when compilation or rendering fails.
|
|
102
129
|
* Captures historical console buffers, partial file states, and downstream environment warnings.
|
|
@@ -109,6 +136,7 @@ export declare class MDRenderError extends Error {
|
|
|
109
136
|
/**
|
|
110
137
|
* Code indicating the underlying cause of the failure:
|
|
111
138
|
* - `unknown`: An unhandled or unexpected internal runtime error.
|
|
139
|
+
* - `userInput`: Invalid user input or Markdown document structure.
|
|
112
140
|
* - `noPS`: PowerShell could not be started or found in the system PATH.
|
|
113
141
|
* - `inPS`: A failure occurred inside PowerShell; MS Word may be missing or corrupt.
|
|
114
142
|
* - `vba`: An error occurred during the execution of internal Word VBA macros.
|