mirror of
https://github.com/discourse/discourse.git
synced 2026-08-14 13:58:53 +08:00
Event descriptions are stored as plain text (extracted via `doc.text.strip` from cooked HTML), so any URLs typed by the user were rendered as non-clickable text in the event popup. This adds a `description_html` attribute to the event serializer that linkifies URLs at serialization time via `EventParser.linkify_description`. The method wraps URL matches in `<a>` tags and delegates `rel` attribute handling to `PrettyText.add_rel_attributes_to_user_content`, which respects trust levels, staff status, domain allowlists, and the `add_rel_nofollow_to_user_content` site setting. The raw `description` attribute remains unchanged (plain text) so the edit form continues to show editable text without HTML markup. On the client side, the Description component now receives `@descriptionHtml` and renders it via `trustHTML`. The JS model maps the new `description_html` field from the API response. Also removes `text-align: justify` from the description text style. Ref - t/180829
37 lines
1.3 KiB
JavaScript
Vendored
37 lines
1.3 KiB
JavaScript
Vendored
import { module, test } from "qunit";
|
|
import DiscoursePostEventEvent from "../../discourse/models/discourse-post-event-event";
|
|
|
|
module("Unit | Model | DiscoursePostEventEvent", function () {
|
|
test("maps description fields from API response", function (assert) {
|
|
const event = DiscoursePostEventEvent.create({
|
|
id: 1,
|
|
description: "Visit https://example.com",
|
|
description_html:
|
|
'Visit <a href="https://example.com">https://example.com</a>',
|
|
});
|
|
|
|
assert.strictEqual(event.description, "Visit https://example.com");
|
|
assert.strictEqual(
|
|
event.descriptionHtml,
|
|
'Visit <a href="https://example.com">https://example.com</a>'
|
|
);
|
|
});
|
|
|
|
test("updateFromEvent copies description fields", function (assert) {
|
|
const event = DiscoursePostEventEvent.create({ id: 1 });
|
|
const updated = DiscoursePostEventEvent.create({
|
|
id: 1,
|
|
description: "Visit https://example.com",
|
|
description_html:
|
|
'Visit <a href="https://example.com">https://example.com</a>',
|
|
});
|
|
|
|
event.updateFromEvent(updated);
|
|
|
|
assert.strictEqual(event.description, "Visit https://example.com");
|
|
assert.strictEqual(
|
|
event.descriptionHtml,
|
|
'Visit <a href="https://example.com">https://example.com</a>'
|
|
);
|
|
});
|
|
});
|