web: Convert .data("code-language") to .attr.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-05-02 17:12:38 -07:00 committed by Tim Abbott
parent c2bae4c9d9
commit abee323c77
3 changed files with 7 additions and 5 deletions

View File

@ -98,9 +98,11 @@ function register_click_handlers(): void {
const $view_in_playground_button = $(this);
const $codehilite_div = $(this).closest(".codehilite");
e.stopPropagation();
const playground_info = realm_playground.get_playground_info_for_languages(
$codehilite_div.data("code-language"),
);
const language = $codehilite_div.attr("data-code-language");
if (language === undefined) {
return;
}
const playground_info = realm_playground.get_playground_info_for_languages(language);
if (playground_info === undefined) {
return;
}

View File

@ -278,7 +278,7 @@ export const update_elements = ($content: JQuery): void => {
$content.find("div.codehilite").each(function (): void {
const $codehilite = $(this);
const $pre = $codehilite.find("pre");
const fenced_code_lang = $codehilite.data("code-language");
const fenced_code_lang = $codehilite.attr("data-code-language");
let playground_info;
if (fenced_code_lang !== undefined) {
playground_info = realm_playground.get_playground_info_for_languages(fenced_code_lang);

View File

@ -547,7 +547,7 @@ function test_code_playground(mock_template, viewing_code) {
$content.set_find_results("div.codehilite", $array([$hilite]));
$hilite.set_find_results("pre", $pre);
$hilite.data("code-language", "javascript");
$hilite.attr("data-code-language", "javascript");
const $code_buttons_container = $.create("code_buttons_container", {
children: ["copy-code-stub", "view-code-stub"],