@textbrocken/cv 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matthias Bärwolff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Professioneller Lebenslauf per Markdown
2
+
3
+ Erzeugt PDF-Dateien aus Markdown oder JSON5. Zum Beispiel aus [dieser Markdown-Datei](./examples/text.md).
4
+
5
+ Verwendet professionelle Schriften (Cinzel, KpRoman) mit Mediävalziffern und Ligaturen.
6
+
7
+ ## Voraussetzungen
8
+
9
+ - Node.js >= 22
10
+
11
+ ## Ausführen
12
+
13
+ ```bash
14
+ # Mit Markdown-Datei (empfohlen)
15
+ npx @textbrocken/cv -i lebenslauf.md
16
+
17
+ # Mit JSON5
18
+ npx @textbrocken/cv -i lebenslauf.json5
19
+
20
+ # Via stdin
21
+ cat lebenslauf.md | npx @textbrocken/cv
22
+ ```
23
+
24
+ ## Markdown-Format
25
+
26
+ ```markdown
27
+ ---
28
+ meta:
29
+ hyphenate: true
30
+ header: Lebenslauf
31
+ salutation: Max Mustermann
32
+ ---
33
+
34
+ **Max Mustermann**
35
+ Musterstraße 1, 12345 Musterstadt
36
+ max@example.com
37
+
38
+ ## Berufserfahrung
39
+
40
+ ### 2020–2024
41
+ **Senior Developer** bei Beispiel GmbH
42
+ - Entwicklung von Webanwendungen
43
+ - Teamleitung
44
+
45
+ ### 2018–2020
46
+ **Junior Developer** bei Startup AG
47
+
48
+ ## Ausbildung
49
+
50
+ ### 2014–2018
51
+ Studium der Informatik, TU Musterstadt
52
+ ```
53
+
54
+ ## Datenstruktur
55
+
56
+ | Feld | Typ | Beschreibung |
57
+ |------|-----|--------------|
58
+ | `header` | String | Überschrift des Dokuments |
59
+ | `salutation` | String | Name für die Unterschrift |
60
+ | `basics` | Array | Persönliche Daten (vor dem ersten `##`) |
61
+ | `body` | Array | Sektionen mit `header` und `sections` |
62
+ | `body[].header` | String | Sektionsüberschrift (`## ...`) |
63
+ | `body[].sections` | Array | Items mit `prefix` und `elaboration` |
64
+
65
+ ## Meta-Optionen
66
+
67
+ | Feld | Typ | Beschreibung | Default |
68
+ |------|-----|--------------|---------|
69
+ | `meta.date` | String | Datum für Unterschrift (z.B. `"1. März 2026"`) | Heute |
70
+ | `meta.hyphenate` | Boolean | Deutsche Silbentrennung | `true` |
71
+ | `meta.fixTypesetting` | Boolean | Typographische Korrekturen (Anführungszeichen, Bindestriche, Ellipsen) | `true` |
72
+
73
+ ## CLI-Optionen
74
+
75
+ | Option | Beschreibung |
76
+ |--------|--------------|
77
+ | `-i, --input` | Eingabedatei (Markdown oder JSON5) |
78
+ | `-o, --output` | Ausgabe-PDF (Standard: Eingabename + `.pdf`) |
79
+ | `-v, --verbose` | Ausführliche Ausgabe |
80
+ | `-q, --quiet` | Keine Ausgabe |
81
+ | `-a, --auto-open` | PDF nach Erstellung öffnen (Standard: `true`) |
82
+
83
+ ## Features
84
+
85
+ - **Deutsche Typographie**: Automatische Umwandlung von `"Anführungszeichen"` → „Anführungszeichen", `--` → –, `...` → …
86
+ - **Silbentrennung**: Deutsche Silbentrennung für sauberen Blocksatz
87
+ - **Mediävalziffern**: Zahlen im klassischen Stil (3, 4, 5, 7, 9 mit Unterlängen)
88
+ - **Markdown**: Fett, kursiv und Aufzählungen im Text
89
+ - **Mehrseitige Dokumente**: Automatische Seitenumbrüche mit Schutz vor verwaisten Überschriften
package/cli.mjs ADDED
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+
3
+ import meow from 'meow';
4
+ import JSON5 from 'json5';
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import { inspect } from 'util';
8
+ import open from 'open';
9
+ import { parseMarkdownCV } from './lib/parse.js';
10
+ import { render } from './lib/render.js';
11
+
12
+ async function getStdin() {
13
+ if (process.stdin.isTTY) return '';
14
+ const chunks = [];
15
+ for await (const chunk of process.stdin) chunks.push(chunk);
16
+ return Buffer.concat(chunks).toString('utf8');
17
+ }
18
+
19
+ const BANNER = `
20
+ _____ ____ _ _ ___ ___ ____ ____ ____ _ _ ____ _ _ / ____ _ _
21
+ | |___ \\/ | |__] |__/ | | | |_/ |___ |\\ | / | | |
22
+ @ | |___ _/\\_ | |__] | \\ |__| |___ | \\_ |___ | \\| / |___ \\/
23
+ `.trim();
24
+
25
+ const DONE = `
26
+ ___ ____ _ _ ____
27
+ | \\ | | |\\ | |___
28
+ |__/ |__| | \\| |___
29
+ `.trim();
30
+
31
+ const trim = (s, len = 16) => s?.length > len ? s.slice(0, len) + '…' : s;
32
+
33
+ function summarize(data) {
34
+ return {
35
+ header: trim(data.header),
36
+ basics: data.basics?.length + ' lines',
37
+ body: data.body?.map(s => ({
38
+ header: trim(s.header),
39
+ sections: s.sections?.map(item => trim(item.prefix))
40
+ })),
41
+ salutation: trim(data.salutation)
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Parse input content based on format detection.
47
+ * Supports: Markdown (with YAML frontmatter), JSON5/JSON
48
+ */
49
+ function parseInput(content, filename = '') {
50
+ const ext = filename ? path.extname(filename).toLowerCase() : '';
51
+
52
+ // Detect markdown by extension or frontmatter
53
+ if (ext === '.md' || ext === '.markdown' || content.trimStart().startsWith('---\n')) {
54
+ return parseMarkdownCV(content);
55
+ }
56
+
57
+ // JSON5 (superset of JSON)
58
+ try {
59
+ return JSON5.parse(content);
60
+ } catch (e) {
61
+ console.error('❌ Failed to parse input as JSON5');
62
+ console.error(' ' + e.message);
63
+ process.exit(1);
64
+ }
65
+ }
66
+
67
+ const cli = meow(`
68
+ Usage
69
+ $ npx @textbrocken/cv -i <input file name> -o <output file name>
70
+
71
+ Options
72
+ -i, --input, Input file: Markdown (.md) or JSON5 (.json5)
73
+ -o, --output Output PDF file (defaults to input file name with .pdf extension)
74
+ -v, --verbose Log verbosely (default false)
75
+ -q, --quiet Log nothing (default false)
76
+ -a, --auto-open Open PDF file in PDF viewer (default true)
77
+
78
+ Examples
79
+ $ npx @textbrocken/cv -i cv.md -o cv.pdf
80
+ $ npx @textbrocken/cv -i cv.json5
81
+ `, {
82
+ importMeta: import.meta,
83
+ flags: {
84
+ input: {
85
+ type: 'string',
86
+ shortFlag: 'i'
87
+ },
88
+ output: {
89
+ type: 'string',
90
+ shortFlag: 'o'
91
+ },
92
+ verbose: {
93
+ shortFlag: 'v',
94
+ type: 'boolean',
95
+ default: false
96
+ },
97
+ quiet: {
98
+ shortFlag: 'q',
99
+ type: 'boolean',
100
+ default: false
101
+ },
102
+ 'autoOpen': {
103
+ shortFlag: 'a',
104
+ type: 'boolean',
105
+ default: true
106
+ },
107
+ help: {
108
+ shortFlag: 'h',
109
+ type: 'boolean'
110
+ }
111
+ }
112
+ });
113
+
114
+ global.logVerbose = cli.flags.verbose;
115
+ global.logNothing = cli.flags.quiet;
116
+
117
+ global.logNothing || console.log(BANNER + '\n');
118
+
119
+ const stdin = await getStdin();
120
+ const inputFile = cli.flags.input;
121
+
122
+ // Validate file extension before reading
123
+ if (inputFile) {
124
+ const ext = path.extname(inputFile).toLowerCase();
125
+ const validExtensions = ['.md', '.markdown', '.json5', '.json'];
126
+ if (ext && !validExtensions.includes(ext)) {
127
+ console.error(`❌ Unsupported file format "${ext}"`);
128
+ console.error(` Supported: ${validExtensions.join(', ')}`);
129
+ process.exit(1);
130
+ }
131
+ }
132
+
133
+ const inputContent = stdin || (inputFile && fs.readFileSync(inputFile, 'utf8'));
134
+
135
+ if (!inputContent) {
136
+ console.log('❌ No input found, call with --help to learn more');
137
+ process.exit(1);
138
+ }
139
+
140
+ global.logVerbose && console.log('⚙️ flags:', {
141
+ input: cli.flags.input,
142
+ output: cli.flags.output || '(auto)',
143
+ autoOpen: cli.flags.autoOpen
144
+ });
145
+
146
+ const inputData = parseInput(inputContent, inputFile || '');
147
+ global.logVerbose && console.log('📄 parsed:', inspect(summarize(inputData), { depth: 4, colors: true }));
148
+
149
+ const outFile = path.resolve(
150
+ cli.flags.output ||
151
+ (inputFile
152
+ ? path.parse(inputFile).name + '.pdf'
153
+ : `letter-${Date.now().toString()}.pdf`)
154
+ );
155
+
156
+ global.logVerbose && console.log('📁 output:', outFile);
157
+
158
+ await render(inputData, outFile);
159
+ cli.flags.autoOpen && await open(outFile, {wait: false});
160
+ global.logNothing || console.log(DONE);
@@ -0,0 +1,93 @@
1
+ Copyright 2020 The Cinzel Project Authors (https://github.com/NDISCOVER/Cinzel)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
Binary file
@@ -0,0 +1,97 @@
1
+ Copyright (c) <dates>, <Copyright Holder> (<URL|email>),
2
+ with Reserved Font Name <Reserved Font Name>.
3
+ Copyright (c) <dates>, <additional Copyright Holder> (<URL|email>),
4
+ with Reserved Font Name <additional Reserved Font Name>.
5
+ Copyright (c) <dates>, <additional Copyright Holder> (<URL|email>).
6
+
7
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
8
+ This license is copied below, and is also available with a FAQ at:
9
+ http://scripts.sil.org/OFL
10
+
11
+
12
+ -----------------------------------------------------------
13
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
14
+ -----------------------------------------------------------
15
+
16
+ PREAMBLE
17
+ The goals of the Open Font License (OFL) are to stimulate worldwide
18
+ development of collaborative font projects, to support the font creation
19
+ efforts of academic and linguistic communities, and to provide a free and
20
+ open framework in which fonts may be shared and improved in partnership
21
+ with others.
22
+
23
+ The OFL allows the licensed fonts to be used, studied, modified and
24
+ redistributed freely as long as they are not sold by themselves. The
25
+ fonts, including any derivative works, can be bundled, embedded,
26
+ redistributed and/or sold with any software provided that any reserved
27
+ names are not used by derivative works. The fonts and derivatives,
28
+ however, cannot be released under any other type of license. The
29
+ requirement for fonts to remain under this license does not apply
30
+ to any document created using the fonts or their derivatives.
31
+
32
+ DEFINITIONS
33
+ "Font Software" refers to the set of files released by the Copyright
34
+ Holder(s) under this license and clearly marked as such. This may
35
+ include source files, build scripts and documentation.
36
+
37
+ "Reserved Font Name" refers to any names specified as such after the
38
+ copyright statement(s).
39
+
40
+ "Original Version" refers to the collection of Font Software components as
41
+ distributed by the Copyright Holder(s).
42
+
43
+ "Modified Version" refers to any derivative made by adding to, deleting,
44
+ or substituting -- in part or in whole -- any of the components of the
45
+ Original Version, by changing formats or by porting the Font Software to a
46
+ new environment.
47
+
48
+ "Author" refers to any designer, engineer, programmer, technical
49
+ writer or other person who contributed to the Font Software.
50
+
51
+ PERMISSION & CONDITIONS
52
+ Permission is hereby granted, free of charge, to any person obtaining
53
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
54
+ redistribute, and sell modified and unmodified copies of the Font
55
+ Software, subject to the following conditions:
56
+
57
+ 1) Neither the Font Software nor any of its individual components,
58
+ in Original or Modified Versions, may be sold by itself.
59
+
60
+ 2) Original or Modified Versions of the Font Software may be bundled,
61
+ redistributed and/or sold with any software, provided that each copy
62
+ contains the above copyright notice and this license. These can be
63
+ included either as stand-alone text files, human-readable headers or
64
+ in the appropriate machine-readable metadata fields within text or
65
+ binary files as long as those fields can be easily viewed by the user.
66
+
67
+ 3) No Modified Version of the Font Software may use the Reserved Font
68
+ Name(s) unless explicit written permission is granted by the corresponding
69
+ Copyright Holder. This restriction only applies to the primary font name as
70
+ presented to the users.
71
+
72
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
73
+ Software shall not be used to promote, endorse or advertise any
74
+ Modified Version, except to acknowledge the contribution(s) of the
75
+ Copyright Holder(s) and the Author(s) or with their explicit written
76
+ permission.
77
+
78
+ 5) The Font Software, modified or unmodified, in part or in whole,
79
+ must be distributed entirely under this license, and must not be
80
+ distributed under any other license. The requirement for fonts to
81
+ remain under this license does not apply to any document created
82
+ using the Font Software.
83
+
84
+ TERMINATION
85
+ This license becomes null and void if any of the above conditions are
86
+ not met.
87
+
88
+ DISCLAIMER
89
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
91
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
92
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
93
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
94
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
95
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
96
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
97
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,6 @@
1
+ import pkg from 'hyphen/de/index.js';
2
+ const { hyphenateSync } = pkg;
3
+
4
+ export function hyphenate(text) {
5
+ return hyphenateSync(text);
6
+ }
package/lib/parse.js ADDED
@@ -0,0 +1,119 @@
1
+ import yaml from 'js-yaml';
2
+
3
+ /**
4
+ * Parse markdown with YAML frontmatter into the CV data structure.
5
+ *
6
+ * Format:
7
+ * ---
8
+ * meta: { ... }
9
+ * header: "Title"
10
+ * salutation: "Name"
11
+ * ---
12
+ *
13
+ * Intro lines (become `basics`)
14
+ *
15
+ * ## Section Header
16
+ *
17
+ * ### Prefix (e.g., date range)
18
+ * Elaboration content with markdown...
19
+ */
20
+ export function parseMarkdownCV(content) {
21
+ // Extract frontmatter
22
+ const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
23
+ if (!frontmatterMatch) {
24
+ throw new Error('Invalid format: missing YAML frontmatter (---\\n...\\n---)');
25
+ }
26
+
27
+ const frontmatter = yaml.load(frontmatterMatch[1]);
28
+ const markdown = frontmatterMatch[2].trim();
29
+
30
+ // Split into sections by ## headers
31
+ const sectionRegex = /^## (.+)$/gm;
32
+ const sections = [];
33
+ let basicsContent = '';
34
+ let match;
35
+
36
+ // Find all ## headers
37
+ const matches = [];
38
+ while ((match = sectionRegex.exec(markdown)) !== null) {
39
+ matches.push({ header: match[1], index: match.index, end: match.index + match[0].length });
40
+ }
41
+
42
+ if (matches.length === 0) {
43
+ // No sections, everything is basics
44
+ basicsContent = markdown;
45
+ } else {
46
+ // Content before first ## is basics
47
+ basicsContent = markdown.slice(0, matches[0].index).trim();
48
+
49
+ // Extract each section
50
+ for (let i = 0; i < matches.length; i++) {
51
+ const start = matches[i].end;
52
+ const end = i + 1 < matches.length ? matches[i + 1].index : markdown.length;
53
+ const sectionContent = markdown.slice(start, end).trim();
54
+
55
+ sections.push({
56
+ header: matches[i].header,
57
+ sections: parseItems(sectionContent),
58
+ });
59
+ }
60
+ }
61
+
62
+ // Parse basics: each non-empty line becomes an item
63
+ const basics = basicsContent
64
+ .split('\n')
65
+ .map(line => line.trim())
66
+ .filter(line => line.length > 0);
67
+
68
+ return {
69
+ meta: frontmatter.meta || {},
70
+ header: frontmatter.header || 'CV',
71
+ basics,
72
+ body: sections,
73
+ salutation: frontmatter.salutation || '',
74
+ };
75
+ }
76
+
77
+ /**
78
+ * Parse section content into items (prefix/elaboration pairs).
79
+ * Each ### header starts a new item with the header as prefix.
80
+ */
81
+ function parseItems(content) {
82
+ const itemRegex = /^### (.+)$/gm;
83
+ const items = [];
84
+ let match;
85
+
86
+ // Find all ### headers
87
+ const matches = [];
88
+ while ((match = itemRegex.exec(content)) !== null) {
89
+ matches.push({ prefix: match[1], index: match.index, end: match.index + match[0].length });
90
+ }
91
+
92
+ if (matches.length === 0) {
93
+ // No items with prefix, treat entire content as single item without prefix
94
+ if (content.trim()) {
95
+ items.push({ prefix: '', elaboration: content.trim() });
96
+ }
97
+ return items;
98
+ }
99
+
100
+ // Content before first ### (if any) becomes item without prefix
101
+ const preamble = content.slice(0, matches[0].index).trim();
102
+ if (preamble) {
103
+ items.push({ prefix: '', elaboration: preamble });
104
+ }
105
+
106
+ // Extract each item
107
+ for (let i = 0; i < matches.length; i++) {
108
+ const start = matches[i].end;
109
+ const end = i + 1 < matches.length ? matches[i + 1].index : content.length;
110
+ const elaboration = content.slice(start, end).trim();
111
+
112
+ items.push({
113
+ prefix: matches[i].prefix,
114
+ elaboration,
115
+ });
116
+ }
117
+
118
+ return items;
119
+ }
package/lib/render.js ADDED
@@ -0,0 +1,194 @@
1
+ import React from 'react';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { Document, Page, Text, View, Font, StyleSheet, renderToFile } from '@react-pdf/renderer';
5
+ import { hyphenate } from './hyphenate.js';
6
+ import { typeset } from './typeset.js';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ Font.register({
11
+ family: 'Cinzel',
12
+ src: path.join(__dirname, '../fonts/Cinzel/Cinzel-VariableFont_wght.ttf'),
13
+ });
14
+
15
+ Font.register({
16
+ family: 'KpRoman',
17
+ fonts: [
18
+ { src: path.join(__dirname, '../fonts/Kp-fonts/KpRoman-Regular.otf'), fontWeight: 'normal' },
19
+ { src: path.join(__dirname, '../fonts/Kp-fonts/KpRoman-Semibold.otf'), fontWeight: 'semibold' },
20
+ { src: path.join(__dirname, '../fonts/Kp-fonts/KpRoman-Italic.otf'), fontWeight: 'normal', fontStyle: 'italic' },
21
+ ],
22
+ });
23
+
24
+ Font.registerHyphenationCallback(word => [word]);
25
+
26
+ const mm = (val) => val * 2.83465;
27
+
28
+ const onum = { onum: true, liga: true };
29
+
30
+ const styles = StyleSheet.create({
31
+ page: {
32
+ paddingTop: mm(20), paddingBottom: mm(25), paddingRight: mm(20), paddingLeft: mm(25),
33
+ fontFamily: 'KpRoman', fontSize: 11, lineHeight: 1.4,
34
+ },
35
+ headerBox: { height: mm(25) },
36
+ headerText: { fontFamily: 'Cinzel', fontSize: 14, features: onum },
37
+ basics: { marginBottom: mm(8) },
38
+ basicsItem: { marginBottom: 1, features: onum },
39
+ sectionHeader: { fontFamily: 'Cinzel', fontSize: 12, marginTop: mm(6), marginBottom: mm(3), features: onum },
40
+ item: { flexDirection: 'row', marginBottom: mm(2) },
41
+ prefix: { width: '25%', paddingRight: mm(4), features: onum },
42
+ elab: { flex: 1 },
43
+ elabText: { features: onum },
44
+ bulletList: { marginLeft: mm(3), marginTop: mm(1) },
45
+ bulletItem: { flexDirection: 'row', marginBottom: mm(0.5) },
46
+ bullet: { width: mm(4) },
47
+ bulletText: { flex: 1, features: onum },
48
+ bold: { fontWeight: 'semibold', features: onum },
49
+ italic: { fontStyle: 'italic', features: onum },
50
+ salutation: { marginTop: mm(10), features: onum },
51
+ });
52
+
53
+ function parseInline(text) {
54
+ if (!text || typeof text !== 'string') return text;
55
+
56
+ const parts = [];
57
+ const regex = /(\*\*(.+?)\*\*|\*(.+?)\*)/g;
58
+ let lastIndex = 0;
59
+ let match;
60
+ let key = 0;
61
+
62
+ while ((match = regex.exec(text)) !== null) {
63
+ if (match.index > lastIndex) {
64
+ parts.push(text.slice(lastIndex, match.index));
65
+ }
66
+ if (match[2]) {
67
+ parts.push(React.createElement(Text, { key: key++, style: styles.bold }, match[2]));
68
+ } else if (match[3]) {
69
+ parts.push(React.createElement(Text, { key: key++, style: styles.italic }, match[3]));
70
+ }
71
+ lastIndex = match.index + match[0].length;
72
+ }
73
+
74
+ if (lastIndex < text.length) {
75
+ parts.push(text.slice(lastIndex));
76
+ }
77
+
78
+ return parts.length > 0 ? parts : text;
79
+ }
80
+
81
+ function parseElaboration(text, shouldHyphenate, shouldTypeset) {
82
+ if (!text) return null;
83
+ if (shouldTypeset) text = typeset(text);
84
+ if (shouldHyphenate) text = hyphenate(text);
85
+
86
+ const lines = text.split('\n');
87
+ const elements = [];
88
+ let bullets = [];
89
+ let key = 0;
90
+
91
+ const flushBullets = () => {
92
+ if (bullets.length > 0) {
93
+ elements.push(
94
+ React.createElement(View, { key: 'bl' + key++, style: styles.bulletList },
95
+ bullets.map((b, i) =>
96
+ React.createElement(View, { key: i, style: styles.bulletItem },
97
+ React.createElement(Text, { style: styles.bullet }, '•'),
98
+ React.createElement(Text, { style: styles.bulletText }, parseInline(b))
99
+ )
100
+ )
101
+ )
102
+ );
103
+ bullets = [];
104
+ }
105
+ };
106
+
107
+ for (const line of lines) {
108
+ const t = line.trim();
109
+ if (t.startsWith('- ')) {
110
+ bullets.push(t.slice(2));
111
+ } else if (t) {
112
+ flushBullets();
113
+ elements.push(React.createElement(Text, { key: 'p' + key++, style: styles.elabText }, parseInline(t)));
114
+ }
115
+ }
116
+ flushBullets();
117
+
118
+ return elements;
119
+ }
120
+
121
+ export async function render(data, outFile) {
122
+ const { header, basics, body, salutation, meta } = data;
123
+ const shouldHyphenate = meta?.hyphenate !== false;
124
+ const shouldTypeset = meta?.fixTypesetting !== false;
125
+
126
+ const process = (text) => {
127
+ if (shouldTypeset) text = typeset(text);
128
+ if (shouldHyphenate) text = hyphenate(text);
129
+ return text;
130
+ };
131
+
132
+ const currentDate = meta?.date || new Date().toLocaleDateString('de-DE', {
133
+ year: 'numeric', month: 'long', day: 'numeric'
134
+ });
135
+
136
+ const content = [];
137
+
138
+ // Header
139
+ content.push(
140
+ React.createElement(View, { key: 'h', style: styles.headerBox },
141
+ React.createElement(Text, { style: styles.headerText }, header || 'CV')
142
+ )
143
+ );
144
+
145
+ // Basics
146
+ content.push(
147
+ React.createElement(View, { key: 'basics', style: styles.basics },
148
+ (basics || []).map((b, i) =>
149
+ React.createElement(Text, { key: i, style: styles.basicsItem }, parseInline(process(b)))
150
+ )
151
+ )
152
+ );
153
+
154
+ // Body
155
+ (body || []).forEach((section, si) => {
156
+ const h = process(section.header);
157
+ const sectionContent = [];
158
+ sectionContent.push(React.createElement(Text, { key: 'sh', style: styles.sectionHeader }, h));
159
+
160
+ (section.sections || []).forEach((item, ii) => {
161
+ sectionContent.push(
162
+ React.createElement(View, { key: 'it'+ii, style: styles.item, wrap: false },
163
+ React.createElement(Text, { style: styles.prefix }, item.prefix || ''),
164
+ React.createElement(View, { style: styles.elab },
165
+ parseElaboration(item.elaboration, shouldHyphenate, shouldTypeset)
166
+ )
167
+ )
168
+ );
169
+ });
170
+
171
+ content.push(
172
+ React.createElement(View, { key: 'sec'+si, wrap: false, minPresenceAhead: 50 },
173
+ sectionContent[0],
174
+ sectionContent[1]
175
+ )
176
+ );
177
+ for (let i = 2; i < sectionContent.length; i++) {
178
+ content.push(React.createElement(View, { key: 'sec'+si+'-'+i }, sectionContent[i]));
179
+ }
180
+ });
181
+
182
+ // Salutation
183
+ content.push(
184
+ React.createElement(Text, { key: 'sal', style: styles.salutation },
185
+ `${salutation}, ${currentDate}`)
186
+ );
187
+
188
+ const doc = React.createElement(Document, null,
189
+ React.createElement(Page, { size: 'A4', style: styles.page }, content)
190
+ );
191
+
192
+ await renderToFile(doc, outFile);
193
+ global.logNothing || console.log('✅ Written to ' + outFile);
194
+ }
package/lib/typeset.js ADDED
@@ -0,0 +1,50 @@
1
+ // Typography fixes for German text
2
+ // Based on https://www.npmjs.com/package/typeset
3
+
4
+ function fixQuotes(text) {
5
+ text = text
6
+ .replace(/(\W|^)"([^\s!?:;.,‽»])/g, '$1\u201e$2') // beginning "
7
+ .replace(/(\u201c[^"]*)"([^"]*$|[^\u201c"]*\u201c)/g, '$1\u201c$2') // ending "
8
+ .replace(/([^0-9])"/g, '$1\u201c') // remaining " at end of word
9
+ .replace(/(\W|^)'(\S)/g, '$1\u201a$2') // beginning '
10
+ .replace(/([a-z])'([a-z])/gi, '$1\u2019$2') // conjunction's possession
11
+ .replace(/((\u2018[^']*)|[a-z])'([^0-9]|$)/gi, '$1\u2018$3') // ending '
12
+ .replace(
13
+ /(\u2018)([0-9]{2}[^\u2019]*)(\u2018([^0-9]|$)|$|\u2019[a-z])/gi,
14
+ '\u2019$2$3'
15
+ ) // abbrev. years like '93
16
+ .replace(
17
+ /(\B|^)\u2018(?=([^\u2019]*\u2019\b)*([^\u2019\u2018]*\W[\u2019\u2018]\b|[^\u2019\u2018]*$))/gi,
18
+ '$1\u2019'
19
+ ) // backwards apostrophe
20
+ .replace(/'''/g, '\u2034') // triple prime
21
+ .replace(/("|'')/g, '\u2033') // double prime
22
+ .replace(/'/g, '\u2032');
23
+
24
+ // Allow escaped quotes
25
+ text = text.replace(/\\"/g, '"');
26
+ text = text.replace(/\\'/g, "'");
27
+
28
+ return text;
29
+ }
30
+
31
+ function fixPunctuation(text) {
32
+ // Dashes
33
+ text = text.replace(/--/g, '–');
34
+ text = text.replace(/ – /g, '\u2009—\u2009'); // thin space + em dash
35
+ text = text.replace(/ - /g, ' – ');
36
+
37
+ // Ellipses
38
+ text = text.replace(/\.\.\./g, '…');
39
+
40
+ // Nbsp for punctuation with spaces
41
+ const NBSP = '\u00A0';
42
+ text = text.replace(/([«¿¡]) /g, '$1' + NBSP);
43
+ text = text.replace(/ ([!?:;.,‽»])/g, NBSP + '$1');
44
+
45
+ return text;
46
+ }
47
+
48
+ export function typeset(text) {
49
+ return fixPunctuation(fixQuotes(text));
50
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@textbrocken/cv",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Generate PDF CVs and letters from Markdown or JSON5",
6
+ "keywords": [
7
+ "markdown",
8
+ "document",
9
+ "pdf",
10
+ "cv",
11
+ "resume",
12
+ "lebenslauf"
13
+ ],
14
+ "repository": {
15
+ "url": "https://github.com/textbrocken/cv.git",
16
+ "type": "git"
17
+ },
18
+ "homepage": "https://github.com/textbrocken/cv",
19
+ "bin": "cli.mjs",
20
+ "engines": {
21
+ "node": ">=22"
22
+ },
23
+ "files": [
24
+ "cli.mjs",
25
+ "lib",
26
+ "fonts",
27
+ "scripts"
28
+ ],
29
+ "dependencies": {
30
+ "@react-pdf/renderer": "^4.3.2",
31
+ "hyphen": "^1.14.1",
32
+ "js-yaml": "^4.1.1",
33
+ "json5": "^2.2.3",
34
+ "meow": "13.x",
35
+ "open": "10.x",
36
+ "react": "^19.2.4"
37
+ },
38
+ "scripts": {
39
+ "postinstall": "node scripts/patch-react-pdf.cjs"
40
+ },
41
+ "author": "mbaer3000",
42
+ "license": "MIT"
43
+ }
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Patches @react-pdf to support OpenType font features (e.g., 'onum' for oldstyle numerals).
5
+ *
6
+ * React-pdf's textkit supports features internally but doesn't expose them through styles.
7
+ * This script patches the layout and textkit modules to wire features through.
8
+ *
9
+ * Run automatically via npm postinstall, or manually: node scripts/patch-react-pdf.js
10
+ */
11
+
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+
15
+ const LAYOUT_PATH = path.join(__dirname, '../node_modules/@react-pdf/layout/lib/index.js');
16
+ const TEXTKIT_PATH = path.join(__dirname, '../node_modules/@react-pdf/textkit/lib/textkit.js');
17
+
18
+ function patchFile(filePath, patches) {
19
+ if (!fs.existsSync(filePath)) {
20
+ console.log(`⏭️ Skipping ${path.basename(filePath)} (not found)`);
21
+ return false;
22
+ }
23
+
24
+ let content = fs.readFileSync(filePath, 'utf8');
25
+ let patched = false;
26
+
27
+ for (const { find, replace, description } of patches) {
28
+ if (content.includes(replace)) {
29
+ console.log(`✓ ${description} (already applied)`);
30
+ continue;
31
+ }
32
+ if (!content.includes(find)) {
33
+ console.log(`⚠️ ${description} (pattern not found - react-pdf may have updated)`);
34
+ continue;
35
+ }
36
+ content = content.replace(find, replace);
37
+ patched = true;
38
+ console.log(`✓ ${description}`);
39
+ }
40
+
41
+ if (patched) {
42
+ fs.writeFileSync(filePath, content);
43
+ }
44
+ return patched;
45
+ }
46
+
47
+ console.log('Patching @react-pdf for OpenType features support...\n');
48
+
49
+ // Patch 1: @react-pdf/layout - add features to style destructuring and attributes (two locations)
50
+ patchFile(LAYOUT_PATH, [
51
+ {
52
+ find: "const { fill = 'black', fontFamily = 'Helvetica', fontWeight, fontStyle, fontSize = 18, textDecorationColor, textDecorationStyle, textTransform, opacity, } = instance.props;",
53
+ replace: "const { fill = 'black', fontFamily = 'Helvetica', fontWeight, fontStyle, fontSize = 18, textDecorationColor, textDecorationStyle, textTransform, opacity, features, } = instance.props;",
54
+ description: 'layout/index.js: Add features to props destructuring (SVG text)',
55
+ },
56
+ {
57
+ find: 'strikeColor: textDecorationColor || fill,\n };',
58
+ replace: 'strikeColor: textDecorationColor || fill,\n features: features || [],\n };',
59
+ description: 'layout/index.js: Add features to attributes object (SVG text)',
60
+ },
61
+ {
62
+ find: "const { color = 'black', direction = 'ltr', fontFamily = 'Helvetica', fontWeight, fontStyle, fontSize = 18, textAlign, lineHeight, textDecoration, textDecorationColor, textDecorationStyle, textTransform, letterSpacing, textIndent, opacity, verticalAlign, } = instance.style;",
63
+ replace: "const { color = 'black', direction = 'ltr', fontFamily = 'Helvetica', fontWeight, fontStyle, fontSize = 18, textAlign, lineHeight, textDecoration, textDecorationColor, textDecorationStyle, textTransform, letterSpacing, textIndent, opacity, verticalAlign, features, } = instance.style;",
64
+ description: 'layout/index.js: Add features to style destructuring (Text)',
65
+ },
66
+ {
67
+ find: "align: textAlign || (direction === 'rtl' ? 'right' : 'left'),\n };",
68
+ replace: "align: textAlign || (direction === 'rtl' ? 'right' : 'left'),\n features: features || [],\n };",
69
+ description: 'layout/index.js: Add features to attributes object (Text)',
70
+ },
71
+ ]);
72
+
73
+ // Patch 2: @react-pdf/textkit - pass features to fontkit layout
74
+ patchFile(TEXTKIT_PATH, [
75
+ {
76
+ find: "const glyphRun = font[0].layout(runString, undefined, undefined, undefined, 'ltr');",
77
+ replace: "const glyphRun = font[0].layout(runString, attributes.features, undefined, undefined, 'ltr');",
78
+ description: 'textkit/textkit.js: Pass features to fontkit layout',
79
+ },
80
+ ]);
81
+
82
+ console.log('\nDone!');