diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5fc2c513..a3f206ee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,9 +10,9 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Node.js environment - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: lts/* cache: "npm" @@ -25,10 +25,10 @@ jobs: unit-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Node.js environment - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: lts/* cache: "npm" @@ -41,10 +41,10 @@ jobs: e2e-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Node.js environment - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: lts/* cache: "npm" @@ -58,7 +58,7 @@ jobs: - name: Run E2E tests run: npm run test:e2e - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: failure() with: name: playwright-test-results diff --git a/src/shared/markdown-serializer.ts b/src/shared/markdown-serializer.ts index 1c42cff3..ccf2cab6 100644 --- a/src/shared/markdown-serializer.ts +++ b/src/shared/markdown-serializer.ts @@ -330,10 +330,13 @@ const defaultMarkdownSerializerNodes: MarkdownSerializerNodes = { ) { text = linkMark.attrs.href as string; } else { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call - const startOfLine: boolean = state.atBlank() || state.closed; + /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unsafe-assignment */ + const startOfLine: boolean = + // @ts-expect-error + // eslint-disable-next-line + state.atBlank() || state.atBlockStart || state.closed; + /* eslint-enable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unsafe-assignment */ + // escape the text using the built in escape code let escapedText = state.esc(node.text, startOfLine); diff --git a/test/shared/roundtrip.e2e.test.ts b/test/shared/roundtrip.e2e.test.ts new file mode 100644 index 00000000..398f9d44 --- /dev/null +++ b/test/shared/roundtrip.e2e.test.ts @@ -0,0 +1,56 @@ +import { test, expect, Page } from "@playwright/test"; +import { + switchMode, + clearEditor, + editorSelector, + enterTextAsMarkdown, +} from "../e2e-helpers"; + +test.describe.serial("roundtrip tests", () => { + let page: Page; + test.beforeAll(async ({ browser }) => { + page = await browser.newPage(); + await page.goto("/empty.html"); + await switchMode(page, "markdown"); + }); + + test.afterAll(async () => { + await page.close(); + }); + + for (const [markdown] of [ + //Basic commonmark + ["plain"], + ["*italic*"], + ["_italic_"], + ["**bold**"], + ["__bold__"], + ["# H1"], + ["## H2"], + ["[link](http://www.example.com)"], + ["![Image](http://www.example.com/pretty.png)"], + ["> blockquote"], + ["* List Item"], + ["- List Item"], + ["1. List Item"], + ["2) List Item"], + ["lol\n\n---\n\nlmao"], + ["lol\n\n***\n\nlmao"], + ["`code`"], + //TODO: Codeblock does weird things roundtripping: Adds an extra space + //['```javascript\ncodeblock\n```' ], + + //Escape character + [String.raw`\# not a header`], + [String.raw`- \# list item (not header)`], + ] as const) { + test(`should make markdown -> richtext -> markdown round trip '${JSON.stringify(markdown)}'`, async () => { + await clearEditor(page); + await enterTextAsMarkdown(page, markdown); + await switchMode(page, "markdown"); + + const text = await page.innerText(editorSelector); + expect(text).toBe(markdown); + }); + } +});