Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
rendered_markdown: Offset ordered lists by start and count.
Karl Stolleybe5c81286cc4
diff --git a/web/src/postprocess_content.ts b/web/src/postprocess_content.tsindex af2fc0315fc..c2cafcdebfb 100644--- a/web/src/postprocess_content.ts+++ b/web/src/postprocess_content.ts@@ -92,6 +92,18 @@ export function postprocess_content(html: string): string {}}+ for (const ol of template.content.querySelectorAll("ol")) {+ const list_start = Number(ol.getAttribute("start") ?? 1);+ // We don't count the first item in the list, as it+ // will be identical to the start value+ const list_length = ol.children.length - 1;+ const max_list_counter = list_start + list_length;+ // We count the characters in the longest list counter,+ // and use that to offset the list accordingly in CSS+ const max_list_counter_string_length = max_list_counter.toString().length;+ ol.classList.add(`counter-length-${max_list_counter_string_length}`);+ }+for (const inline_img of template.content.querySelectorAll<HTMLImageElement>("div.message_inline_image > a > img",)) {diff --git a/web/styles/rendered_markdown.css b/web/styles/rendered_markdown.cssindex 33ae5e5418e..f2a499c901f 100644--- a/web/styles/rendered_markdown.css+++ b/web/styles/rendered_markdown.css@@ -20,6 +20,31 @@margin-inline-start: 3ch;}+ /* We set margin according to the length of the longest list counter. */+ .counter-length-1 {+ margin-inline-start: 2ch;+ }++ .counter-length-2 {+ margin-inline-start: 3ch;+ }++ .counter-length-3 {+ margin-inline-start: 4ch;+ }++ .counter-length-4 {+ margin-inline-start: 5ch;+ }++ .counter-length-5 {+ margin-inline-start: 6ch;+ }++ .counter-length-6 {+ margin-inline-start: 7ch;+ }+& hr {border-bottom: 1px solid hsl(0deg 0% 87%);border-top: 1px solid hsl(0deg 0% 87%);diff --git a/web/tests/postprocess_content.test.cjs b/web/tests/postprocess_content.test.cjsindex 2b43c4226c3..9f4dd1a6be1 100644--- a/web/tests/postprocess_content.test.cjs+++ b/web/tests/postprocess_content.test.cjs@@ -38,6 +38,13 @@ run_test("postprocess_content", () => {);});+run_test("ordered_lists", () => {+ assert.equal(+ postprocess_content('<ol start="9"><li>Nine</li><li>Ten</li></ol>'),+ '<ol start="9" class="counter-length-2"><li>Nine</li><li>Ten</li></ol>',+ );+});+run_test("message_inline_animated_image_still", ({override}) => {const thumbnail_formats = [{