@jsonresume/core 0.3.8 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -14
- package/package.json +3 -3
- package/src/__tests__/components/inlineMarkdown.test.jsx +29 -0
- package/src/__tests__/components/primitives.test.jsx +20 -0
- package/src/index.js +7 -0
- package/src/primitives/InlineMarkdown.jsx +30 -0
- package/src/primitives/ListItem.jsx +9 -2
- package/src/primitives/index.jsx +1 -0
package/README.md
CHANGED
|
@@ -581,20 +581,10 @@ export function render(resume) {
|
|
|
581
581
|
|
|
582
582
|
### Step 5: Register Theme
|
|
583
583
|
|
|
584
|
-
Add
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
export const THEMES = {
|
|
590
|
-
// ...
|
|
591
|
-
myname: {
|
|
592
|
-
name: 'My Theme',
|
|
593
|
-
theme: myTheme,
|
|
594
|
-
description: 'A beautiful custom theme',
|
|
595
|
-
},
|
|
596
|
-
};
|
|
597
|
-
```
|
|
584
|
+
jsonresume.org renders themes through `@repo/resume-themes`. Add the package
|
|
585
|
+
as a dependency there, a loader in `packages/resume-themes/src/loaders.ts`,
|
|
586
|
+
and an entry in `packages/theme-config/src/metadata.js`: the full checklist
|
|
587
|
+
is in [`docs/CREATING_A_THEME.md`](../../docs/CREATING_A_THEME.md#3-registration-checklist).
|
|
598
588
|
|
|
599
589
|
## Examples
|
|
600
590
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsonresume/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Framework-agnostic resume component core - design tokens, primitives, and validators",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"styled-components": "^6.1.19",
|
|
39
|
-
"@jsonresume/types": "0.
|
|
40
|
-
"@jsonresume/utils": "0.
|
|
39
|
+
"@jsonresume/types": "0.8.0",
|
|
40
|
+
"@jsonresume/utils": "0.5.0"
|
|
41
41
|
},
|
|
42
42
|
"keywords": [
|
|
43
43
|
"resume",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { renderHtml } from './renderHtml.jsx';
|
|
4
|
+
import { InlineMarkdown, renderInlineMarkdown } from '../../index.js';
|
|
5
|
+
|
|
6
|
+
describe('InlineMarkdown (component)', () => {
|
|
7
|
+
it('renders the inline Markdown the schema allows', () => {
|
|
8
|
+
const { html } = renderHtml(
|
|
9
|
+
<InlineMarkdown text="Shipped **v2** with [Rust](https://rust-lang.org)" />
|
|
10
|
+
);
|
|
11
|
+
expect(html).toContain('<span>Shipped <strong>v2</strong> with ');
|
|
12
|
+
expect(html).toContain('<a href="https://rust-lang.org">Rust</a>');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders as another element, escaping what it is given', () => {
|
|
16
|
+
const { html } = renderHtml(
|
|
17
|
+
<ul>
|
|
18
|
+
<InlineMarkdown as="li" className="x" text="<b>raw</b> *ok*" />
|
|
19
|
+
</ul>
|
|
20
|
+
);
|
|
21
|
+
expect(html).toContain(
|
|
22
|
+
'<li class="x"><b>raw</b> <em>ok</em></li>'
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('is the same renderer @jsonresume/utils exports', () => {
|
|
27
|
+
expect(renderInlineMarkdown('`a`')).toBe('<code>a</code>');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -111,6 +111,26 @@ describe('ListItem', () => {
|
|
|
111
111
|
expect(html).not.toContain('resume-highlights');
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
+
it('renders inline Markdown in string descriptions and highlights (#600)', () => {
|
|
115
|
+
const { html } = renderHtml(
|
|
116
|
+
<ListItem
|
|
117
|
+
title="t"
|
|
118
|
+
description="Led **five** people"
|
|
119
|
+
highlights={['See [it](https://e.com)', '<script>x</script>']}
|
|
120
|
+
/>
|
|
121
|
+
);
|
|
122
|
+
expect(html).toContain('<strong>five</strong>');
|
|
123
|
+
expect(html).toContain('<a href="https://e.com"');
|
|
124
|
+
expect(html).not.toContain('<script>');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('passes React nodes through unchanged', () => {
|
|
128
|
+
const { html } = renderHtml(
|
|
129
|
+
<ListItem title="t" description={<em>node</em>} />
|
|
130
|
+
);
|
|
131
|
+
expect(html).toContain('<em>node</em>');
|
|
132
|
+
});
|
|
133
|
+
|
|
114
134
|
it('renders every highlight as a list item', () => {
|
|
115
135
|
const { html } = renderHtml(
|
|
116
136
|
<ListItem title="t" highlights={['a', 'b', 'c']} />
|
package/src/index.js
CHANGED
|
@@ -28,8 +28,15 @@ export {
|
|
|
28
28
|
AccentSidebarStripe,
|
|
29
29
|
AccentTopRule,
|
|
30
30
|
RulesetStack,
|
|
31
|
+
InlineMarkdown,
|
|
31
32
|
} from './primitives/index.jsx';
|
|
32
33
|
|
|
34
|
+
// Inline Markdown in resume text (#600): one renderer for every theme
|
|
35
|
+
export {
|
|
36
|
+
renderInlineMarkdown,
|
|
37
|
+
stripInlineMarkdown,
|
|
38
|
+
} from '@jsonresume/utils/markdown';
|
|
39
|
+
|
|
33
40
|
// Export design tokens
|
|
34
41
|
export {
|
|
35
42
|
default as tokens,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { renderInlineMarkdown } from '@jsonresume/utils/markdown';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* InlineMarkdown Component
|
|
6
|
+
* Resume text with its inline Markdown rendered (#600): **strong**,
|
|
7
|
+
* *emphasis*, `code` and [links](https://example.com), the subset the
|
|
8
|
+
* schema allows in summaries, work and project highlights and project
|
|
9
|
+
* descriptions. Every theme that uses it shows the same thing. The text is
|
|
10
|
+
* escaped first and links keep only http(s) and mailto addresses, so it is
|
|
11
|
+
* safe with resume text from anyone.
|
|
12
|
+
*
|
|
13
|
+
* @component
|
|
14
|
+
* @example
|
|
15
|
+
* <InlineMarkdown text={work.summary} />
|
|
16
|
+
* <InlineMarkdown as="li" text={highlight} />
|
|
17
|
+
*
|
|
18
|
+
* @param {string} text - The resume text
|
|
19
|
+
* @param {React.ElementType} [as='span'] - HTML element to render as
|
|
20
|
+
*/
|
|
21
|
+
export function InlineMarkdown({ text, as: Tag = 'span', ...rest }) {
|
|
22
|
+
return (
|
|
23
|
+
<Tag
|
|
24
|
+
{...rest}
|
|
25
|
+
dangerouslySetInnerHTML={{ __html: renderInlineMarkdown(text) }}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default InlineMarkdown;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import styled from 'styled-components';
|
|
3
|
+
import { renderInlineMarkdown } from '@jsonresume/utils/markdown';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* ListItem Component
|
|
@@ -74,6 +75,12 @@ const Highlights = styled.ul`
|
|
|
74
75
|
}
|
|
75
76
|
`;
|
|
76
77
|
|
|
78
|
+
// Strings get their inline Markdown rendered (#600); nodes pass through.
|
|
79
|
+
const prose = (value) =>
|
|
80
|
+
typeof value === 'string'
|
|
81
|
+
? { dangerouslySetInnerHTML: { __html: renderInlineMarkdown(value) } }
|
|
82
|
+
: { children: value };
|
|
83
|
+
|
|
77
84
|
export function ListItem({
|
|
78
85
|
title,
|
|
79
86
|
subtitle,
|
|
@@ -110,13 +117,13 @@ export function ListItem({
|
|
|
110
117
|
)}
|
|
111
118
|
|
|
112
119
|
{description && (
|
|
113
|
-
<Description className="resume-description"
|
|
120
|
+
<Description className="resume-description" {...prose(description)} />
|
|
114
121
|
)}
|
|
115
122
|
|
|
116
123
|
{highlights.length > 0 && (
|
|
117
124
|
<Highlights className="resume-highlights">
|
|
118
125
|
{highlights.map((highlight, index) => (
|
|
119
|
-
<li key={index}
|
|
126
|
+
<li key={index} {...prose(highlight)} />
|
|
120
127
|
))}
|
|
121
128
|
</Highlights>
|
|
122
129
|
)}
|
package/src/primitives/index.jsx
CHANGED
|
@@ -12,6 +12,7 @@ export { Badge, BadgeList } from './Badge.jsx';
|
|
|
12
12
|
export { ContactInfo } from './ContactInfo.jsx';
|
|
13
13
|
export { Link } from './Link.jsx';
|
|
14
14
|
export { InlineSeparatorPipe } from './InlineSeparatorPipe.jsx';
|
|
15
|
+
export { InlineMarkdown } from './InlineMarkdown.jsx';
|
|
15
16
|
|
|
16
17
|
// Divider and separator components
|
|
17
18
|
export { KeylineDivider } from './KeylineDivider';
|