-- Copyright (c) Sallai AndrĂ¡s, 2020 -- Licenc: GNU GPL v3 -- emma -- Versio: 1.0 -- The split() function from: -- https://gist.github.com/jaredallard/ddb152179831dd23b230 -- 2020-12-22 -- This is HTML code generator for Geany editor -------------------------------------------------------- -- Settings -- Tabulator: spaces " " or \t tabChars=" " -------------------------------------------------------- function split(str, sep) local wordTable = {} local from = 1 local sepFrom, sepTo = string.find(str, sep, from) while sepFrom do table.insert(wordTable, string.sub(str, from, sepFrom-1)) from = sepTo + 1 sepFrom, sepTo = string.find(str, sep, from) end table.insert(wordTable, string.sub(str, from)) return wordTable end function getElementName(elementStr) local poz = string.find(elementStr, "*") if poz == nil then element = elementStr else element = string.sub(elementStr, 1, poz-1) end return element end function getTagAttribute(element) if element == "a" then return " href=\"\"" else return "" end end function getActualElement(elementStr) local poz = string.find(elementStr, "*") if poz == nil then count = 1 else count = string.sub(elementStr, poz+1) end return tonumber(count) end function addStartingTags(code, actualElement, elementName, tableSize) if actualElement > 1 then for i = 1, actualElement-1 do code = code .. tabChars end end code = code .. "<" code = code .. elementName code = code .. getTagAttribute(elementName) code = code .. ">" if actualElement < tableSize then code = code .. "\n" end return code end function addClosingTags(code, actualElement, elementName, tableSize) if actualElement < tableSize then for i = 1, actualElement-1 do code = code .. tabChars end end code = code .. "" code = code .. "\n" return code end function genCode(wordTable, actualElement) local code = "" local tableSize = table.getn(wordTable) if actualElement<=tableSize then internalCode = genCode(wordTable, actualElement+1) elementName = getElementName(wordTable[actualElement]) numberOfElements = getActualElement(wordTable[actualElement]) for i = 1, numberOfElements do code = addStartingTags(code, actualElement, elementName, tableSize) code = code .. internalCode code = addClosingTags(code, actualElement, elementName, tableSize) end end return code end function insertCode() local endpoint = geany.caret() geany.wordchars="abcdefghijklmnopqrstuvwz0123456789>*" local content = geany.word() local wordLength = string.len(content) if wordLength > 0 then local startpoint = endpoint - wordLength local contentTable = split(content, ">") local generatedTags = genCode(contentTable, 1) geany.select(startpoint, endpoint) geany.selection(generatedTags) end end insertCode()