Skip to content

Commit e5dde85

Browse files
fix: update plain (#1098)
| [![PR App][icn]][demo] | Fix RM-12618 | | :--------------------: | :----------: | ## 🧰 Changes Migrates `plain` to better support MDX. Primarly, it looks like we never updated the variable handler portion. This should support our indexing job and generating metadata (ie. `description`). ## 🧬 QA & Testing - [Broken on production][prod]. - [Working in this PR app][demo]. [demo]: https://markdown-pr-PR_NUMBER.herokuapp.com [prod]: https://SUBDOMAIN.readme.io [icn]: https://user-images.githubusercontent.com/886627/160426047-1bee9488-305a-4145-bb2b-09d8b757d38a.svg
1 parent b53b6cc commit e5dde85

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

__tests__/lib/plain.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ Is it _me_ you're looking for?
3535
expect(plain(tree)).toBe('Title Some body');
3636
});
3737

38+
it('compiles JSX callouts', () => {
39+
const txt = `
40+
<Callout icon="📘">
41+
Title
42+
43+
Some body
44+
</Callout>
45+
`;
46+
const tree = hast(txt);
47+
48+
expect(plain(tree)).toBe('Title Some body');
49+
});
50+
3851
it('compiles markdown tables', () => {
3952
const txt = `
4053
| Header 1 | Header 2 |
@@ -53,4 +66,41 @@ Is it _me_ you're looking for?
5366

5467
expect(plain(tree)).toBe('entitled kittens');
5568
});
69+
70+
it('compiles JSX images to their title', () => {
71+
const txt = `
72+
<Image src="http://placekitten.com/600/600" alt="image **label**" title="entitled kittens" />
73+
`;
74+
const tree = hast(txt);
75+
76+
expect(plain(tree)).toBe('entitled kittens');
77+
});
78+
79+
it('compiles html blocks to their plain text', () => {
80+
const txt = `
81+
<HTMLBlock>{\`
82+
<p>Paragraph text</p>
83+
\`}</HTMLBlock>
84+
`;
85+
86+
expect(plain(hast(txt))).toBe('Paragraph text');
87+
});
88+
89+
it('compiles glossary items to their term', () => {
90+
const txt = '<Glossary>parliament</Glossary>';
91+
92+
expect(plain(hast(txt))).toBe('parliament');
93+
});
94+
95+
it('compiles variables to their name', () => {
96+
const txt = '{user.name}';
97+
98+
expect(plain(hast(txt))).toBe('name');
99+
});
100+
101+
it('compiles provided variables to their values', () => {
102+
const txt = '{user.name}';
103+
104+
expect(plain(hast(txt), { variables: { name: 'Owlbert' } })).toBe('Owlbert');
105+
});
56106
});

lib/plain.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,17 @@ function one(node: Nodes, opts: Options) {
3535

3636
return [icon, ' ', title, title && body && ': ', body].filter(Boolean).join('');
3737
}
38-
case 'readme-glossary-item': {
39-
return node.properties.term;
40-
}
41-
case 'readme-variable': {
42-
const key = node.properties.variable.toString();
43-
const val = opts.variables[key];
44-
return val || `<<${key}>>`;
38+
case 'Variable': {
39+
const key = node.properties.name.toString();
40+
const val = 'variables' in opts && opts.variables[key];
41+
return val || key;
4542
}
4643
case 'img': {
4744
return node.properties?.title || '';
4845
}
4946
case 'Accordion':
5047
case 'Card':
48+
case 'Callout':
5149
case 'Tab': {
5250
const title = node.properties?.title || '';
5351
const children = node?.children;

0 commit comments

Comments
 (0)