-
Notifications
You must be signed in to change notification settings - Fork 114
Add configurable code blocks and inline code #1193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anquinn
wants to merge
3
commits into
basecamp:main
Choose a base branch
from
anquinn:configurable-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width,initial-scale=1"> | ||
| <title>Lexxy Test — Code Fully Disabled</title> | ||
| <link rel="stylesheet" href="/styles.css"> | ||
| </head> | ||
| <body> | ||
| <form> | ||
| <div class="title"> | ||
| <input type="text" name="post[title]" placeholder="Post title" aria-label="Post title"> | ||
| </div> | ||
|
|
||
| <div class="body"> | ||
| <lexxy-editor class="lexxy-content" placeholder="Write something..." code-blocks="false" inline-code="false" required></lexxy-editor> | ||
| </div> | ||
|
|
||
| <div class="events"></div> | ||
| </form> | ||
|
|
||
| <script type="module" src="/editor.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width,initial-scale=1"> | ||
| <title>Lexxy Test — Code Blocks Disabled</title> | ||
| <link rel="stylesheet" href="/styles.css"> | ||
| </head> | ||
| <body> | ||
| <form> | ||
| <div class="title"> | ||
| <input type="text" name="post[title]" placeholder="Post title" aria-label="Post title"> | ||
| </div> | ||
|
|
||
| <div class="body"> | ||
| <lexxy-editor class="lexxy-content" placeholder="Write something..." code-blocks="false" required></lexxy-editor> | ||
| </div> | ||
|
|
||
| <div class="events"></div> | ||
| </form> | ||
|
|
||
| <script type="module" src="/editor.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width,initial-scale=1"> | ||
| <title>Lexxy Test — Inline Code Disabled</title> | ||
| <link rel="stylesheet" href="/styles.css"> | ||
| </head> | ||
| <body> | ||
| <form> | ||
| <div class="title"> | ||
| <input type="text" name="post[title]" placeholder="Post title" aria-label="Post title"> | ||
| </div> | ||
|
|
||
| <div class="body"> | ||
| <lexxy-editor class="lexxy-content" placeholder="Write something..." inline-code="false" required></lexxy-editor> | ||
| </div> | ||
|
|
||
| <div class="events"></div> | ||
| </form> | ||
|
|
||
| <script type="module" src="/editor.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { test } from "../../test_helper.js" | ||
| import { expect } from "@playwright/test" | ||
| import { assertEditorHtml, startMonitoringConsole } from "../../helpers/assertions.js" | ||
| import { clickToolbarButton } from "../../helpers/toolbar.js" | ||
|
|
||
| const CODE_BLOCK_HTML = '<pre data-language="plain"><code>alpha beta</code></pre><p>After</p>' | ||
| const INLINE_CODE_HTML = "<p>Hello <code>world</code> again</p>" | ||
|
|
||
| test.describe("Code blocks disabled, inline code enabled", () => { | ||
| test.beforeEach(async ({ page, editor }) => { | ||
| await page.goto("/code-blocks-false.html") | ||
| await editor.waitForConnected() | ||
| await page.waitForSelector("lexxy-toolbar[connected]") | ||
| }) | ||
|
|
||
| test("the shared code toolbar button is still visible", async ({ page }) => { | ||
| await expect(page.locator("lexxy-toolbar button[name='code']")).toBeVisible() | ||
| }) | ||
|
|
||
| test("the toolbar button applies inline code instead of a code block", async ({ page, editor }) => { | ||
| await editor.setValue("<p>hello</p>") | ||
| await editor.select("hello") | ||
|
|
||
| await clickToolbarButton(page, "insertCodeBlock") | ||
|
|
||
| await assertEditorHtml(editor, "<p><code>hello</code></p>") | ||
| await expect(editor.content.locator("pre")).toHaveCount(0) | ||
| }) | ||
|
|
||
| test("typing a Markdown fence does not create a code block", async ({ editor }) => { | ||
| await editor.click() | ||
| await editor.send("```") | ||
| await editor.send("Enter") | ||
| await editor.flush() | ||
|
|
||
| await expect(editor.content.locator("pre")).toHaveCount(0) | ||
| }) | ||
|
|
||
| test("a loaded code block is reduced to plain text", async ({ editor }) => { | ||
| await editor.setValue(CODE_BLOCK_HTML) | ||
|
|
||
| await expect(editor.content.locator("code")).toHaveCount(0) | ||
| const value = await editor.value() | ||
| expect(value).not.toContain("<pre") | ||
| expect(value).toContain("alpha beta") | ||
| expect(value).toContain("After") | ||
| }) | ||
| }) | ||
|
|
||
| test.describe("Inline code disabled, code blocks enabled", () => { | ||
| test.beforeEach(async ({ page, editor }) => { | ||
| await page.goto("/inline-code-false.html") | ||
| await editor.waitForConnected() | ||
| await page.waitForSelector("lexxy-toolbar[connected]") | ||
| }) | ||
|
|
||
| test("the shared code toolbar button is still visible", async ({ page }) => { | ||
| await expect(page.locator("lexxy-toolbar button[name='code']")).toBeVisible() | ||
| }) | ||
|
|
||
| test("the toolbar button inserts a code block instead of inline code", async ({ page, editor }) => { | ||
| await editor.setValue("<p>hello</p>") | ||
| await editor.select("hello") | ||
|
|
||
| await clickToolbarButton(page, "insertCodeBlock") | ||
|
|
||
| await expect.poll(() => editor.value()).toContain("<pre") | ||
| expect(await editor.value()).not.toContain("<code") | ||
| }) | ||
|
|
||
| test("typing a Markdown backtick does not apply inline code", async ({ editor }) => { | ||
| await editor.click() | ||
| await editor.send("`hello`") | ||
| await editor.flush() | ||
|
|
||
| await expect(editor.content.locator("code")).toHaveCount(0) | ||
| expect(await editor.plainTextValue()).toContain("hello") | ||
| }) | ||
|
|
||
| test("loaded inline code is reduced to plain text", async ({ editor }) => { | ||
| await editor.setValue(INLINE_CODE_HTML) | ||
|
|
||
| await expect(editor.content.locator("code")).toHaveCount(0) | ||
| const value = await editor.value() | ||
| expect(value).not.toContain("<code") | ||
| expect(value).toContain("Hello") | ||
| expect(value).toContain("world") | ||
| expect(value).toContain("again") | ||
| }) | ||
| }) | ||
|
|
||
| test.describe("Code blocks and inline code both disabled", () => { | ||
| test("the shared code toolbar button is hidden", async ({ page, editor }) => { | ||
| await page.goto("/code-all-false.html") | ||
| await editor.waitForConnected() | ||
| await page.waitForSelector("lexxy-toolbar[connected]") | ||
|
|
||
| await expect(page.locator("lexxy-toolbar button[name='code']")).toBeHidden() | ||
| }) | ||
|
|
||
| test("the editor connects without console errors", async ({ page, editor }) => { | ||
| startMonitoringConsole(page) | ||
|
|
||
| await page.goto("/code-all-false.html") | ||
| await editor.waitForConnected() | ||
|
|
||
| expect(page).toHaveNoErrors() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { expect, test } from "vitest" | ||
| import { createElement } from "../helpers/dom_helper" | ||
| import EditorConfiguration from "src/editor/configuration" | ||
| import { configure } from "src/index" | ||
|
|
||
| configure({ | ||
| default: { | ||
| codeBlocks: true, | ||
| inlineCode: true | ||
| }, | ||
| noCode: { | ||
| codeBlocks: false, | ||
| inlineCode: false | ||
| }, | ||
| fallbackToDefault: { | ||
| } | ||
| }) | ||
|
|
||
| test("uses default code options", () => { | ||
| const element = createElement("<lexxy-editor></lexxy-editor>") | ||
| const config = new EditorConfiguration(element) | ||
| expect(config.get("codeBlocks")).toBe(true) | ||
| expect(config.get("inlineCode")).toBe(true) | ||
| }) | ||
|
|
||
| test("uses preset code options", () => { | ||
| const element = createElement("<lexxy-editor preset='noCode'></lexxy-editor>") | ||
| const config = new EditorConfiguration(element) | ||
| expect(config.get("codeBlocks")).toBe(false) | ||
| expect(config.get("inlineCode")).toBe(false) | ||
| }) | ||
|
|
||
| test("overrides code blocks via element attribute", () => { | ||
| const element = createElement(`<lexxy-editor code-blocks="false"></lexxy-editor>`) | ||
| const config = new EditorConfiguration(element) | ||
| expect(config.get("codeBlocks")).toBe(false) | ||
| expect(config.get("inlineCode")).toBe(true) | ||
| }) | ||
|
|
||
| test("overrides inline code via element attribute", () => { | ||
| const element = createElement(`<lexxy-editor inline-code="false"></lexxy-editor>`) | ||
| const config = new EditorConfiguration(element) | ||
| expect(config.get("inlineCode")).toBe(false) | ||
| expect(config.get("codeBlocks")).toBe(true) | ||
| }) | ||
|
|
||
| test("preset falls back to default code options", () => { | ||
| const element = createElement("<lexxy-editor preset='fallbackToDefault'></lexxy-editor>") | ||
| const config = new EditorConfiguration(element) | ||
| expect(config.get("codeBlocks")).toBe(true) | ||
| expect(config.get("inlineCode")).toBe(true) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think editing another tool would be out of scope of this PR