Browse Source

Added greeterutil.txt2html()

(cherry picked from commit fb3f7d5)
sisyphus
Scott Balneaves 9 years ago committed by Dustin Falgout
parent
commit
ab93cdd9ca
  1. 7
      man/lightdm-webkit2-greeter.1
  2. 41
      src/lightdm-webkit2-greeter-ext.c

7
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 <br>, 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

41
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 &amp; */
txt = g_strreplace (txt, "&", "&amp;");
/* Replace " with &quot; */
txt = g_strreplace (txt, "\"", "&quot;");
/* Replace < with &lt; */
txt = g_strreplace (txt, "<", "&lt;");
/* Replace > with &gt; */
txt = g_strreplace (txt, ">", "&gt;");
/* Replace newlines with <br> */
txt = g_strreplace (txt, "\n", "<br>");
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}};

Loading…
Cancel
Save