From 716333c6be60f99445eaa3e309908eded229afa3 Mon Sep 17 00:00:00 2001 From: Karl Stolley Date: Wed, 24 Sep 2025 12:23:34 -0400 Subject: [PATCH] postprocess: Move list-processing to the top. This is the most simple loop, so sticking it at the top keeps it from getting lost among the more complex processing that follows. --- web/src/postprocess_content.ts | 28 +++++++++++++------------- web/tests/postprocess_content.test.cjs | 14 ++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/web/src/postprocess_content.ts b/web/src/postprocess_content.ts index 4b8c752b6a..2fc52f9f1f 100644 --- a/web/src/postprocess_content.ts +++ b/web/src/postprocess_content.ts @@ -12,6 +12,20 @@ export function postprocess_content(html: string): string { const template = inertDocument.createElement("template"); template.innerHTML = html; + 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}`); + // We subtract 1 from list_start, as `count 0` displays 1. + ol.style.setProperty("counter-reset", `count ${list_start - 1}`); + } + for (const elt of template.content.querySelectorAll("a")) { // Ensure that all external links have target="_blank" // rel="opener noreferrer". This ensures that external links @@ -211,20 +225,6 @@ 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}`); - // We subtract 1 from list_start, as `count 0` displays 1. - ol.style.setProperty("counter-reset", `count ${list_start - 1}`); - } - for (const inline_img of template.content.querySelectorAll( ".message-media-preview-image img", )) { diff --git a/web/tests/postprocess_content.test.cjs b/web/tests/postprocess_content.test.cjs index 1f1bcadda6..8adab165d7 100644 --- a/web/tests/postprocess_content.test.cjs +++ b/web/tests/postprocess_content.test.cjs @@ -13,6 +13,13 @@ const {initialize_user_settings} = zrequire("user_settings"); const user_settings = {web_font_size_px: 16}; initialize_user_settings({user_settings}); +run_test("ordered_lists", () => { + assert.equal( + postprocess_content('
  1. Nine
  2. Ten
'), + '
  1. Nine
  2. Ten
', + ); +}); + // Care should be taken to present real-world cases here and // throughout, rather than contrived examples that serve // only to satisfy 100% test coverage. @@ -82,13 +89,6 @@ run_test("postprocess_media_and_embeds", () => { ); }); -run_test("ordered_lists", () => { - assert.equal( - postprocess_content('
  1. Nine
  2. Ten
'), - '
  1. Nine
  2. Ten
', - ); -}); - run_test("inline_image_galleries", ({override}) => { const thumbnail_formats = [ {