Skip to content

Commit 8de12d2

Browse files
fix(escape-char): resolve an issue where escape chars were not being preserved when switching between modes (#366)
Co-authored-by: Dan Cormier <[email protected]>
1 parent dab5eae commit 8de12d2

File tree

3 files changed

+70
-11
lines changed

3 files changed

+70
-11
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
lint:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
- name: Setup Node.js environment
15-
uses: actions/setup-node@v3
15+
uses: actions/setup-node@v4
1616
with:
1717
node-version: lts/*
1818
cache: "npm"
@@ -25,10 +25,10 @@ jobs:
2525
unit-test:
2626
runs-on: ubuntu-latest
2727
steps:
28-
- uses: actions/checkout@v3
28+
- uses: actions/checkout@v4
2929

3030
- name: Setup Node.js environment
31-
uses: actions/setup-node@v3
31+
uses: actions/setup-node@v4
3232
with:
3333
node-version: lts/*
3434
cache: "npm"
@@ -41,10 +41,10 @@ jobs:
4141
e2e-test:
4242
runs-on: ubuntu-latest
4343
steps:
44-
- uses: actions/checkout@v3
44+
- uses: actions/checkout@v4
4545

4646
- name: Setup Node.js environment
47-
uses: actions/setup-node@v3
47+
uses: actions/setup-node@v4
4848
with:
4949
node-version: lts/*
5050
cache: "npm"
@@ -58,7 +58,7 @@ jobs:
5858
- name: Run E2E tests
5959
run: npm run test:e2e
6060

61-
- uses: actions/upload-artifact@v3
61+
- uses: actions/upload-artifact@v4
6262
if: failure()
6363
with:
6464
name: playwright-test-results

src/shared/markdown-serializer.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,13 @@ const defaultMarkdownSerializerNodes: MarkdownSerializerNodes = {
330330
) {
331331
text = linkMark.attrs.href as string;
332332
} else {
333-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
334-
// @ts-expect-error
335-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
336-
const startOfLine: boolean = state.atBlank() || state.closed;
333+
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unsafe-assignment */
334+
const startOfLine: boolean =
335+
// @ts-expect-error
336+
// eslint-disable-next-line
337+
state.atBlank() || state.atBlockStart || state.closed;
338+
/* eslint-enable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unsafe-assignment */
339+
337340
// escape the text using the built in escape code
338341
let escapedText = state.esc(node.text, startOfLine);
339342

test/shared/roundtrip.e2e.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { test, expect, Page } from "@playwright/test";
2+
import {
3+
switchMode,
4+
clearEditor,
5+
editorSelector,
6+
enterTextAsMarkdown,
7+
} from "../e2e-helpers";
8+
9+
test.describe.serial("roundtrip tests", () => {
10+
let page: Page;
11+
test.beforeAll(async ({ browser }) => {
12+
page = await browser.newPage();
13+
await page.goto("/empty.html");
14+
await switchMode(page, "markdown");
15+
});
16+
17+
test.afterAll(async () => {
18+
await page.close();
19+
});
20+
21+
for (const [markdown] of [
22+
//Basic commonmark
23+
["plain"],
24+
["*italic*"],
25+
["_italic_"],
26+
["**bold**"],
27+
["__bold__"],
28+
["# H1"],
29+
["## H2"],
30+
["[link](http://www.example.com)"],
31+
["![Image](http://www.example.com/pretty.png)"],
32+
["> blockquote"],
33+
["* List Item"],
34+
["- List Item"],
35+
["1. List Item"],
36+
["2) List Item"],
37+
["lol\n\n---\n\nlmao"],
38+
["lol\n\n***\n\nlmao"],
39+
["`code`"],
40+
//TODO: Codeblock does weird things roundtripping: Adds an extra space
41+
//['```javascript\ncodeblock\n```' ],
42+
43+
//Escape character
44+
[String.raw`\# not a header`],
45+
[String.raw`- \# list item (not header)`],
46+
] as const) {
47+
test(`should make markdown -> richtext -> markdown round trip '${JSON.stringify(markdown)}'`, async () => {
48+
await clearEditor(page);
49+
await enterTextAsMarkdown(page, markdown);
50+
await switchMode(page, "markdown");
51+
52+
const text = await page.innerText(editorSelector);
53+
expect(text).toBe(markdown);
54+
});
55+
}
56+
});

0 commit comments

Comments
 (0)