diff --git a/man/lightdm-webkit2-greeter.1 b/man/lightdm-webkit2-greeter.1 index 73a3658..ca24f67 100644 --- a/man/lightdm-webkit2-greeter.1 +++ b/man/lightdm-webkit2-greeter.1 @@ -267,6 +267,13 @@ Returns an array of strings of filenames present at "path", or Null if the path does not exist\&. .RE .PP +greeterutil\&.txt2html(txt)\fR +.RS 4 +Returns a simple HTML conversion of the passed text\&. Newlines are replaced +with
, and the characters \&&, <, >, and " are replaced with their HTML +equivalents\&. +.RE +.PP Please see the LightDM API documentation for the complete list of calls available\&. The lightdm-webkit2-greeter implements all of the LightDM API\&. .PP diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 8afc2b6..3ad111c 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -1228,6 +1228,46 @@ get_dirlist_cb(JSContextRef context, } } +static JSValueRef +txt2html_cb(JSContextRef context, + JSObjectRef function, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef *exception) { + gchar *txt; + JSValueRef result; + + if (argumentCount != 1) { + return mkexception(context, exception, ARGNOTSUPPLIED); + } + + txt = arg_to_string(context, arguments[0], exception); + if (!txt) { + return JSValueMakeNull(context); + } + + /* Replace & with & */ + txt = g_strreplace (txt, "&", "&"); + + /* Replace " with " */ + txt = g_strreplace (txt, "\"", """); + + /* Replace < with < */ + txt = g_strreplace (txt, "<", "<"); + + /* Replace > with > */ + txt = g_strreplace (txt, ">", ">"); + + /* Replace newlines with
*/ + txt = g_strreplace (txt, "\n", "
"); + + result = string_or_null (context, txt); + g_free (txt); + + return result; +} + static const JSStaticValue lightdm_user_values[] = { {"name", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly}, @@ -1324,6 +1364,7 @@ static const JSStaticFunction config_file_functions[] = { static const JSStaticFunction greeter_util_functions[] = { {"dirlist", get_dirlist_cb, kJSPropertyAttributeReadOnly}, + {"txt2html", txt2html_cb, kJSPropertyAttributeReadOnly}, {NULL, NULL, 0}};