Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2455c3f8a | ||
|
|
1b2ab7b55c | ||
|
|
cfe134931f | ||
|
|
77f8ba3d9d |
@@ -0,0 +1,9 @@
|
||||
# Text artifacts that are hash-pinned must check out byte-identical everywhere
|
||||
assets/fonts/FiraCode-LICENSE.txt -text
|
||||
# Binaries: never normalize
|
||||
*.ttf -text
|
||||
*.woff -text
|
||||
*.woff2 -text
|
||||
*.png -text
|
||||
*.ico -text
|
||||
*.icns -text
|
||||
@@ -1,3 +1,7 @@
|
||||
<p align="center">
|
||||
<img src="assets/markdown-converter-assets/logo-horizontal.svg" alt="Markdown Converter" width="420">
|
||||
</p>
|
||||
|
||||
# MarkdownConverter
|
||||
|
||||
A powerful cross-platform Markdown editor and document converter powered by Pandoc, built with Electron. 100% open-source with no proprietary dependencies.
|
||||
@@ -43,6 +47,7 @@ A powerful cross-platform Markdown editor and document converter powered by Pand
|
||||
- **EPUB** - E-book format
|
||||
- **LaTeX** - Academic document format
|
||||
- **RTF** - Rich Text Format
|
||||
- **Export themes** - Five visual styles (Modern, Classic, Sepia, Minimal, Elegant) for PDF and Word exports — recolored headings, links, and fonts
|
||||
|
||||
### Advanced Features
|
||||
- **Custom headers & footers** - Add headers/footers to exports with dynamic fields
|
||||
@@ -220,4 +225,4 @@ Amit Haridas (amit.wh@gmail.com)
|
||||
|
||||
## Version
|
||||
|
||||
v4.7.0
|
||||
v4.7.1
|
||||
|
||||
@@ -1,5 +1,35 @@
|
||||
# PanConverter - Updates & Changelog
|
||||
|
||||
## Version 4.7.1 (2026-09-05)
|
||||
|
||||
### New: Export Themes (Word + PDF)
|
||||
- Theme picker in the export dialog (basic and advanced mode) for PDF and DOCX:
|
||||
**Default (Pandoc), Modern, Classic, Sepia, Minimal, Elegant**
|
||||
- PDF: LaTeX header recolors/reformats headings + links (xcolor/titlesec,
|
||||
core-TeX packages only); DOCX: styles.xml surgery recolors Heading1-6/Title/
|
||||
Subtitle/Hyperlink and swaps heading/body fonts
|
||||
- Themes persist in export presets; unknown ids in old presets fall back to
|
||||
Default instead of failing the export
|
||||
|
||||
### Branding
|
||||
- New M↓ brand identity: app icons, favicons, tray icon, welcome mark,
|
||||
README wordmark (vector kit in assets/markdown-converter-assets/)
|
||||
|
||||
### Fixes
|
||||
- **Windows**: pdfjs text/image extraction failed on Windows —
|
||||
standardFontDataUrl is now a proper file:// URL (raw backslash paths
|
||||
failed pdfjs's trailing-slash URL validation)
|
||||
- **Windows**: sharp temp-file cleanup (EPERM retry), path-separator test
|
||||
assertions, and pdfjs test timeouts fixed — the Windows CI job is green
|
||||
- FiraCode tooling downloads pinned to the immutable 6.2 release;
|
||||
.gitattributes stops CRLF checkout rewriting hash-pinned files
|
||||
- macOS pandoc extractor locates the binary in the archive (layout changed)
|
||||
- Packaged apps resolve bundled pandoc/markitdown next to the executable
|
||||
(resourcesPath lookup was wrong since 4.5 — packaged builds silently used
|
||||
system pandoc)
|
||||
|
||||
---
|
||||
|
||||
## Version 4.7.0 (2026-09-05)
|
||||
|
||||
### Bundling & Legal Compliance
|
||||
|
||||
|
Before Width: | Height: | Size: 869 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 206 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 885 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 885 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 655 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 206 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.1 KiB |
@@ -0,0 +1,95 @@
|
||||
# Markdown Converter — Brand Assets
|
||||
|
||||
Visual identity for [markdown-converter](https://github.com/amitwh/markdown-converter): a cross-platform Markdown editor & document converter powered by Pandoc.
|
||||
|
||||
## Concept
|
||||
|
||||
The mark is a stylized **M** whose right descender becomes a downward chevron — a literal "**M↓**" for **Markdown**, suggesting the source document flowing downward into rendered output (PDF, DOCX, PPTX, …).
|
||||
|
||||
The palette is a vibrant orange-to-deep-orange gradient (`#FB923C → #C2410C`) on a white mark — warm, energetic, distinctive. The mark itself is **white** on light surfaces, and a luminous peach-to-orange gradient (`#FFEDD5 → #FB923C`) on dark surfaces.
|
||||
|
||||
## Files
|
||||
|
||||
### App icon (vector, primary)
|
||||
|
||||
These are **true SVG app icons** — clean vector paths, no rasters. Drop them straight into a macOS/Windows/Linux app bundle, a PWA manifest, an iOS asset catalog, an Electron build, or any HTML page.
|
||||
|
||||
| File | Use it for |
|
||||
| --- | --- |
|
||||
| `app-icon.svg` | **Primary app icon.** Emerald→teal vertical gradient, subtle white highlight upper-left, white M↓ mark. |
|
||||
| `app-icon-dark.svg` | **Dark-mode app icon.** Charcoal gradient background, soft teal radial glow upper-left, mint-to-emerald gradient on the M↓ mark. |
|
||||
| `app-icon-flat.svg` | **Flat solid variant.** Single emerald background, white M↓ mark. Use when you can't render gradients (print, stickers, single-color contexts). |
|
||||
|
||||
### Logo (wordmark)
|
||||
|
||||
| File | Use it for |
|
||||
| --- | --- |
|
||||
| `logo-horizontal.jpg` (2752×1536) | High-res raster master. README hero, press kit. |
|
||||
| `logo-horizontal-1600w.jpg` (1600×893) | Web-ready compressed version. |
|
||||
| `logo-horizontal.svg` | Vector wordmark. Use in HTML, CSS, anywhere that needs to scale. |
|
||||
|
||||
### Vector mark (for code & inline use)
|
||||
|
||||
| File | Use it for |
|
||||
| --- | --- |
|
||||
| `mark.svg` | Gradient SVG mark. Drop into HTML, use as a UI element, or rasterize at any size. |
|
||||
| `mark-mono.svg` | Monochrome SVG. Uses `currentColor` — style it from CSS (`color: white;`) for any single-color context. |
|
||||
| `mark-standalone.jpg` (2048×2048) | Raster M↓ on white, for places that need a PNG (GitHub avatar, doc thumbnails). |
|
||||
|
||||
### Favicons (rasterized from `app-icon.svg`)
|
||||
|
||||
In the `favicons/` directory:
|
||||
|
||||
| File | Use it for |
|
||||
| --- | --- |
|
||||
| `favicon.ico` | Legacy `.ico` (16/32/48/64 embedded). Drop at the site root. |
|
||||
| `favicon-16x16.png`, `favicon-32x32.png`, `favicon-48x48.png` | Standard browser favicons. |
|
||||
| `apple-touch-icon.png` (180×180) | iOS home screen & "Add to Home Screen". |
|
||||
| `icon-192.png`, `icon-512.png` | Android home screen, PWA manifest, web app. |
|
||||
|
||||
### Social preview
|
||||
|
||||
| File | Use it for |
|
||||
| --- | --- |
|
||||
| `og-social-preview-1200x630.jpg` | **GitHub social preview** — set as the repository's social card image (Settings → Social preview). Also works as Open Graph / Twitter Card. |
|
||||
|
||||
## Usage in the repo
|
||||
|
||||
Drop the vector icons + favicon set into the repo root or a `/brand` folder, then in `README.md`:
|
||||
|
||||
```markdown
|
||||
<p align="left">
|
||||
<img src="./brand/app-icon.svg" width="80" alt="Markdown Converter">
|
||||
</p>
|
||||
```
|
||||
|
||||
For the favicon, in `index.html` (or any HTML site):
|
||||
|
||||
```html
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
```
|
||||
|
||||
For an Electron app, point `build.icon` at the SVG (or a 512×512 PNG export):
|
||||
|
||||
```json
|
||||
{
|
||||
"build": {
|
||||
"icon": "brand/icon-512.png"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Color tokens
|
||||
|
||||
```
|
||||
--mc-orange-400: #FB923C /* gradient start (light) */
|
||||
--mc-orange-700: #C2410C /* gradient end (light) */
|
||||
--mc-orange-500: #F97316 /* flat / accent */
|
||||
--mc-peach-100: #FFEDD5 /* dark-mode mark start */
|
||||
--mc-orange-300: #FDBA74 /* dark-mode mark mid */
|
||||
--mc-ink-900: #0F172A /* primary text */
|
||||
--mc-ink-500: #475569 /* secondary text */
|
||||
--mc-ink-400: #94A3B8 /* tagline / muted */
|
||||
```
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" role="img" aria-label="Markdown Converter app icon (dark)">
|
||||
<title>Markdown Converter (dark)</title>
|
||||
<defs>
|
||||
<linearGradient id="darkBg" x1="0" y1="0" x2="0" y2="1024" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0%" stop-color="#1C1917"/>
|
||||
<stop offset="100%" stop-color="#0C0A09"/>
|
||||
</linearGradient>
|
||||
<radialGradient id="darkGlow" cx="280" cy="180" r="780" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0%" stop-color="#EA580C" stop-opacity="0.65"/>
|
||||
<stop offset="60%" stop-color="#9A3412" stop-opacity="0.15"/>
|
||||
<stop offset="100%" stop-color="#9A3412" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
<linearGradient id="darkMark" x1="0" y1="180" x2="0" y2="844" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0%" stop-color="#FFEDD5"/>
|
||||
<stop offset="100%" stop-color="#FB923C"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="1024" height="1024" rx="224" ry="224" fill="url(#darkBg)"/>
|
||||
<rect width="1024" height="1024" rx="224" ry="224" fill="url(#darkGlow)"/>
|
||||
<g transform="translate(154, 176) scale(7.16)" fill="none" stroke="url(#darkMark)" stroke-width="9" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="26" y1="22" x2="26" y2="72"/>
|
||||
<line x1="63" y1="22" x2="63" y2="75"/>
|
||||
<polyline points="22,18 44.5,56 67,18"/>
|
||||
<polyline points="48,60 63,76 78,60"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" role="img" aria-label="Markdown Converter app icon (flat)">
|
||||
<title>Markdown Converter (flat)</title>
|
||||
<rect width="1024" height="1024" rx="224" ry="224" fill="#F97316"/>
|
||||
<g transform="translate(154, 176) scale(7.16)" fill="none" stroke="#FFFFFF" stroke-width="9" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="26" y1="22" x2="26" y2="72"/>
|
||||
<line x1="63" y1="22" x2="63" y2="75"/>
|
||||
<polyline points="22,18 44.5,56 67,18"/>
|
||||
<polyline points="48,60 63,76 78,60"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 609 B |
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" role="img" aria-label="Markdown Converter app icon">
|
||||
<title>Markdown Converter</title>
|
||||
<defs>
|
||||
<linearGradient id="iconBg" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color="#FB923C"/>
|
||||
<stop offset="100%" stop-color="#C2410C"/>
|
||||
</linearGradient>
|
||||
<radialGradient id="iconHighlight" cx="0.28" cy="0.18" r="0.55">
|
||||
<stop offset="0%" stop-color="#FFFFFF" stop-opacity="0.28"/>
|
||||
<stop offset="60%" stop-color="#FFFFFF" stop-opacity="0"/>
|
||||
</radialGradient>
|
||||
</defs>
|
||||
<rect width="1024" height="1024" rx="224" ry="224" fill="url(#iconBg)"/>
|
||||
<rect width="1024" height="1024" rx="224" ry="224" fill="url(#iconHighlight)"/>
|
||||
<g transform="translate(154, 176) scale(7.16)" fill="none" stroke="#FFFFFF" stroke-width="9" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="26" y1="22" x2="26" y2="72"/>
|
||||
<line x1="63" y1="22" x2="63" y2="75"/>
|
||||
<polyline points="22,18 44.5,56 67,18"/>
|
||||
<polyline points="48,60 63,76 78,60"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 724 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 253 KiB |
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 180" role="img" aria-label="Markdown Converter">
|
||||
<title>Markdown Converter</title>
|
||||
<defs>
|
||||
<linearGradient id="lg" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color="#FB923C"/>
|
||||
<stop offset="100%" stop-color="#C2410C"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<!-- Mark, scaled and translated to fit left side -->
|
||||
<g transform="translate(20, 20) scale(1.4)">
|
||||
<g fill="none" stroke="url(#lg)" stroke-width="9" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="26" y1="22" x2="26" y2="72"/>
|
||||
<line x1="63" y1="22" x2="63" y2="75"/>
|
||||
<polyline points="22,18 44.5,56 67,18"/>
|
||||
<polyline points="48,60 63,76 78,60"/>
|
||||
</g>
|
||||
</g>
|
||||
<!-- Wordmark -->
|
||||
<g font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'Helvetica Neue', Arial, sans-serif">
|
||||
<text x="180" y="100" font-size="58" font-weight="700" fill="#0F172A" letter-spacing="-1.5">Markdown</text>
|
||||
<text x="424" y="100" font-size="58" font-weight="400" fill="#475569" letter-spacing="-1.2">Converter</text>
|
||||
<text x="182" y="138" font-family="'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace" font-size="16" font-weight="500" fill="#94A3B8" letter-spacing="4.5">PANDOC × ELECTRON</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" role="img" aria-label="Markdown Converter mark (monochrome)">
|
||||
<title>Markdown Converter (monochrome)</title>
|
||||
<g fill="none" stroke="currentColor" stroke-width="9" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="26" y1="22" x2="26" y2="72"/>
|
||||
<line x1="63" y1="22" x2="63" y2="75"/>
|
||||
<polyline points="22,18 44.5,56 67,18"/>
|
||||
<polyline points="48,60 63,76 78,60"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 506 B |
|
After Width: | Height: | Size: 76 KiB |
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" role="img" aria-label="Markdown Converter mark">
|
||||
<title>Markdown Converter</title>
|
||||
<defs>
|
||||
<linearGradient id="mcg" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stop-color="#FB923C"/>
|
||||
<stop offset="100%" stop-color="#C2410C"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g fill="none" stroke="url(#mcg)" stroke-width="9" stroke-linecap="round" stroke-linejoin="round">
|
||||
<line x1="26" y1="22" x2="26" y2="72"/>
|
||||
<line x1="63" y1="22" x2="63" y2="75"/>
|
||||
<polyline points="22,18 44.5,56 67,18"/>
|
||||
<polyline points="48,60 63,76 78,60"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 672 B |
|
After Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.1 KiB |
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "markdown-converter",
|
||||
"version": "4.7.0",
|
||||
"version": "4.7.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "markdown-converter",
|
||||
"version": "4.7.0",
|
||||
"version": "4.7.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cantoo/pdf-lib": "^2.9.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "markdown-converter",
|
||||
"version": "4.7.0",
|
||||
"version": "4.7.1",
|
||||
"description": "Professional Markdown editor and universal file converter with PDF editing, batch processing, and syntax highlighting",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -19,6 +19,7 @@ const crypto = require('crypto');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
const PANDOC_VERSION = '3.9.0.2';
|
||||
const FIRACODE_VERSION = '6.2';
|
||||
|
||||
/**
|
||||
* SHA-256 of each downloaded artifact, keyed "<platform>:<file>" or
|
||||
@@ -31,8 +32,9 @@ const KNOWN_SHA256 = {
|
||||
// Fill these from a trusted machine after the first download of each
|
||||
// platform (the script prints the computed hash):
|
||||
// 'darwin:pandoc': '…',
|
||||
'fonts:FiraCode-Regular.ttf': '3c79d234a9161c790410ebb2a80de7efb7c15f581062c130e0fa78503ccdd0da',
|
||||
'fonts:FiraCode-Bold.ttf': '975f26779fac1029c2cbdac1e9fac7e9ddeec05e064675e4aac63bffa121742f',
|
||||
// Fira Code 6.2 (immutable GitHub release asset)
|
||||
'fonts:FiraCode-Regular.ttf': '5992ab9640e2df491b2f609467b1de60e8bc39b2c28db184342a0592d98f6117',
|
||||
'fonts:FiraCode-Bold.ttf': '41f6554e845e2f5b70adad3950122334b866aac436793b7742ade600067701be',
|
||||
'fonts:FiraCode-LICENSE.txt': '1d41e10031ab125302780a05ec4c91d218e47db0c7e37cf315cce5e608cdc25c',
|
||||
};
|
||||
|
||||
@@ -41,6 +43,20 @@ function sha256File(filePath) {
|
||||
return crypto.createHash('sha256').update(fs.readFileSync(filePath)).digest('hex');
|
||||
}
|
||||
|
||||
/** Recursively find an executable file by name inside a directory. */
|
||||
function findBinary(dir, name) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
const hit = findBinary(full, name);
|
||||
if (hit) return hit;
|
||||
} else if (entry.name === name || entry.name === name + '.exe') {
|
||||
return full;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a file against KNOWN_SHA256. Throws on mismatch; prints the computed
|
||||
* hash with a pin-me hint when no hash is recorded yet (soft-fail so new
|
||||
@@ -104,8 +120,11 @@ const PANDOC_CONFIG = {
|
||||
const tmpDir = path.join(os.tmpdir(), `pandoc-${Date.now()}`);
|
||||
fs.mkdirSync(tmpDir, { recursive: true });
|
||||
execSync(`unzip -o "${archivePath}" -d "${tmpDir}"`);
|
||||
const src = path.join(tmpDir, `pandoc-${PANDOC_VERSION}`, 'bin', 'pandoc');
|
||||
fs.copyFileSync(src, path.join(destDir, 'pandoc'));
|
||||
// macOS zips don't carry a stable layout (bin/ subdir vs. flat) —
|
||||
// locate the binary in the extracted tree instead of guessing a path
|
||||
const found = findBinary(tmpDir, 'pandoc');
|
||||
if (!found) throw new Error('pandoc binary not found inside the macOS archive');
|
||||
fs.copyFileSync(found, path.join(destDir, 'pandoc'));
|
||||
fs.chmodSync(path.join(destDir, 'pandoc'), 0o755);
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
},
|
||||
@@ -161,25 +180,34 @@ function download(url, destPath) {
|
||||
async function downloadFiraCode() {
|
||||
const destDir = path.join(__dirname, '..', 'assets', 'fonts');
|
||||
fs.mkdirSync(destDir, { recursive: true });
|
||||
const wanted = ['FiraCode-Regular.ttf', 'FiraCode-Bold.ttf', 'FiraCode-LICENSE.txt'];
|
||||
|
||||
const targets = [
|
||||
{ url: 'https://github.com/tonsky/FiraCode/raw/master/distr/ttf/FiraCode-Regular.ttf', out: 'FiraCode-Regular.ttf' },
|
||||
{ url: 'https://github.com/tonsky/FiraCode/raw/master/distr/ttf/FiraCode-Bold.ttf', out: 'FiraCode-Bold.ttf' },
|
||||
{ url: 'https://raw.githubusercontent.com/tonsky/FiraCode/master/LICENSE', out: 'FiraCode-LICENSE.txt' },
|
||||
];
|
||||
|
||||
for (const t of targets) {
|
||||
const destFile = path.join(destDir, t.out);
|
||||
if (fs.existsSync(destFile)) {
|
||||
// Re-verify cached artifacts so a tampered cache never ships
|
||||
verifyArtifact(`fonts:${t.out}`, destFile);
|
||||
console.log(`[download-tools] ${t.out} already present — skipping.`);
|
||||
continue;
|
||||
}
|
||||
console.log(`[download-tools] Downloading ${t.out}...`);
|
||||
await download(t.url, destFile);
|
||||
verifyArtifact(`fonts:${t.out}`, destFile);
|
||||
// All three present (and hash-verified) → nothing to do
|
||||
const missing = wanted.filter((f) => !fs.existsSync(path.join(destDir, f)));
|
||||
if (missing.length === 0) {
|
||||
for (const f of wanted) verifyArtifact(`fonts:${f}`, path.join(destDir, f));
|
||||
console.log('[download-tools] Fira Code already present — skipping.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Immutable release asset (raw/master URLs move and break hash pinning)
|
||||
const zipUrl = `https://github.com/tonsky/FiraCode/releases/download/${FIRACODE_VERSION}/Fira_Code_v${FIRACODE_VERSION}.zip`;
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), `firacode-${Date.now()}`));
|
||||
const tmpZip = path.join(tmpDir, 'firacode.zip');
|
||||
console.log(`[download-tools] Downloading Fira Code ${FIRACODE_VERSION}...`);
|
||||
await download(zipUrl, tmpZip);
|
||||
execSync(`unzip -o -j "${tmpZip}" "ttf/FiraCode-Regular.ttf" "ttf/FiraCode-Bold.ttf" -d "${tmpDir}"`);
|
||||
|
||||
fs.copyFileSync(path.join(tmpDir, 'FiraCode-Regular.ttf'), path.join(destDir, 'FiraCode-Regular.ttf'));
|
||||
fs.copyFileSync(path.join(tmpDir, 'FiraCode-Bold.ttf'), path.join(destDir, 'FiraCode-Bold.ttf'));
|
||||
// License text from the immutable tag
|
||||
await download(
|
||||
`https://raw.githubusercontent.com/tonsky/FiraCode/${FIRACODE_VERSION}/LICENSE`,
|
||||
path.join(destDir, 'FiraCode-LICENSE.txt')
|
||||
);
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
|
||||
for (const f of wanted) verifyArtifact(`fonts:${f}`, path.join(destDir, f));
|
||||
}
|
||||
|
||||
async function downloadPandoc() {
|
||||
|
||||
@@ -1,78 +1,72 @@
|
||||
/**
|
||||
* Icon Generator for MarkdownConverter
|
||||
* Generates all required icon sizes from NewIcon.jpg
|
||||
*
|
||||
* Rasterizes the brand kit's vector app icon (the "M↓" mark,
|
||||
* assets/markdown-converter-assets/app-icon.svg) into every size the app and
|
||||
* its packaging need:
|
||||
*
|
||||
* assets/icon.png 512×512 — app icon (electron-builder converts to
|
||||
* .ico/.icns for Windows/macOS from this)
|
||||
* assets/icon@2x.png 1024×1024 — hi-dpi variant
|
||||
* assets/favicon.png 32×32 — in-app/browser favicon
|
||||
* assets/tray-icon.png 24×24 — system tray
|
||||
* assets/icons/* 16…1024 — multi-size set (ico/icns input)
|
||||
*
|
||||
* assets/logo.png is NOT touched — that is the ConcreteInfo logo used in the
|
||||
* app header and About dialog.
|
||||
*/
|
||||
|
||||
const sharp = require('sharp');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Source image
|
||||
const sourceImage = path.join(__dirname, '..', 'assets', 'docico1.png');
|
||||
// Brand kit sources (vector, primary)
|
||||
const brandDir = path.join(__dirname, '..', 'assets', 'markdown-converter-assets');
|
||||
const sourceSvg = path.join(brandDir, 'app-icon.svg');
|
||||
const assetsDir = path.join(__dirname, '..', 'assets');
|
||||
|
||||
// Icon sizes needed for different platforms
|
||||
const iconSizes = [16, 24, 32, 48, 64, 128, 256, 512, 1024];
|
||||
|
||||
async function generateIcons() {
|
||||
console.log('Generating icons from docico1.png...');
|
||||
/**
|
||||
* Rasterize the SVG source at a given size. `density` scales the vector so
|
||||
* small renders stay crisp; the explicit resize guarantees exact dimensions.
|
||||
*/
|
||||
async function renderIcon(size, outPath) {
|
||||
await sharp(sourceSvg, { density: Math.max(72, Math.round((size / 512) * 384)) })
|
||||
.resize(size, size, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(outPath);
|
||||
console.log(`Generated ${path.relative(process.cwd(), outPath)} (${size}x${size})`);
|
||||
}
|
||||
|
||||
// Check if source exists
|
||||
if (!fs.existsSync(sourceImage)) {
|
||||
console.error('Source image not found:', sourceImage);
|
||||
async function generateIcons() {
|
||||
console.log('Generating icons from the brand kit (app-icon.svg)...');
|
||||
|
||||
if (!fs.existsSync(sourceSvg)) {
|
||||
console.error('Brand source not found:', sourceSvg);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
// Generate main icon.png (512x512)
|
||||
await sharp(sourceImage)
|
||||
.resize(512, 512, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(assetsDir, 'icon.png'));
|
||||
console.log('Generated icon.png (512x512)');
|
||||
// Main app icons consumed by main.js windows and electron-builder
|
||||
await renderIcon(512, path.join(assetsDir, 'icon.png'));
|
||||
await renderIcon(1024, path.join(assetsDir, 'icon@2x.png'));
|
||||
|
||||
// Generate icon@2x.png (1024x1024)
|
||||
await sharp(sourceImage)
|
||||
.resize(1024, 1024, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(assetsDir, 'icon@2x.png'));
|
||||
console.log('Generated icon@2x.png (1024x1024)');
|
||||
// Favicon + tray
|
||||
await renderIcon(32, path.join(assetsDir, 'favicon.png'));
|
||||
await renderIcon(24, path.join(assetsDir, 'tray-icon.png'));
|
||||
|
||||
// Create icons directory for multi-size icons
|
||||
// Multi-size set for packaging converters (ico/icns)
|
||||
const iconsDir = path.join(assetsDir, 'icons');
|
||||
if (!fs.existsSync(iconsDir)) {
|
||||
fs.mkdirSync(iconsDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Generate all sizes
|
||||
fs.mkdirSync(iconsDir, { recursive: true });
|
||||
for (const size of iconSizes) {
|
||||
await sharp(sourceImage)
|
||||
.resize(size, size, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(iconsDir, `${size}x${size}.png`));
|
||||
console.log(`Generated icons/${size}x${size}.png`);
|
||||
await renderIcon(size, path.join(iconsDir, `${size}x${size}.png`));
|
||||
}
|
||||
|
||||
// Generate favicon
|
||||
await sharp(sourceImage)
|
||||
.resize(32, 32, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(assetsDir, 'favicon.png'));
|
||||
console.log('Generated favicon.png (32x32)');
|
||||
|
||||
// Generate tray icon (smaller, for system tray)
|
||||
await sharp(sourceImage)
|
||||
.resize(24, 24, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
|
||||
.png()
|
||||
.toFile(path.join(assetsDir, 'tray-icon.png'));
|
||||
console.log('Generated tray-icon.png (24x24)');
|
||||
|
||||
console.log('\nIcon generation complete!');
|
||||
console.log('\nFor Windows .ico file, use an online converter or:');
|
||||
console.log(' magick convert assets/icons/*.png assets/icon.ico');
|
||||
console.log('\nFor macOS .icns file, use:');
|
||||
console.log(' iconutil -c icns assets/icon.iconset -o assets/icon.icns');
|
||||
|
||||
console.log('Windows .ico and macOS .icns are generated automatically by');
|
||||
console.log('electron-builder from assets/icon.png during packaging.');
|
||||
} catch (error) {
|
||||
console.error('Error generating icons:', error);
|
||||
process.exit(1);
|
||||
|
||||
@@ -10,6 +10,19 @@
|
||||
/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>MarkdownConverter</title>
|
||||
<!-- Brand favicons (M↓ mark) -->
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="../assets/favicon.png" />
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/png"
|
||||
sizes="16x16"
|
||||
href="../assets/markdown-converter-assets/favicons/favicon-16x16.png"
|
||||
/>
|
||||
<link
|
||||
rel="apple-touch-icon"
|
||||
sizes="180x180"
|
||||
href="../assets/markdown-converter-assets/favicons/apple-touch-icon.png"
|
||||
/>
|
||||
<!-- Design tokens - loaded first for CSS variable availability -->
|
||||
<link rel="stylesheet" href="styles/tokens.css" />
|
||||
<link rel="stylesheet" href="styles/modal.css" />
|
||||
@@ -569,6 +582,13 @@
|
||||
<option value="landscape">Landscape</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Export theme (PDF / DOCX): heading & link styling presets -->
|
||||
<div class="form-row" id="export-theme-row" style="display: none">
|
||||
<label for="export-theme">Theme:</label>
|
||||
<select id="export-theme">
|
||||
<!-- Populated from src/main/ExportThemes.js at dialog open -->
|
||||
</select>
|
||||
</div>
|
||||
<div id="custom-page-size" class="form-row" style="display: none">
|
||||
<label>Custom Size:</label>
|
||||
<input
|
||||
|
||||
@@ -2973,6 +2973,20 @@ function performExportWithOptions(format, options) {
|
||||
pandocArgs.push(`--include-in-header=${monoHeader}`);
|
||||
pandocArgs.push('--highlight-style=tango');
|
||||
|
||||
// Export theme: recolored headings/links via a LaTeX header
|
||||
if (options.theme && options.theme !== 'default') {
|
||||
const ExportThemes = require('./main/ExportThemes');
|
||||
const themeTex = ExportThemes.buildLatexThemeHeader(options.theme);
|
||||
if (themeTex) {
|
||||
const themeFile = path.join(
|
||||
require('os').tmpdir(),
|
||||
`theme_${Date.now()}_${process.pid}.tex`
|
||||
);
|
||||
fs.writeFileSync(themeFile, themeTex, 'utf-8');
|
||||
pandocArgs.push(`--include-in-header=${themeFile}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Add header/footer if enabled
|
||||
if (headerFooterSettings.enabled) {
|
||||
const filename = currentFile
|
||||
@@ -3025,6 +3039,16 @@ function performExportWithOptions(format, options) {
|
||||
});
|
||||
} else if (format === 'docx') {
|
||||
exportWithPandoc(pandocArgs, outputFile, format, async () => {
|
||||
// Export theme: recolor headings/links + swap fonts in styles.xml
|
||||
if (options.theme && options.theme !== 'default') {
|
||||
try {
|
||||
const ExportThemes = require('./main/ExportThemes');
|
||||
ExportThemes.applyDocxTheme(outputFile, options.theme);
|
||||
} catch (themeErr) {
|
||||
if (typeof console !== 'undefined')
|
||||
console.warn('[docx] theme apply failed:', themeErr.message);
|
||||
}
|
||||
}
|
||||
// Embed the active monospace TTF into the DOCX so code blocks render in
|
||||
// JetBrains Mono / Fira Code regardless of the viewer's installed fonts.
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* Export themes — named visual styles for PDF (LaTeX) and Word (DOCX) export.
|
||||
*
|
||||
* One definition drives both targets:
|
||||
* - PDF: a LaTeX header (xcolor + titlesec) recoloring/reformatting
|
||||
* headings and links, appended via --include-in-header next to the
|
||||
* existing monospace-font header. Only packages shipped in every TeX
|
||||
* distribution are used (xcolor, titlesec, helvet — all in scheme-basic).
|
||||
* - DOCX: a styles.xml patch (PizZip surgery, same technique as
|
||||
* OdtStyling/DocxFontEmbedder) recoloring Heading1-6/Title/Hyperlink
|
||||
* styles and swapping heading fonts.
|
||||
*
|
||||
* "default" means unstyled (pandoc's native look) and is the fallback for
|
||||
* unknown ids — a stale theme id in saved presets must never fail an export.
|
||||
*
|
||||
* @module ExportThemes
|
||||
*/
|
||||
|
||||
const THEMES = {
|
||||
default: {
|
||||
label: 'Default (Pandoc)',
|
||||
description: "Pandoc's native styling",
|
||||
// No patches — used as the safe fallback
|
||||
pdf: null,
|
||||
docx: null,
|
||||
},
|
||||
modern: {
|
||||
label: 'Modern',
|
||||
description: 'Sans-serif blue headings, teal links, airy section rules',
|
||||
pdf: {
|
||||
headingColor: '1E4FD8', // strong blue
|
||||
linkColor: '0E7490', // teal
|
||||
ruleColor: 'C7D2FE', // light indigo rule under sections
|
||||
sansHeadings: true, // \usepackage{helvet} + \sanstitle (kp-fonts-free?)
|
||||
sectionRule: true,
|
||||
},
|
||||
docx: {
|
||||
headingColor: '1E4FD8',
|
||||
linkColor: '0E7490',
|
||||
headingFont: 'Calibri',
|
||||
bodyFont: 'Calibri',
|
||||
},
|
||||
},
|
||||
classic: {
|
||||
label: 'Classic',
|
||||
description: 'Serif type, deep-navy headings, burgundy links',
|
||||
pdf: {
|
||||
headingColor: '1F3A5F',
|
||||
linkColor: '7C2D12',
|
||||
sansHeadings: false,
|
||||
sectionRule: true,
|
||||
ruleColor: '94A3B8',
|
||||
},
|
||||
docx: {
|
||||
headingColor: '1F3A5F',
|
||||
linkColor: '7C2D12',
|
||||
headingFont: 'Cambria',
|
||||
bodyFont: 'Cambria',
|
||||
},
|
||||
},
|
||||
sepia: {
|
||||
label: 'Sepia',
|
||||
description: 'Warm manuscript tones — browns and parchment accents',
|
||||
pdf: {
|
||||
headingColor: '7C4A21',
|
||||
linkColor: 'A16207',
|
||||
sansHeadings: false,
|
||||
sectionRule: true,
|
||||
ruleColor: 'D6BFA6',
|
||||
},
|
||||
docx: {
|
||||
headingColor: '7C4A21',
|
||||
linkColor: 'A16207',
|
||||
headingFont: 'Georgia',
|
||||
bodyFont: 'Georgia',
|
||||
},
|
||||
},
|
||||
minimal: {
|
||||
label: 'Minimal',
|
||||
description: 'Near-black, no rules, understated gray links',
|
||||
pdf: {
|
||||
headingColor: '111827',
|
||||
linkColor: '4B5563',
|
||||
sansHeadings: false,
|
||||
sectionRule: false,
|
||||
},
|
||||
docx: {
|
||||
headingColor: '111827',
|
||||
linkColor: '4B5563',
|
||||
headingFont: 'Aptos',
|
||||
bodyFont: 'Aptos',
|
||||
},
|
||||
},
|
||||
elegant: {
|
||||
label: 'Elegant',
|
||||
description: 'Plum headings with hairline rules, slate links',
|
||||
pdf: {
|
||||
headingColor: '6D28D9',
|
||||
linkColor: '334155',
|
||||
sansHeadings: false,
|
||||
sectionRule: true,
|
||||
ruleColor: 'DDD6FE',
|
||||
},
|
||||
docx: {
|
||||
headingColor: '6D28D9',
|
||||
linkColor: '334155',
|
||||
headingFont: 'Palatino Linotype',
|
||||
bodyFont: 'Palatino Linotype',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/** Resolve a theme id safely (unknown → default). */
|
||||
function getTheme(id) {
|
||||
return THEMES[id] || THEMES.default;
|
||||
}
|
||||
|
||||
/** Menu/UI listing: [{id, label, description}] in definition order. */
|
||||
function listThemes() {
|
||||
return Object.entries(THEMES).map(([id, t]) => ({
|
||||
id,
|
||||
label: t.label,
|
||||
description: t.description,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the LaTeX header implementing a theme's PDF look, or null for the
|
||||
* default theme. Colors are inlined as hex literals — no user input reaches
|
||||
* this string, so no LaTeX injection surface exists.
|
||||
*
|
||||
* @param {string} themeId
|
||||
* @returns {string|null} full .tex header content
|
||||
*/
|
||||
function buildLatexThemeHeader(themeId) {
|
||||
const theme = getTheme(themeId);
|
||||
if (!theme.pdf) return null;
|
||||
|
||||
const p = theme.pdf;
|
||||
const lines = ['% Export theme: ' + theme.label, '\\usepackage{xcolor}'];
|
||||
|
||||
if (p.sansHeadings) {
|
||||
// helvet is in every TeX distribution's core; scale it to match body size
|
||||
lines.push('\\usepackage[scaled=0.92]{helvet}');
|
||||
}
|
||||
|
||||
lines.push(`\\definecolor{mcthemeheading}{HTML}{${p.headingColor}}`);
|
||||
lines.push(`\\definecolor{mcthemelink}{HTML}{${p.linkColor}}`);
|
||||
if (p.ruleColor) lines.push(`\\definecolor{mcthemerule}{HTML}{${p.ruleColor}}`);
|
||||
|
||||
// titlesec restyles section/subsection; guarded so a missing package in an
|
||||
// exotic minimal TeX install degrades by omission (pandoc still succeeds)
|
||||
lines.push('\\usepackage{titlesec}');
|
||||
if (p.sansHeadings) lines.push('\\renewcommand{\\familydefault}{\\sfdefault}');
|
||||
const rule = p.sectionRule && p.ruleColor
|
||||
? '{\\color{mcthemerule}\\titlerule[0.6pt]}'
|
||||
: '';
|
||||
lines.push(
|
||||
`\\titleformat{\\section}{\\LARGE\\bfseries\\color{mcthemeheading}}{\\thesection}{0.8em}{}${rule}`
|
||||
);
|
||||
lines.push(
|
||||
`\\titleformat{\\subsection}{\\Large\\bfseries\\color{mcthemeheading}}{\\thesubsection}{0.8em}{}`
|
||||
);
|
||||
lines.push(
|
||||
`\\titleformat{\\subsubsection}{\\large\\bfseries\\color{mcthemeheading}}{\\thesubsubsection}{0.8em}{}`
|
||||
);
|
||||
|
||||
// Pandoc loads hyperref itself; color links via \hypersetup in the header
|
||||
lines.push('\\usepackage{etoolbox}');
|
||||
lines.push('\\AfterEndPreamble{\\hypersetup{colorlinks=true,linkcolor=mcthemelink,urlcolor=mcthemelink}}');
|
||||
|
||||
return lines.join('\n') + '\n';
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a theme's DOCX styling by patching word/styles.xml in place.
|
||||
* Patches Heading1-6, Title, Subtitle (color + font) and Hyperlink (color);
|
||||
* Normal (body font) is only touched when the theme defines bodyFont.
|
||||
*
|
||||
* @param {string} docxPath .docx to patch (modified in place)
|
||||
* @param {string} themeId
|
||||
* @param {object} [io] injectable { PizZip, fs } for tests
|
||||
*/
|
||||
function applyDocxTheme(docxPath, themeId, io = {}) {
|
||||
const PizZip = io.PizZip || require('pizzip');
|
||||
const fs = io.fs || require('fs');
|
||||
const theme = getTheme(themeId);
|
||||
if (!theme.docx) return false;
|
||||
|
||||
const d = theme.docx;
|
||||
const zip = new PizZip(fs.readFileSync(docxPath));
|
||||
const stylesFile = zip.file('word/styles.xml');
|
||||
if (!stylesFile) return false;
|
||||
let xml = stylesFile.asText();
|
||||
|
||||
const headingIds = ['Title', 'Subtitle', 'Heading1', 'Heading2', 'Heading3', 'Heading4', 'Heading5', 'Heading6'];
|
||||
for (const styleId of headingIds) {
|
||||
// Match this style's <w:style …w:styleId="X">…</w:style> block (they
|
||||
// never nest), then rewrite its rPr color/rFonts
|
||||
const re = new RegExp(`(<w:style [^>]*w:styleId="${styleId}"[^>]*>)([\\s\\S]*?)(</w:style>)`);
|
||||
const match = re.exec(xml);
|
||||
if (!match) continue;
|
||||
let inner = match[2];
|
||||
|
||||
// Drop any existing color/rFonts in the style's rPr, then insert ours
|
||||
inner = inner.replace(/<w:color w:val="[0-9A-Fa-f]{6}"\s*\/>/g, '');
|
||||
inner = inner.replace(/<w:rFonts[^>]*\/>/g, '');
|
||||
|
||||
const patch =
|
||||
`<w:color w:val="${d.headingColor}"/>` +
|
||||
(d.headingFont
|
||||
? `<w:rFonts w:ascii="${d.headingFont}" w:hAnsi="${d.headingFont}" w:cs="${d.headingFont}"/>`
|
||||
: '');
|
||||
|
||||
if (inner.includes('<w:rPr>')) {
|
||||
inner = inner.replace('<w:rPr>', `<w:rPr>${patch}`);
|
||||
} else {
|
||||
// Style without rPr: add one right after the <w:name …/> element
|
||||
inner = inner.replace(/(<w:name [^>]*\/>)/, `$1<w:rPr>${patch}</w:rPr>`);
|
||||
}
|
||||
xml = xml.replace(match[0], `${match[1]}${inner}${match[3]}`);
|
||||
}
|
||||
|
||||
// Hyperlink character style: recolor only
|
||||
const hl = /(<w:style [^>]*w:styleId="Hyperlink"[^>]*>)([\s\S]*?)(<\/w:style>)/.exec(xml);
|
||||
if (hl) {
|
||||
let inner = hl[2].replace(/<w:color w:val="[0-9A-Fa-f]{6}"\s*\/>/g, '');
|
||||
const patch = `<w:color w:val="${d.linkColor}"/>`;
|
||||
if (inner.includes('<w:rPr>')) inner = inner.replace('<w:rPr>', `<w:rPr>${patch}`);
|
||||
else inner = inner.replace(/(<w:name [^>]*\/>)/, `$1<w:rPr>${patch}</w:rPr>`);
|
||||
xml = xml.replace(hl[0], `${hl[1]}${inner}${hl[3]}`);
|
||||
}
|
||||
|
||||
// Body font: patch the docDefaults rPrDefault (affects Normal everywhere)
|
||||
if (d.bodyFont) {
|
||||
const patch = `<w:rFonts w:ascii="${d.bodyFont}" w:hAnsi="${d.bodyFont}" w:cs="${d.bodyFont}"/>`;
|
||||
xml = xml.replace(
|
||||
/(<w:docDefaults>\s*<w:rPrDefault>\s*<w:rPr>)/,
|
||||
`$1${patch}`
|
||||
);
|
||||
}
|
||||
|
||||
zip.file('word/styles.xml', xml);
|
||||
fs.writeFileSync(docxPath, zip.generate({ type: 'nodebuffer' }));
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { THEMES, getTheme, listThemes, buildLatexThemeHeader, applyDocxTheme };
|
||||
@@ -441,10 +441,16 @@ async function loadPdfjs() {
|
||||
|
||||
// Points pdfjs-dist at its bundled standard font metrics so it doesn't warn
|
||||
// (and degrade text-extraction fidelity) when a PDF uses a standard font.
|
||||
// pdfjs validates this as a URL that must end with a forward slash — a raw
|
||||
// Windows path (C:\...\standard_fonts\) fails that check and breaks
|
||||
// extractText/extractImages on Windows, so always hand pdfjs a file:// URL.
|
||||
function getStandardFontDataUrl() {
|
||||
return (
|
||||
path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts') + path.sep
|
||||
const dir = path.join(
|
||||
path.dirname(require.resolve('pdfjs-dist/package.json')),
|
||||
'standard_fonts'
|
||||
);
|
||||
const url = require('url').pathToFileURL(dir);
|
||||
return url.href.endsWith('/') ? url.href : url.href + '/';
|
||||
}
|
||||
|
||||
async function pdfExtractText(data) {
|
||||
|
||||
@@ -2964,6 +2964,26 @@ function initializeExportForm(format) {
|
||||
document.getElementById('custom-geometry').style.display = 'none';
|
||||
}
|
||||
|
||||
// Export theme picker: shown for the formats that support theming; options
|
||||
// come straight from the shared theme definitions (labels + descriptions)
|
||||
const themeRow = document.getElementById('export-theme-row');
|
||||
const themeSelect = document.getElementById('export-theme');
|
||||
if (themeRow && themeSelect) {
|
||||
const themeable = format === 'pdf' || format === 'docx';
|
||||
themeRow.style.display = themeable ? 'flex' : 'none';
|
||||
if (themeSelect.options.length === 0) {
|
||||
const { listThemes } = require('./main/ExportThemes');
|
||||
for (const theme of listThemes()) {
|
||||
const option = document.createElement('option');
|
||||
option.value = theme.id;
|
||||
option.textContent = theme.label;
|
||||
option.title = theme.description;
|
||||
themeSelect.appendChild(option);
|
||||
}
|
||||
}
|
||||
themeSelect.value = 'default';
|
||||
}
|
||||
|
||||
// Toggle and reset Reveal.js-specific fields
|
||||
const revealjsOnly = document.querySelector('.revealjs-only');
|
||||
if (revealjsOnly) {
|
||||
@@ -3076,6 +3096,12 @@ function collectExportOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
// Export theme is available in basic mode too (PDF + DOCX)
|
||||
const themeSelect = document.getElementById('export-theme');
|
||||
if (themeSelect && (currentExportFormat === 'pdf' || currentExportFormat === 'docx')) {
|
||||
options.theme = themeSelect.value || 'default';
|
||||
}
|
||||
|
||||
// Collect page size and orientation (always collected, from basic options)
|
||||
const pageSize = document.getElementById('page-size').value;
|
||||
const pageOrientation = document.getElementById('page-orientation').value;
|
||||
|
||||
@@ -120,6 +120,12 @@ function captureDialogOptions() {
|
||||
: geometrySelect;
|
||||
}
|
||||
|
||||
// Export theme (PDF + DOCX) — stored with presets like engine/geometry
|
||||
if (format === 'pdf' || format === 'docx') {
|
||||
const theme = valueOf('export-theme');
|
||||
if (theme) options.theme = theme;
|
||||
}
|
||||
|
||||
if (format === 'revealjs') {
|
||||
options.revealTheme = valueOf('reveal-theme');
|
||||
options.revealTransition = valueOf('reveal-transition');
|
||||
@@ -206,6 +212,15 @@ function applyPresetToDialog(preset) {
|
||||
setVisible('custom-geometry', true);
|
||||
}
|
||||
|
||||
// Export theme (guard: a preset saved with a newer/older theme list still
|
||||
// applies, falling back to default for unknown ids)
|
||||
const themeSelect = elementById('export-theme');
|
||||
if (themeSelect) {
|
||||
const theme = advancedOptions.theme || 'default';
|
||||
const hasTheme = Array.from(themeSelect.options).some((opt) => opt.value === theme);
|
||||
setValue('export-theme', hasTheme ? theme : 'default');
|
||||
}
|
||||
|
||||
// Reveal.js options
|
||||
setValue('reveal-theme', advancedOptions.revealTheme || 'black');
|
||||
setValue('reveal-transition', advancedOptions.revealTransition || 'slide');
|
||||
|
||||
@@ -119,3 +119,9 @@
|
||||
color: var(--gray-500);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Brand mark in the welcome hero (M↓ mark from the brand kit) */
|
||||
.welcome-mark {
|
||||
display: block;
|
||||
margin: 0 auto 10px;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ function createWelcomeContent(recentFiles = [], appVersion = '') {
|
||||
return `
|
||||
<div class="welcome-container">
|
||||
<div class="welcome-hero">
|
||||
<img src="../assets/markdown-converter-assets/mark.svg" alt="" width="56" height="56" class="welcome-mark" />
|
||||
<h1 class="welcome-title">MarkdownConverter</h1>
|
||||
<p class="welcome-version">${appVersion ? `Version ${appVersion}` : ''}</p>
|
||||
<p class="welcome-subtitle">Professional Markdown Editor & Universal Document Converter</p>
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
*
|
||||
* ExportThemes tests: LaTeX header generation (content + injection safety)
|
||||
* and DOCX styles.xml patching against a minimal pandoc-style fixture.
|
||||
*/
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const PizZip = require('pizzip');
|
||||
const {
|
||||
THEMES,
|
||||
getTheme,
|
||||
listThemes,
|
||||
buildLatexThemeHeader,
|
||||
applyDocxTheme,
|
||||
} = require('../../src/main/ExportThemes');
|
||||
|
||||
// Minimal pandoc-like word/styles.xml: heading + hyperlink styles + docDefaults
|
||||
const STYLES_XML = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
||||
<w:docDefaults>
|
||||
<w:rPrDefault><w:rPr><w:sz w:val="22"/></w:rPr></w:rPrDefault>
|
||||
</w:docDefaults>
|
||||
<w:style w:type="paragraph" w:styleId="Heading1">
|
||||
<w:name w:val="heading 1"/>
|
||||
<w:pPr><w:outlineLvl w:val="0"/></w:pPr>
|
||||
<w:rPr><w:b/><w:sz w:val="32"/></w:rPr>
|
||||
</w:style>
|
||||
<w:style w:type="paragraph" w:styleId="Heading2">
|
||||
<w:name w:val="heading 2"/>
|
||||
<w:rPr><w:b/><w:color w:val="2E74B5"/></w:rPr>
|
||||
</w:style>
|
||||
<w:style w:type="paragraph" w:styleId="Title">
|
||||
<w:name w:val="Title"/>
|
||||
<w:rPr><w:b/></w:rPr>
|
||||
</w:style>
|
||||
<w:style w:type="character" w:styleId="Hyperlink">
|
||||
<w:name w:val="Hyperlink"/>
|
||||
<w:rPr><w:color w:val="0563C1"/><w:u w:val="single"/></w:rPr>
|
||||
</w:style>
|
||||
</w:styles>`;
|
||||
|
||||
function writeDocxFixture(filePath) {
|
||||
const zip = new PizZip();
|
||||
zip.file(
|
||||
'[Content_Types].xml',
|
||||
'<?xml version="1.0"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"/>'
|
||||
);
|
||||
zip.file('word/styles.xml', STYLES_XML);
|
||||
zip.file('word/document.xml', '<w:document/>');
|
||||
fs.writeFileSync(filePath, zip.generate({ type: 'nodebuffer' }));
|
||||
}
|
||||
|
||||
function readStyles(filePath) {
|
||||
return new PizZip(fs.readFileSync(filePath)).file('word/styles.xml').asText();
|
||||
}
|
||||
|
||||
describe('ExportThemes', () => {
|
||||
describe('definitions', () => {
|
||||
it('lists themes with labels in a stable order, default first', () => {
|
||||
const list = listThemes();
|
||||
expect(list[0].id).toBe('default');
|
||||
expect(list.map((t) => t.id)).toEqual(Object.keys(THEMES));
|
||||
expect(list.every((t) => t.label && t.description)).toBe(true);
|
||||
});
|
||||
|
||||
it('falls back to default for unknown ids', () => {
|
||||
expect(getTheme('nope').id).toBeUndefined(); // default theme has no id field
|
||||
expect(getTheme('nope').label).toBe('Default (Pandoc)');
|
||||
expect(getTheme('modern').label).toBe('Modern');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildLatexThemeHeader', () => {
|
||||
it('returns null for the default theme', () => {
|
||||
expect(buildLatexThemeHeader('default')).toBeNull();
|
||||
expect(buildLatexThemeHeader('unknown-id')).toBeNull();
|
||||
});
|
||||
|
||||
it('emits xcolor, heading color, and titlesec formatting', () => {
|
||||
const tex = buildLatexThemeHeader('modern');
|
||||
expect(tex).toContain('\\usepackage{xcolor}');
|
||||
// \definecolor{mcthemeheading}{HTML}{1E4FD8}
|
||||
expect(tex).toContain('\\definecolor{mcthemeheading}{HTML}{1E4FD8}');
|
||||
expect(tex).toContain('\\definecolor{mcthemelink}{HTML}{0E7490}');
|
||||
expect(tex).toContain('\\titleformat{\\section}');
|
||||
// modern = sans headings
|
||||
expect(tex).toContain('helvet');
|
||||
});
|
||||
|
||||
it('omits section rules and helvet for themes that decline them', () => {
|
||||
const tex = buildLatexThemeHeader('minimal');
|
||||
expect(tex).not.toContain('helvet');
|
||||
expect(tex).not.toContain('titlerule');
|
||||
});
|
||||
|
||||
it('only inlines hex literals (no user input reaches LaTeX)', () => {
|
||||
for (const id of Object.keys(THEMES)) {
|
||||
const tex = buildLatexThemeHeader(id);
|
||||
if (!tex) continue;
|
||||
// Every color is the {HTML}{HEXHEXHEX} literal form
|
||||
const colors = tex.match(/\{HTML\}\{([^}]*)\}/g) || [];
|
||||
expect(colors.length).toBeGreaterThan(0);
|
||||
for (const c of colors) {
|
||||
expect(c).toMatch(/^\{HTML\}\{[A-F0-9]{6}\}$/);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('applyDocxTheme', () => {
|
||||
let tmpDir, docxPath;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'theme_'));
|
||||
docxPath = path.join(tmpDir, 'doc.docx');
|
||||
writeDocxFixture(docxPath);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
||||
});
|
||||
|
||||
it('is a no-op returning false for the default theme', () => {
|
||||
expect(applyDocxTheme(docxPath, 'default')).toBe(false);
|
||||
expect(readStyles(docxPath)).toBe(STYLES_XML);
|
||||
});
|
||||
|
||||
it('recolors headings, swaps heading font, and recolors hyperlinks', () => {
|
||||
const applied = applyDocxTheme(docxPath, 'modern');
|
||||
expect(applied).toBe(true);
|
||||
|
||||
const xml = readStyles(docxPath);
|
||||
// Heading color + font injected
|
||||
expect(xml).toContain('<w:color w:val="1E4FD8"/>');
|
||||
expect(xml).toContain('w:ascii="Calibri"');
|
||||
// Heading2's old color is replaced, not duplicated
|
||||
expect(xml).not.toContain('2E74B5');
|
||||
const h1 = /w:styleId="Heading1"[\s\S]*?<\/w:style>/.exec(xml)[0];
|
||||
expect(h1.match(/<w:color/g)).toHaveLength(1);
|
||||
// Hyperlink recolored
|
||||
expect(xml).not.toContain('0563C1');
|
||||
expect(xml).toContain('<w:color w:val="0E7490"/>');
|
||||
// Body font lands in docDefaults
|
||||
expect(xml).toMatch(/<w:rPrDefault>\s*<w:rPr><w:rFonts w:ascii="Calibri"/);
|
||||
});
|
||||
|
||||
it('preserves unrelated style content', () => {
|
||||
applyDocxTheme(docxPath, 'classic');
|
||||
const xml = readStyles(docxPath);
|
||||
expect(xml).toContain('<w:sz w:val="32"/>');
|
||||
expect(xml).toContain('<w:u w:val="single"/>');
|
||||
expect(xml).toContain('<w:outlineLvl w:val="0"/>');
|
||||
});
|
||||
|
||||
it('tolerates styles.xml without an rPr block in a style', () => {
|
||||
// Title style in the fixture has rPr; craft one without it
|
||||
const bare = STYLES_XML.replace(
|
||||
/(<w:style w:type="paragraph" w:styleId="Title">\s*<w:name w:val="Title"\/>)\s*<w:rPr><w:b\/><\/w:rPr>/,
|
||||
'$1'
|
||||
);
|
||||
const zip = new PizZip();
|
||||
zip.file('[Content_Types].xml', '<Types/>');
|
||||
zip.file('word/styles.xml', bare);
|
||||
fs.writeFileSync(docxPath, zip.generate({ type: 'nodebuffer' }));
|
||||
|
||||
expect(applyDocxTheme(docxPath, 'sepia')).toBe(true);
|
||||
const xml = readStyles(docxPath);
|
||||
const title = /w:styleId="Title"[\s\S]*?<\/w:style>/.exec(xml)[0];
|
||||
expect(title).toContain('<w:color w:val="7C4A21"/>');
|
||||
});
|
||||
|
||||
it('returns false when styles.xml is missing', () => {
|
||||
const zip = new PizZip();
|
||||
zip.file('[Content_Types].xml', '<Types/>');
|
||||
fs.writeFileSync(docxPath, zip.generate({ type: 'nodebuffer' }));
|
||||
expect(applyDocxTheme(docxPath, 'modern')).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -15,7 +15,15 @@ describe('ImageOperations', () => {
|
||||
.png()
|
||||
.toFile(inputPath);
|
||||
});
|
||||
afterEach(() => fs.rmSync(tmpDir, { recursive: true, force: true }));
|
||||
// Windows: sharp can hold the file handle briefly after await returns,
|
||||
// so plain rmSync throws EPERM — retry and tolerate stale temp dirs.
|
||||
afterEach(() => {
|
||||
try {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
||||
} catch {
|
||||
/* leftover temp dir is cosmetic on locked-file platforms */
|
||||
}
|
||||
});
|
||||
|
||||
test('imageConvert converts PNG to JPEG', async () => {
|
||||
const outputPath = path.join(tmpDir, 'out.jpg');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
* @jest-environment-options {"testTimeout": 30000}
|
||||
*
|
||||
* PDFBatchOperations.js tests for Task 22's batch PDF operations: the folder
|
||||
* loop that applies one PDFOperations.executeOperation() op to every .pdf in an
|
||||
@@ -293,7 +294,9 @@ describe('PDFBatchOperations - runPDFBatchOperation', () => {
|
||||
operation: 'compress',
|
||||
outputFolder: path.join(blocker, 'child'),
|
||||
data: {},
|
||||
sanitizeError: (message) => message.replace(new RegExp(path.sep, 'g'), '_SANITIZED_'),
|
||||
// path.sep is "\" on Windows — escape it for RegExp use
|
||||
sanitizeError: (message) =>
|
||||
message.replace(new RegExp(path.sep.replace(/\\/g, '\\\\'), 'g'), '_SANITIZED_'),
|
||||
});
|
||||
|
||||
expect(completion.success).toBe(false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* @jest-environment node
|
||||
* @jest-environment-options {"testTimeout": 30000}
|
||||
*
|
||||
* PDFOperations.js tests for Task 15's new operations: extractText, pageNumbers,
|
||||
* crop, extractImages. Uses pdf-lib to build minimal fixture PDFs at test time,
|
||||
@@ -47,13 +48,19 @@ describe('PDFOperations - Task 15 new operations', () => {
|
||||
});
|
||||
|
||||
describe('pdfExtractText', () => {
|
||||
it('extracts text from all pages', async () => {
|
||||
const result = await PDFOperations.pdfExtractText({ inputPath });
|
||||
it(
|
||||
'extracts text from all pages',
|
||||
async () => {
|
||||
const result = await PDFOperations.pdfExtractText({ inputPath });
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.text).toContain('Hello Task 15 Page One');
|
||||
expect(result.text).toContain('Second Page Content');
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.text).toContain('Hello Task 15 Page One');
|
||||
expect(result.text).toContain('Second Page Content');
|
||||
},
|
||||
// First pdfjs-dist legacy import can exceed the 5s default on slower
|
||||
// CI runners (observed on windows-latest)
|
||||
30000
|
||||
);
|
||||
|
||||
it('returns failure for a nonexistent file', async () => {
|
||||
const result = await PDFOperations.pdfExtractText({
|
||||
@@ -150,38 +157,42 @@ describe('PDFOperations - Task 15 new operations', () => {
|
||||
});
|
||||
|
||||
describe('pdfExtractImages', () => {
|
||||
it('extracts embedded raster images as PNG files', async () => {
|
||||
const imgPath = path.join(tmpDir, 'red.png');
|
||||
await sharp({
|
||||
create: { width: 20, height: 20, channels: 3, background: { r: 255, g: 0, b: 0 } },
|
||||
})
|
||||
.png()
|
||||
.toFile(imgPath);
|
||||
it(
|
||||
'extracts embedded raster images as PNG files',
|
||||
async () => {
|
||||
const imgPath = path.join(tmpDir, 'red.png');
|
||||
await sharp({
|
||||
create: { width: 20, height: 20, channels: 3, background: { r: 255, g: 0, b: 0 } },
|
||||
})
|
||||
.png()
|
||||
.toFile(imgPath);
|
||||
|
||||
const doc = await PDFDocument.create();
|
||||
const page = doc.addPage([300, 300]);
|
||||
const pngImage = await doc.embedPng(fs.readFileSync(imgPath));
|
||||
page.drawImage(pngImage, { x: 50, y: 50, width: 100, height: 100 });
|
||||
const doc = await PDFDocument.create();
|
||||
const page = doc.addPage([300, 300]);
|
||||
const pngImage = await doc.embedPng(fs.readFileSync(imgPath));
|
||||
page.drawImage(pngImage, { x: 50, y: 50, width: 100, height: 100 });
|
||||
|
||||
const imagePdfPath = path.join(tmpDir, 'with-image.pdf');
|
||||
fs.writeFileSync(imagePdfPath, await doc.save());
|
||||
const imagePdfPath = path.join(tmpDir, 'with-image.pdf');
|
||||
fs.writeFileSync(imagePdfPath, await doc.save());
|
||||
|
||||
const outputDir = path.join(tmpDir, 'extracted');
|
||||
const result = await PDFOperations.pdfExtractImages({
|
||||
inputPath: imagePdfPath,
|
||||
outputDir,
|
||||
});
|
||||
const outputDir = path.join(tmpDir, 'extracted');
|
||||
const result = await PDFOperations.pdfExtractImages({
|
||||
inputPath: imagePdfPath,
|
||||
outputDir,
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.count).toBeGreaterThanOrEqual(1);
|
||||
expect(result.files.length).toBe(result.count);
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.count).toBeGreaterThanOrEqual(1);
|
||||
expect(result.files.length).toBe(result.count);
|
||||
|
||||
for (const file of result.files) {
|
||||
expect(fs.existsSync(file)).toBe(true);
|
||||
const meta = await sharp(file).metadata();
|
||||
expect(meta.format).toBe('png');
|
||||
}
|
||||
});
|
||||
for (const file of result.files) {
|
||||
expect(fs.existsSync(file)).toBe(true);
|
||||
const meta = await sharp(file).metadata();
|
||||
expect(meta.format).toBe('png');
|
||||
}
|
||||
},
|
||||
30000 // pdfjs import + sharp decode on slower CI runners
|
||||
);
|
||||
|
||||
it('returns zero images for a text-only PDF', async () => {
|
||||
const outputDir = path.join(tmpDir, 'extracted-none');
|
||||
|
||||
@@ -22,7 +22,10 @@ describe('MonospaceFontConfig', () => {
|
||||
(p) => !p.includes('app.asar.unpacked') && p.endsWith('JetBrainsMono-Regular.ttf')
|
||||
);
|
||||
const p = MonospaceFontConfig.getMonoFontTtfPath('jetbrains-mono', 400);
|
||||
expect(p).toMatch(/assets\/fonts\/JetBrainsMono-Regular\.ttf$/);
|
||||
// Normalize separators: Windows paths are backslash-joined
|
||||
expect(p.split(require('path').sep).join('/')).toMatch(
|
||||
/assets\/fonts\/JetBrainsMono-Regular\.ttf$/
|
||||
);
|
||||
});
|
||||
|
||||
test('returns packaged asar.unpacked path when present and file exists', () => {
|
||||
|
||||