add gui.clear_markup(...)

This commit is contained in:
MihailRis 2024-12-06 20:13:45 +03:00
parent 98de0d45ef
commit 16698cc68b
3 changed files with 35 additions and 0 deletions

View File

@ -39,3 +39,14 @@ gui.get_locales_info() -> table of tables {
```
Returns information about all loaded locales (res/texts/\*).
```lua
gui.clear_markup(
-- markup language ("md" - Markdown)
language: str,
-- text with markup
text: str
) -> str
```
Removes markup from text.

View File

@ -36,3 +36,14 @@ gui.get_locales_info() -> таблица таблиц где
```
Возвращает информацию о всех загруженных локалях (res/texts/\*).
```lua
gui.clear_markup(
-- язык разметки ("md" - Markdown)
language: str,
-- текст с разметкой
text: str
) -> str
```
Удаляет разметку из текста.

View File

@ -12,6 +12,8 @@
#include "graphics/ui/elements/TrackBar.hpp"
#include "graphics/ui/elements/UINode.hpp"
#include "graphics/ui/gui_util.hpp"
#include "graphics/ui/markdown.hpp"
#include "graphics/core/Font.hpp"
#include "items/Inventories.hpp"
#include "util/stringutil.hpp"
#include "world/Level.hpp"
@ -726,6 +728,16 @@ static int l_gui_getviewport(lua::State* L) {
return lua::pushvec2(L, engine->getGUI()->getContainer()->getSize());
}
static int l_gui_clear_markup(lua::State* L) {
auto lang = lua::require_string(L, 1);
std::string text = lua::require_string(L, 2);
if (std::strcmp(lang, "md") == 0) {
auto [processed, _] = markdown::process(text, true);
text = std::move(processed);
}
return lua::pushstring(L, text);
}
const luaL_Reg guilib[] = {
{"get_viewport", lua::wrap<l_gui_getviewport>},
{"getattr", lua::wrap<l_gui_getattr>},
@ -733,5 +745,6 @@ const luaL_Reg guilib[] = {
{"get_env", lua::wrap<l_gui_get_env>},
{"str", lua::wrap<l_gui_str>},
{"get_locales_info", lua::wrap<l_gui_get_locales_info>},
{"clear_markup", lua::wrap<l_gui_clear_markup>},
{"__reindex", lua::wrap<l_gui_reindex>},
{NULL, NULL}};