fix(muya): restore inline HTML tag marker style and hide bare <br/> markers by Jocs · Pull Request #5636 · marktext/marktext · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/muya/e2e/tests/blocks/html-inline.spec.ts
1 change: 1 addition & 0 deletions packages/muya/e2e/tests/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const editor = {
// Inline html tags wrap their children with `.mu-raw-html`. The tag itself
// is the actual `<u>`, `<mark>`, `<sup>`, `<sub>` or `<ruby>` element.
rawHtml: '.mu-raw-html',
htmlTagMarker: 'span.mu-html-tag',
} as const;

// Float root class names confirmed against the `const name = 'mu-...'` lines
Expand Down
6 changes: 6 additions & 0 deletions packages/muya/src/assets/styles/inlineSyntax.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
white-space: nowrap;
}

span.mu-html-tag {
color: var(--editor-color-50);
font-weight: 200;
font-family: monospace;
}

/* link and auto-link and reference link */
a.mu-inline-rule,
span.mu-inline-rule.mu-link {
Expand Down
59 changes: 59 additions & 0 deletions packages/muya/src/inlineRenderer/__tests__/htmlTagMarker.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// @vitest-environment jsdom

import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { CLASS_NAMES } from '../../config';
import { Muya } from '../../muya';

const bootedMuyas: Muya[] = [];

beforeEach(() => {
(window as unknown as { MUYA_VERSION?: string }).MUYA_VERSION = 'test';
});

afterEach(() => {
while (bootedMuyas.length)
bootedMuyas.pop()!.destroy();
document.body.innerHTML = '';
delete (window as unknown as { MUYA_VERSION?: string }).MUYA_VERSION;
});

function boot(markdown: string): Muya {
const host = document.createElement('div');
document.body.appendChild(host);
const muya = new Muya(host, { markdown } as ConstructorParameters<typeof Muya>[1]);
muya.init();
bootedMuyas.push(muya);
return muya;
}

describe('inline <br> marker', () => {
it('collapses the literal marker while keeping a real <br> line break', () => {
const muya = boot('Line 1<br/>Line 2');
const wrapper = muya.domNode.querySelector<HTMLElement>(
`span.${CLASS_NAMES.MU_HTML_TAG}`,
)!;
const marker = wrapper.querySelector<HTMLElement>(
`span.${CLASS_NAMES.MU_HIDE}`,
)!;

expect(marker.textContent).toBe('<br/>');
expect(marker.classList.contains(CLASS_NAMES.MU_OUTPUT_REMOVE)).toBe(true);
expect(marker.querySelector('br')).toBeNull();
expect(wrapper.querySelector('br')).not.toBeNull();
});

it('reveals the marker once the caret sits inside the <br> token', () => {
const muya = boot('Line 1<br/>Line 2');
muya.editor.scrollPage!.firstContentInDescendant()!.setCursor(7, 7, true);

const wrapper = muya.domNode.querySelector<HTMLElement>(
`span.${CLASS_NAMES.MU_HTML_TAG}`,
)!;
const marker = wrapper.querySelector<HTMLElement>(
`span.${CLASS_NAMES.MU_HTML_TAG}.${CLASS_NAMES.MU_OUTPUT_REMOVE}`,
)!;

expect(marker.textContent).toBe('<br/>');
expect(marker.classList.contains(CLASS_NAMES.MU_HIDE)).toBe(false);
});
});
27 changes: 17 additions & 10 deletions packages/muya/src/inlineRenderer/renderer/htmlTag.ts
Loading