mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-03 02:11:07 +05:30
- PdfFontHeader: use mkdtempSync for exclusive temp dir; caller unlinks after pandoc consumes (cleanup wired into exportWithPandoc callback) - download-tools: pin FiraCode to immutable release v6.2 with SHA-256 digests verified before atomic rename; refuse download on mismatch - Vendor missing FiraCode-Bold.ttf + JetBrainsMono-Regular.ttf
68 lines
2.2 KiB
JavaScript
68 lines
2.2 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
|
|
const { buildPdfFontHeader } = require('../../../../src/main/PdfFontHeader');
|
|
|
|
describe('PdfFontHeader', () => {
|
|
let tmpDir;
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mono-pdfhdr-'));
|
|
});
|
|
afterEach(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('writes a fontspec header for JetBrains Mono Regular', () => {
|
|
const ttf = path.join(tmpDir, 'JetBrainsMono-Regular.ttf');
|
|
fs.writeFileSync(ttf, 'fake');
|
|
const out = buildPdfFontHeader(
|
|
{ monospaceFont: 'jetbrains-mono', monospaceLigatures: false },
|
|
ttf,
|
|
'JetBrains Mono'
|
|
);
|
|
expect(typeof out.headerPath).toBe('string');
|
|
expect(fs.existsSync(out.headerPath)).toBe(true);
|
|
const content = fs.readFileSync(out.headerPath, 'utf-8');
|
|
expect(content).toContain('\\setmonofont');
|
|
expect(content).toContain('JetBrainsMono-Regular.ttf');
|
|
expect(out.familyName).toBe('JetBrains Mono');
|
|
fs.rmSync(out.dir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('writes header with ligatures when enabled', () => {
|
|
const ttf = path.join(tmpDir, 'FiraCode-Regular.ttf');
|
|
fs.writeFileSync(ttf, 'fake');
|
|
const out = buildPdfFontHeader(
|
|
{ monospaceFont: 'fira-code', monospaceLigatures: true },
|
|
ttf,
|
|
'Fira Code'
|
|
);
|
|
const content = fs.readFileSync(out.headerPath, 'utf-8');
|
|
expect(content).toContain('Ligatures=TeX');
|
|
fs.rmSync(out.dir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('header is written under os.tmpdir', () => {
|
|
const ttf = path.join(tmpDir, 'JetBrainsMono-Regular.ttf');
|
|
fs.writeFileSync(ttf, 'fake');
|
|
const out = buildPdfFontHeader(
|
|
{ monospaceFont: 'jetbrains-mono', monospaceLigatures: false },
|
|
ttf,
|
|
'JetBrains Mono'
|
|
);
|
|
expect(out.headerPath.startsWith(os.tmpdir())).toBe(true);
|
|
fs.rmSync(out.dir, { recursive: true, force: true });
|
|
});
|
|
|
|
test('throws if ttfPath does not exist', () => {
|
|
expect(() =>
|
|
buildPdfFontHeader(
|
|
{ monospaceFont: 'jetbrains-mono', monospaceLigatures: false },
|
|
'/nonexistent.ttf',
|
|
'JetBrains Mono'
|
|
)
|
|
).toThrow(/TTF/);
|
|
});
|
|
});
|