Module:Hotkey
From Liquipedia Commons Wiki
--- -- @Liquipedia -- wiki=commons -- page=Module:Hotkey -- -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- local Class = require('Module:Class') local Hotkeys = {} local SEPERATORS = { ['->'] = ' → ', ['then'] = ' → ', ['arrow'] = ' → ', ['+'] = ' + ', ['and'] = ' + ', ['&'] = ' + ', ['plus'] = ' + ', ['/'] = ' → ', ['or'] = ' → ', ['forwardslash'] = ' → ', ['slash'] = ' / ', ['space'] = ' ', ['nbsp'] = ' ', [' '] = ' ' } ---Creates a keyboard-button-like hotkey display ---@param args {hotkey: string|number|nil} ---@return string ---@overload fun(hotkey: table): string function Hotkeys.hotkey(args) local hotkey = args.hotkey return tostring(mw.html.create('span'):addClass('hotkey-key'):wikitext(hotkey or '')) end ---Creates a keyboard-button-like hotkey display of 2 hotkeys ---@param args {hotkey1: string|number|nil, hotkey2: string|number|nil, seperator: string?} ---@return string function Hotkeys.hotkey2(args) local seperator = args.seperator local hotkey1 = Hotkeys.hotkey{hotkey = args.hotkey1} local hotkey2 = Hotkeys.hotkey{hotkey = args.hotkey2} seperator = SEPERATORS[string.lower(seperator or '')] or seperator or '' return '<b>' .. hotkey1 .. seperator .. hotkey2 .. '</b>' end return Class.export(Hotkeys, {frameOnly = true, exports = {'hotkey', 'hotkey2'}})