Skip to content

Commit

Permalink
fix(messageRenderer): differentiate heading size by its level [WPB-11…
Browse files Browse the repository at this point in the history
…802] (#18421)

* feat(messageRenderer): differentiate heading size by its level

* fix(messageRenderer): tests
  • Loading branch information
olafsulich authored Dec 5, 2024
1 parent 6794cdb commit d0ad643
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/script/util/messageRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,11 @@ describe('Markdown for code snippets', () => {
});

describe('Markdown for headings', () => {
it('renders all headings the same', () => {
expect(renderMessage('# heading')).toBe('<div class="md-heading">heading</div>');
expect(renderMessage('## heading')).toBe('<div class="md-heading">heading</div>');
expect(renderMessage('### heading')).toBe('<div class="md-heading">heading</div>');
expect(renderMessage('#### heading')).toBe('<div class="md-heading">heading</div>');
it('differentiate heading size by its level', () => {
expect(renderMessage('# heading')).toBe('<div class="md-heading md-heading--1">heading</div>');
expect(renderMessage('## heading')).toBe('<div class="md-heading md-heading--2">heading</div>');
expect(renderMessage('### heading')).toBe('<div class="md-heading md-heading--3">heading</div>');
expect(renderMessage('#### heading')).toBe('<div class="md-heading md-heading--4">heading</div>');
});
});

Expand Down
5 changes: 4 additions & 1 deletion src/script/util/messageRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ const markdownit = new MarkdownIt('zero', {

const originalFenceRule = markdownit.renderer.rules.fence!;

markdownit.renderer.rules.heading_open = () => '<div class="md-heading">';
markdownit.renderer.rules.heading_open = (tokens, idx) => {
const headingLevel = tokens[idx].tag.slice(1);
return `<div class="md-heading md-heading--${headingLevel}">`;
};
markdownit.renderer.rules.heading_close = () => '</div>';
const originalNormalizeLink = markdownit.normalizeLink!;

Expand Down
14 changes: 13 additions & 1 deletion src/style/content/conversation/message-list.less
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,22 @@

.md-heading {
margin: 4px 0 8px;
font-size: var(--font-size-large);
font-size: var(--font-size-base);
font-weight: var(--font-weight-bold);
line-height: var(--line-height-lg);

&--1 {
font-size: var(--font-size-xlarge);
}

&--2 {
font-size: var(--font-size-large);
}

&--3 {
font-size: var(--font-size-base);
}

& + br {
display: none;
}
Expand Down

0 comments on commit d0ad643

Please sign in to comment.