-- abbreviations.lua -- SPDX-FileCopyrightText: 2025 toastal -- SPDX-License-Identifier: MPL-2.0 -- -- This plugin fills tags with a table that will fill in empty titles -- -- TODO: read a relative abbreviations.X for page-specific content & overrides Plugin.require_version("4.3.0") abbrs = config["table"] if not Value.is_table(abbrs) then Log.warning("`table` missing from `abbreviation` config") Plugin.exit() end function process(elem) HTML.set_tag_name(elem, "abbr") if not (HTML.has_class(elem, "untitled")) then local current_title = HTML.get_attribute(elem, "title") if Value.is_nil(current_title) or current_title == "" then local text_content = HTML.strip_tags(elem) if Value.is_nil(text_content) or text_content == "" then Plugin.fail("Empty ") end local new_title = abbrs[text_content] Log.debug(format("Substituting abbreviation: %s → %s", text_content, new_title)) if new_title then HTML.set_attribute(elem, "title", new_title) else Log.warning(format("ā€œ%sā€ not in the abbreviation table. Either provide an entry in the configuration file or make sure the element has a `title` attribute or the ``.untitled`` class as a utility hack. Sometimes this may be intentional.", text_content)) end end end HTML.remove_class(elem, "abbr") HTML.remove_class(elem, "untitled") end local selectors = Table.get_key_default(config, "selectors", {"abbr", ".abbr"}) Table.iter_values(process, HTML.select_all_of(page, selectors))