Skip to content

Commit

Permalink
feat: escapes (#903)
Browse files Browse the repository at this point in the history
| [![PR App][icn]][demo] | RM-9897 |
| :--------------------: | :-----: |

## 🧰 Changes

Compiles `escape` nodes from rdmd.

In `remark@9`, they no longer treat escapes as a separate node type.
This is mostly fine, except when we're migrating from rdmd to rmdx. The
[rules for escapes](https://github.github.com/gfm/#backslash-escapes)
seem pretty simple, so I'm not too worried about this change.

## 🧬 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
  • Loading branch information
kellyjosephprice authored Jun 13, 2024
1 parent dfc7c51 commit 94c37bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions __tests__/compilers/compatability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,20 @@ This is an image: <img src="http://example.com/#\\>" >

expect(mdx(rdmd.mdast(md)).trim()).toBe('This is an image: <img src="http://example.com/#\\>" />');
});

it('compiles escapes', () => {
const md = `
\\- not a list item
`;

expect(mdx(rdmd.mdast(md)).trim()).toBe('\\- not a list item');
});

it('compiles escapes of backslashes', () => {
const md = `
\\\\**still emphatic**
`;

expect(mdx(rdmd.mdast(md)).trim()).toBe('\\\\**still emphatic**');
});
});
3 changes: 3 additions & 0 deletions processor/compile/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type CompatNodes =
| { type: NodeTypes.glossary; data: { hProperties: { term: string } } }
| { type: NodeTypes.glossary; data: { hName: 'Glossary' }; children: [{ type: 'text'; value: string }] }
| { type: NodeTypes.reusableContent; tag: string }
| { type: 'escape'; value: string }
| Html;

/*
Expand Down Expand Up @@ -39,6 +40,8 @@ const compatibility = (node: CompatNodes) => {
return `<${node.tag} />`;
case 'html':
return html(node);
case 'escape':
return `\\${node.value}`;
default:
throw new Error('Unhandled node type!');
}
Expand Down
1 change: 1 addition & 0 deletions processor/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function compilers() {
[NodeTypes.variable]: compatibility,
[NodeTypes.glossary]: compatibility,
[NodeTypes.reusableContent]: compatibility,
escape: compatibility,
html: compatibility,
};

Expand Down

0 comments on commit 94c37bc

Please sign in to comment.