From e0234b5e0b4e201b9ec064ee10489cd25d5bee1a Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 29 Sep 2025 15:40:42 +0200 Subject: [PATCH] FIX: ensures placeholders works in lists (#63) Prior to this fix the following cases wouldn't work: - nested lists - a link in a list --- javascripts/discourse/initializers/setup.js | 2 +- spec/system/placeholder_spec.rb | 22 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/javascripts/discourse/initializers/setup.js b/javascripts/discourse/initializers/setup.js index 01c5a81..8ed36eb 100644 --- a/javascripts/discourse/initializers/setup.js +++ b/javascripts/discourse/initializers/setup.js @@ -3,7 +3,7 @@ import { withPluginApi } from "discourse/lib/plugin-api"; import DiscoursePlaceholderBuilder from "../components/modal/discourse-placeholder-builder"; const VALID_TAGS = - "h1, h2, h3, h4, h5, h6, p, code, blockquote, .md-table, li p"; + "h1, h2, h3, h4, h5, h6, p, code, blockquote, .md-table, li, li > *"; const DELIMITER = "="; const EXPIRE_AFTER_DAYS = 7; const EXPIRE_AFTER_SECONDS = EXPIRE_AFTER_DAYS * 24 * 60 * 60; diff --git a/spec/system/placeholder_spec.rb b/spec/system/placeholder_spec.rb index c880597..b6711ff 100644 --- a/spec/system/placeholder_spec.rb +++ b/spec/system/placeholder_spec.rb @@ -68,5 +68,27 @@ RSpec.describe "Placeholder", system: true do expect(page).to have_link(href: "https://example.com/bar") end + + context "when placeholder is used in a[href] of list item" do + fab!(:post) { Fabricate(:post, raw: <<~MD) } + [wrap=placeholder key=\"TEST1\"][/wrap] + - test + - [Some link](https://example.com/=TEST1=) + MD + + it "replaces string in href" do + topic_page.visit_topic(post.topic) + + expect(page).to have_link(href: "https://example.com/=TEST1=") + + page.find('.discourse-placeholder-value[data-key="TEST1"]').fill_in(with: "foo") + + expect(page).to have_link(href: "https://example.com/foo") + + page.find('.discourse-placeholder-value[data-key="TEST1"]').fill_in(with: "bar") + + expect(page).to have_link(href: "https://example.com/bar") + end + end end end