* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' [not found] <878rxx8w1i.fsf.ref@yahoo.com> @ 2021-11-09 10:26 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-09 13:21 ` Eli Zaretskii ` (2 more replies) 0 siblings, 3 replies; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-09 10:26 UTC (permalink / raw) To: 51712 [-- Attachment #1: Type: text/plain, Size: 220 bytes --] Hopefully this allows to reduce the amount of JavaScript hacks needed to load HTML into a widget. It also lets you customize the base URI WebKit uses to find web resources, which you can't do from JavaScript. Thanks. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-xwidget-webkit-load-html.patch --] [-- Type: text/x-patch, Size: 3436 bytes --] From f368cd47dd5a2d232024ef1fb0f95f4b0c15e566 Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Tue, 9 Nov 2021 18:24:03 +0800 Subject: [PATCH] Add `xwidget-webkit-load-html' * doc/lispref/display.texi (Xwidgets): Document new function. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_load_html): New function. (syms_of_xwidget): Define new subr. --- doc/lispref/display.texi | 10 ++++++++++ etc/NEWS | 5 +++++ src/xwidget.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index b6bd14f887..3ccc755391 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6943,6 +6943,16 @@ Xwidgets signals an error. @end defun +@defun xwidget-webkit-load-html xwidget text base-uri +Load @var{text} into @var{xwidget}, which should be a WebKit xwidget. +@var{text} will be treated as HTML markup, and rendered by +@var{xwidget}. + +For the purpose of controlling the location where web resources will +be found, you can optionally specify a base URI as a string in +@var{base-uri}, which defaults to @samp{about:blank}. +@end defun + @node Buttons @section Buttons @cindex buttons in buffers diff --git a/etc/NEWS b/etc/NEWS index 807f31fa33..93c161025b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -792,6 +792,11 @@ what the widget will actually receive. On GTK+, only key and function key events are implemented. ++++ +*** New function 'xwidget-webkit-load-html'. +This function is used to load HTML text into WebKit xwidgets, without +having to create a temporary file or URL. + +++ *** New functions for performing searches on WebKit xwidgets. Some new functions, such as 'xwidget-webkit-search', have been added diff --git a/src/xwidget.c b/src/xwidget.c index fc76ce307e..22893bfe2e 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2139,6 +2139,43 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, + Sxwidget_webkit_load_html, 2, 3, 0, + doc: /* Make XWIDGET's WebKit widget render text. +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT +should be a string that will be displayed by XWIDGET as plain text. +BASE_URI will be a URI that is used to fetch resources, and if not +specified, is treated as equivalent to `about:blank'. */) + (Lisp_Object xwidget, Lisp_Object text, Lisp_Object base_uri) +{ + struct xwidget *xw; +#ifdef USE_GTK + WebKitWebView *webview; + char *data, *uri; +#endif + + CHECK_XWIDGET (xwidget); + CHECK_STRING (text); + if (NILP (base_uri)) + base_uri = build_string ("about:blank"); + CHECK_STRING (base_uri); + base_uri = ENCODE_UTF_8 (base_uri); + text = ENCODE_UTF_8 (text); + xw = XXWIDGET (xwidget); + +#ifdef USE_GTK + data = SSDATA (text); + uri = SSDATA (base_uri); + webview = WEBKIT_WEB_VIEW (xw->widget_osr); + + block_input (); + webkit_web_view_load_html (webview, data, uri); + unblock_input (); +#endif + + return Qnil; +} + void syms_of_xwidget (void) { @@ -2177,6 +2214,7 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_next_result); defsubr (&Sxwidget_webkit_previous_result); defsubr (&Sset_xwidget_buffer); + defsubr (&Sxwidget_webkit_load_html); DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); -- 2.31.1 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-09 10:26 ` bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-09 13:21 ` Eli Zaretskii 2021-11-09 13:42 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 4:34 ` Richard Stallman 2022-09-09 18:26 ` Lars Ingebrigtsen 2 siblings, 1 reply; 20+ messages in thread From: Eli Zaretskii @ 2021-11-09 13:21 UTC (permalink / raw) To: Po Lu; +Cc: 51712 > Date: Tue, 09 Nov 2021 18:26:17 +0800 > From: Po Lu via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> > > +@defun xwidget-webkit-load-html xwidget text base-uri > +Load @var{text} into @var{xwidget}, which should be a WebKit xwidget. > +@var{text} will be treated as HTML markup, and rendered by > +@var{xwidget}. can you rephrase the last sentence not to use passive tense, please? > +For the purpose of controlling the location where web resources will > +be found, you can optionally specify a base URI as a string in > +@var{base-uri}, which defaults to @samp{about:blank}. But BASE-URI is not an &optional argument above. And also, this sentence is unnecessarily complex because you state the reason before the goal. It is much better to do it the other way around, and while at that, make 2 simple sentences out of one complex one: Optional argument @var{base-uri}, which should be a string, specifies the location of the web resource. It defaults to @samp{about:blank}. (Of course, now this begs the question: what does it mean "web resource" for HTML text? How about answering that in the text?) > ++++ > +*** New function 'xwidget-webkit-load-html'. > +This function is used to load HTML text into WebKit xwidgets, without > +having to create a temporary file or URL. The second part is either unnecessary or too terse. if it is important to explain that, please elaborate how temporary files are relevant here. > +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, > + Sxwidget_webkit_load_html, 2, 3, 0, > + doc: /* Make XWIDGET's WebKit widget render text. > +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT > +should be a string that will be displayed by XWIDGET as plain text. The "plain text" part seems to contradict the text in the manual, which says it will be rendered as HTML markup? > +BASE_URI will be a URI that is used to fetch resources, and if not > +specified, is treated as equivalent to `about:blank'. */) "will be" is confusing: why the future tense? Also, what kind of Lisp type is that? And I think explaining the importance of "fetching resources" would be beneficiary here. And finally, "is treated as equivalent" is better reworded as "and defaults to ...", which is our style in these cases. > + if (NILP (base_uri)) > + base_uri = build_string ("about:blank"); > + CHECK_STRING (base_uri); That last line should better be under 'else', right? > + base_uri = ENCODE_UTF_8 (base_uri); Is it a good idea to produce non-ASCII URIs? > + text = ENCODE_UTF_8 (text); > + xw = XXWIDGET (xwidget); > + > +#ifdef USE_GTK > + data = SSDATA (text); > + uri = SSDATA (base_uri); > + webview = WEBKIT_WEB_VIEW (xw->widget_osr); > + > + block_input (); > + webkit_web_view_load_html (webview, data, uri); > + unblock_input (); > +#endif Hmm... if we only use TEXT and BASE-URI in the GTK build, why do we encode them in the other builds? Isn't that a waste of cycles? IOW, what does this function do if USE_GTK is not defined? Thanks. ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-09 13:21 ` Eli Zaretskii @ 2021-11-09 13:42 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-09 14:07 ` Eli Zaretskii 0 siblings, 1 reply; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-09 13:42 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 51712 [-- Attachment #1: Type: text/plain, Size: 2592 bytes --] Eli Zaretskii <eliz@gnu.org> writes: > > can you rephrase the last sentence not to use passive tense, please? > > But BASE-URI is not an &optional argument above. > > And also, this sentence is unnecessarily complex because you state the > reason before the goal. It is much better to do it the other way > around, and while at that, make 2 simple sentences out of one complex > one: > > Optional argument @var{base-uri}, which should be a string, > specifies the location of the web resource. It defaults to > @samp{about:blank}. > > (Of course, now this begs the question: what does it mean "web > resource" for HTML text? How about answering that in the text?) > > The second part is either unnecessary or too terse. if it is > important to explain that, please elaborate how temporary files are > relevant here. > > The "plain text" part seems to contradict the text in the manual, > which says it will be rendered as HTML markup? > > "will be" is confusing: why the future tense? > > Also, what kind of Lisp type is that? It should be a string, thanks, I've resolved the concerns you listed above. > And I think explaining the importance of "fetching resources" would be > beneficiary here. I documented it in the manual the best I could. I'm no web developer, and the WebKitGTK documentation is vague on this subject, so I can't think of anything better. > And finally, "is treated as equivalent" is better reworded as "and > defaults to ...", which is our style in these cases. Thanks, done. >> + if (NILP (base_uri)) >> + base_uri = build_string ("about:blank"); >> + CHECK_STRING (base_uri); > > That last line should better be under 'else', right? Done, thanks. >> + base_uri = ENCODE_UTF_8 (base_uri); > Is it a good idea to produce non-ASCII URIs? I personally think it's not, but the uuencoding of the URI is done by WebKitGTK, which expects strings passed as the `uri' parameter to be encoded as UTF-8 as opposed to uuencoded. >> + text = ENCODE_UTF_8 (text); >> + xw = XXWIDGET (xwidget); >> + >> +#ifdef USE_GTK >> + data = SSDATA (text); >> + uri = SSDATA (base_uri); >> + webview = WEBKIT_WEB_VIEW (xw->widget_osr); >> + >> + block_input (); >> + webkit_web_view_load_html (webview, data, uri); >> + unblock_input (); >> +#endif > Hmm... if we only use TEXT and BASE-URI in the GTK build, why do we > encode them in the other builds? Isn't that a waste of cycles? IOW, > what does this function do if USE_GTK is not defined? This feature isn't supported on macOS, but it's my hope that someone will port it to macOS in short order. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-xwidget-webkit-load-html.patch --] [-- Type: text/x-patch, Size: 3517 bytes --] From 4d4b1013813bebf9d473cc04f73cf784fb759091 Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Tue, 9 Nov 2021 21:36:40 +0800 Subject: [PATCH] Add `xwidget-webkit-load-html' * doc/lispref/display.texi (Xwidgets): Document new function. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_load_html): New function. (syms_of_xwidget): Define new subr. --- doc/lispref/display.texi | 11 +++++++++++ etc/NEWS | 5 +++++ src/xwidget.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index b6bd14f887..07b9f1a743 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6943,6 +6943,17 @@ Xwidgets signals an error. @end defun +@defun xwidget-webkit-load-html xwidget text &optional base-uri +Load @var{text} into @var{xwidget}, which should be a WebKit xwidget. +It treats @var{text} as HTML markup, which will be rendered by +@var{xwidget}. + +Optional argument @var{base-uri}, which should be a string, specifies +the location of web resources, such as the resource @samp{foo.png} in +the HTML tag @samp{<img src="foo.png">}. It defaults to +@samp{about:blank}. +@end defun + @node Buttons @section Buttons @cindex buttons in buffers diff --git a/etc/NEWS b/etc/NEWS index 807f31fa33..b55630336e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -792,6 +792,11 @@ what the widget will actually receive. On GTK+, only key and function key events are implemented. ++++ +*** New function 'xwidget-webkit-load-html'. +This function is used to load HTML text into WebKit xwidgets, without +having to create a temporary file to store the markup. + +++ *** New functions for performing searches on WebKit xwidgets. Some new functions, such as 'xwidget-webkit-search', have been added diff --git a/src/xwidget.c b/src/xwidget.c index fc76ce307e..37e4fd94c1 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2139,6 +2139,45 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, + Sxwidget_webkit_load_html, 2, 3, 0, + doc: /* Make XWIDGET's WebKit widget render text. +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT +should be a string that will be displayed by XWIDGET as HTML markup. +BASE_URI should be a string containing a URI that is used to fetch +resources, and if not specified, defaults to `about:blank'. */) + (Lisp_Object xwidget, Lisp_Object text, Lisp_Object base_uri) +{ + struct xwidget *xw; +#ifdef USE_GTK + WebKitWebView *webview; + char *data, *uri; +#endif + + CHECK_XWIDGET (xwidget); + CHECK_STRING (text); + if (NILP (base_uri)) + base_uri = build_string ("about:blank"); + else + CHECK_STRING (base_uri); + +#ifdef USE_GTK + base_uri = ENCODE_UTF_8 (base_uri); + text = ENCODE_UTF_8 (text); + xw = XXWIDGET (xwidget); + + data = SSDATA (text); + uri = SSDATA (base_uri); + webview = WEBKIT_WEB_VIEW (xw->widget_osr); + + block_input (); + webkit_web_view_load_html (webview, data, uri); + unblock_input (); +#endif + + return Qnil; +} + void syms_of_xwidget (void) { @@ -2177,6 +2216,7 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_next_result); defsubr (&Sxwidget_webkit_previous_result); defsubr (&Sset_xwidget_buffer); + defsubr (&Sxwidget_webkit_load_html); DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); -- 2.31.1 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-09 13:42 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-09 14:07 ` Eli Zaretskii 2021-11-09 23:56 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 20+ messages in thread From: Eli Zaretskii @ 2021-11-09 14:07 UTC (permalink / raw) To: Po Lu; +Cc: 51712 > From: Po Lu <luangruo@yahoo.com> > Cc: 51712@debbugs.gnu.org > Date: Tue, 09 Nov 2021 21:42:06 +0800 > > >> + text = ENCODE_UTF_8 (text); > >> + xw = XXWIDGET (xwidget); > >> + > >> +#ifdef USE_GTK > >> + data = SSDATA (text); > >> + uri = SSDATA (base_uri); > >> + webview = WEBKIT_WEB_VIEW (xw->widget_osr); > >> + > >> + block_input (); > >> + webkit_web_view_load_html (webview, data, uri); > >> + unblock_input (); > >> +#endif > > > Hmm... if we only use TEXT and BASE-URI in the GTK build, why do we > > encode them in the other builds? Isn't that a waste of cycles? IOW, > > what does this function do if USE_GTK is not defined? > > This feature isn't supported on macOS, but it's my hope that someone > will port it to macOS in short order. Then I'd suggest not to have it defined on non-GTK builds for now. It is confusing to have a function that silently does nothing (after wasting some cycles). > +@defun xwidget-webkit-load-html xwidget text &optional base-uri > +Load @var{text} into @var{xwidget}, which should be a WebKit xwidget. > +It treats @var{text} as HTML markup, which will be rendered by > +@var{xwidget}. I'd say that TEXT should be a string. The name itself doesn't necessarily say so. > +Optional argument @var{base-uri}, which should be a string, specifies > +the location of web resources, such as the resource @samp{foo.png} in > +the HTML tag @samp{<img src="foo.png">}. It defaults to > +@samp{about:blank}. Hmm... this is better, but at least I am still in the dark regarding the need for this optional argument. E.g., what would happen if you use that tag, but don't specify the URI? > +*** New function 'xwidget-webkit-load-html'. > +This function is used to load HTML text into WebKit xwidgets, without > +having to create a temporary file to store the markup. This still leaves me wondering why the entry talks about temporary files. > +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, > + Sxwidget_webkit_load_html, 2, 3, 0, > + doc: /* Make XWIDGET's WebKit widget render text. ^^^^ "text" should be in CAPS. Thanks. ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-09 14:07 ` Eli Zaretskii @ 2021-11-09 23:56 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 0:02 ` Lars Ingebrigtsen 0 siblings, 1 reply; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-09 23:56 UTC (permalink / raw) To: Eli Zaretskii; +Cc: larsi, 51712 [-- Attachment #1: Type: text/plain, Size: 1436 bytes --] Eli Zaretskii <eliz@gnu.org> writes: > Then I'd suggest not to have it defined on non-GTK builds for now. It > is confusing to have a function that silently does nothing (after > wasting some cycles). Thanks, I'll keep that in mind. > I'd say that TEXT should be a string. The name itself doesn't > necessarily say so. Fixed, thanks. >> +Optional argument @var{base-uri}, which should be a string, specifies >> +the location of web resources, such as the resource @samp{foo.png} in >> +the HTML tag @samp{<img src="foo.png">}. It defaults to >> +@samp{about:blank}. > Hmm... this is better, but at least I am still in the dark regarding > the need for this optional argument. E.g., what would happen if you > use that tag, but don't specify the URI? I'm in the dark too. I am not a web developer, and browser engines are remarkably lax about these things, but hopefully Lars can explain better (after all, shr must deal with these things too), so I added him to the Ccs. > This still leaves me wondering why the entry talks about temporary > files. Previously, loading custom markup into a widget required using a temporary file to store the markup. >> +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, >> + Sxwidget_webkit_load_html, 2, 3, 0, >> + doc: /* Make XWIDGET's WebKit widget render text. > ^^^^ > "text" should be in CAPS. Thanks. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-xwidget-webkit-load-html.patch --] [-- Type: text/x-patch, Size: 3529 bytes --] From 8877c57a09dce06f6b1b64294ce8a632f862cc6e Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Tue, 9 Nov 2021 21:36:40 +0800 Subject: [PATCH] Add `xwidget-webkit-load-html' * doc/lispref/display.texi (Xwidgets): Document new function. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_load_html): New function. (syms_of_xwidget): Define new subr. --- doc/lispref/display.texi | 11 +++++++++++ etc/NEWS | 5 +++++ src/xwidget.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index b6bd14f887..0b6dc05267 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6943,6 +6943,17 @@ Xwidgets signals an error. @end defun +@defun xwidget-webkit-load-html xwidget text &optional base-uri +Load @var{text}, a string, into @var{xwidget}, which should be a +WebKit xwidget. It treats @var{text} as HTML markup, which will be +rendered by @var{xwidget}. + +Optional argument @var{base-uri}, which should be a string, specifies +the location of web resources, such as the resource @samp{foo.png} in +the HTML tag @samp{<img src="foo.png">}. It defaults to +@samp{about:blank}. +@end defun + @node Buttons @section Buttons @cindex buttons in buffers diff --git a/etc/NEWS b/etc/NEWS index 807f31fa33..b55630336e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -792,6 +792,11 @@ what the widget will actually receive. On GTK+, only key and function key events are implemented. ++++ +*** New function 'xwidget-webkit-load-html'. +This function is used to load HTML text into WebKit xwidgets, without +having to create a temporary file to store the markup. + +++ *** New functions for performing searches on WebKit xwidgets. Some new functions, such as 'xwidget-webkit-search', have been added diff --git a/src/xwidget.c b/src/xwidget.c index fc76ce307e..2587b658e7 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2139,6 +2139,43 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +#ifdef USE_GTK +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, + Sxwidget_webkit_load_html, 2, 3, 0, + doc: /* Make XWIDGET's WebKit widget render TEXT. +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT +should be a string that will be displayed by XWIDGET as HTML markup. +BASE_URI should be a string containing a URI that is used to fetch +resources, and if not specified, defaults to `about:blank'. */) + (Lisp_Object xwidget, Lisp_Object text, Lisp_Object base_uri) +{ + struct xwidget *xw; + WebKitWebView *webview; + char *data, *uri; + + CHECK_XWIDGET (xwidget); + CHECK_STRING (text); + if (NILP (base_uri)) + base_uri = build_string ("about:blank"); + else + CHECK_STRING (base_uri); + + base_uri = ENCODE_UTF_8 (base_uri); + text = ENCODE_UTF_8 (text); + xw = XXWIDGET (xwidget); + + data = SSDATA (text); + uri = SSDATA (base_uri); + webview = WEBKIT_WEB_VIEW (xw->widget_osr); + + block_input (); + webkit_web_view_load_html (webview, data, uri); + unblock_input (); + + return Qnil; +} +#endif + void syms_of_xwidget (void) { @@ -2177,6 +2214,9 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_next_result); defsubr (&Sxwidget_webkit_previous_result); defsubr (&Sset_xwidget_buffer); +#ifdef USE_GTK + defsubr (&Sxwidget_webkit_load_html); +#endif DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); -- 2.31.1 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-09 23:56 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 0:02 ` Lars Ingebrigtsen 2021-11-10 0:14 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 20+ messages in thread From: Lars Ingebrigtsen @ 2021-11-10 0:02 UTC (permalink / raw) To: Po Lu; +Cc: 51712 Po Lu <luangruo@yahoo.com> writes: >> Hmm... this is better, but at least I am still in the dark regarding >> the need for this optional argument. E.g., what would happen if you >> use that tag, but don't specify the URI? > > I'm in the dark too. I am not a web developer, and browser engines are > remarkably lax about these things, but hopefully Lars can explain better > (after all, shr must deal with these things too), so I added him to the > Ccs. The base URI is used when expanding relative links. So if you have HTML that looks like <a href="foo.html"><img src="img.png"></a> then the browser can't resolve those two URLs without having the base URI. So you'd pass in a base URI of https://example.com/foo/bar/zot if that's where the HTML snippet is from. When the URLs are absolute, the base URI is irrelevant. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 0:02 ` Lars Ingebrigtsen @ 2021-11-10 0:14 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 0:22 ` Lars Ingebrigtsen 0 siblings, 1 reply; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 0:14 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, 51712 [-- Attachment #1: Type: text/plain, Size: 1089 bytes --] Lars Ingebrigtsen <larsi@gnus.org> writes: > Po Lu <luangruo@yahoo.com> writes: > >>> Hmm... this is better, but at least I am still in the dark regarding >>> the need for this optional argument. E.g., what would happen if you >>> use that tag, but don't specify the URI? >> >> I'm in the dark too. I am not a web developer, and browser engines are >> remarkably lax about these things, but hopefully Lars can explain better >> (after all, shr must deal with these things too), so I added him to the >> Ccs. > > The base URI is used when expanding relative links. So if you have HTML > that looks like > > <a href="foo.html"><img src="img.png"></a> > > then the browser can't resolve those two URLs without having the base > URI. So you'd pass in a base URI of https://example.com/foo/bar/zot if > that's where the HTML snippet is from. > > When the URLs are absolute, the base URI is irrelevant. Thanks, does this look OK to you? And I'm afraid I'm not terribly good at phrasing this into words, so I would really appreciate it if you could help write that section of the manual. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-xwidget-webkit-load-html.patch --] [-- Type: text/x-patch, Size: 3562 bytes --] From 1d701339df5ed91ed730fb134976137bcf1e0ce6 Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Tue, 9 Nov 2021 21:36:40 +0800 Subject: [PATCH] Add `xwidget-webkit-load-html' * doc/lispref/display.texi (Xwidgets): Document new function. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_load_html): New function. (syms_of_xwidget): Define new subr. --- doc/lispref/display.texi | 11 +++++++++++ etc/NEWS | 5 +++++ src/xwidget.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index b6bd14f887..aa7d64493c 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6943,6 +6943,17 @@ Xwidgets signals an error. @end defun +@defun xwidget-webkit-load-html xwidget text &optional base-uri +Load @var{text}, a string, into @var{xwidget}, which should be a +WebKit xwidget. It treats @var{text} as HTML markup, which will be +rendered by @var{xwidget}. + +Optional argument @var{base-uri}, which should be a string, specifies +the location of web resources specified through relative links, such +as the resource @samp{foo.png} in the HTML tag @samp{<img +src="foo.png">}. It defaults to @samp{about:blank}. +@end defun + @node Buttons @section Buttons @cindex buttons in buffers diff --git a/etc/NEWS b/etc/NEWS index 3cad0995ac..ae318be1c0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -796,6 +796,11 @@ what the widget will actually receive. On GTK+, only key and function key events are implemented. ++++ +*** New function 'xwidget-webkit-load-html'. +This function is used to load HTML text into WebKit xwidgets, without +having to create a temporary file to store the markup. + +++ *** New functions for performing searches on WebKit xwidgets. Some new functions, such as 'xwidget-webkit-search', have been added diff --git a/src/xwidget.c b/src/xwidget.c index fc76ce307e..2587b658e7 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2139,6 +2139,43 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +#ifdef USE_GTK +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, + Sxwidget_webkit_load_html, 2, 3, 0, + doc: /* Make XWIDGET's WebKit widget render TEXT. +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT +should be a string that will be displayed by XWIDGET as HTML markup. +BASE_URI should be a string containing a URI that is used to fetch +resources, and if not specified, defaults to `about:blank'. */) + (Lisp_Object xwidget, Lisp_Object text, Lisp_Object base_uri) +{ + struct xwidget *xw; + WebKitWebView *webview; + char *data, *uri; + + CHECK_XWIDGET (xwidget); + CHECK_STRING (text); + if (NILP (base_uri)) + base_uri = build_string ("about:blank"); + else + CHECK_STRING (base_uri); + + base_uri = ENCODE_UTF_8 (base_uri); + text = ENCODE_UTF_8 (text); + xw = XXWIDGET (xwidget); + + data = SSDATA (text); + uri = SSDATA (base_uri); + webview = WEBKIT_WEB_VIEW (xw->widget_osr); + + block_input (); + webkit_web_view_load_html (webview, data, uri); + unblock_input (); + + return Qnil; +} +#endif + void syms_of_xwidget (void) { @@ -2177,6 +2214,9 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_next_result); defsubr (&Sxwidget_webkit_previous_result); defsubr (&Sset_xwidget_buffer); +#ifdef USE_GTK + defsubr (&Sxwidget_webkit_load_html); +#endif DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); -- 2.31.1 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 0:14 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 0:22 ` Lars Ingebrigtsen 2021-11-10 2:44 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 20+ messages in thread From: Lars Ingebrigtsen @ 2021-11-10 0:22 UTC (permalink / raw) To: Po Lu; +Cc: 51712 Po Lu <luangruo@yahoo.com> writes: > Thanks, does this look OK to you? And I'm afraid I'm not terribly good > at phrasing this into words, so I would really appreciate it if you > could help write that section of the manual. [...] > +Optional argument @var{base-uri}, which should be a string, specifies > +the location of web resources specified through relative links, such > +as the resource @samp{foo.png} in the HTML tag @samp{<img > +src="foo.png">}. It defaults to @samp{about:blank}. Looks good to me. > +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT > +should be a string that will be displayed by XWIDGET as HTML markup. > +BASE_URI should be a string containing a URI that is used to fetch > +resources, and if not specified, defaults to `about:blank'. */) Should probably be "relative resources (i.e., URLs that aren't absolute)" or something of the kind. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 0:22 ` Lars Ingebrigtsen @ 2021-11-10 2:44 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 5:59 ` Lars Ingebrigtsen 0 siblings, 1 reply; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 2:44 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, 51712 [-- Attachment #1: Type: text/plain, Size: 991 bytes --] Lars Ingebrigtsen <larsi@gnus.org> writes: > Po Lu <luangruo@yahoo.com> writes: > >> Thanks, does this look OK to you? And I'm afraid I'm not terribly good >> at phrasing this into words, so I would really appreciate it if you >> could help write that section of the manual. > > [...] > >> +Optional argument @var{base-uri}, which should be a string, specifies >> +the location of web resources specified through relative links, such >> +as the resource @samp{foo.png} in the HTML tag @samp{<img >> +src="foo.png">}. It defaults to @samp{about:blank}. > > Looks good to me. > >> +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT >> +should be a string that will be displayed by XWIDGET as HTML markup. >> +BASE_URI should be a string containing a URI that is used to fetch >> +resources, and if not specified, defaults to `about:blank'. */) > > Should probably be "relative resources (i.e., URLs that aren't > absolute)" or something of the kind. Hmm, OK, how's this? [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-xwidget-webkit-load-html.patch --] [-- Type: text/x-patch, Size: 3591 bytes --] From 1d701339df5ed91ed730fb134976137bcf1e0ce6 Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Tue, 9 Nov 2021 21:36:40 +0800 Subject: [PATCH] Add `xwidget-webkit-load-html' * doc/lispref/display.texi (Xwidgets): Document new function. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_load_html): New function. (syms_of_xwidget): Define new subr. --- doc/lispref/display.texi | 11 +++++++++++ etc/NEWS | 5 +++++ src/xwidget.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index b6bd14f887..aa7d64493c 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6943,6 +6943,17 @@ Xwidgets signals an error. @end defun +@defun xwidget-webkit-load-html xwidget text &optional base-uri +Load @var{text}, a string, into @var{xwidget}, which should be a +WebKit xwidget. It treats @var{text} as HTML markup, which will be +rendered by @var{xwidget}. + +Optional argument @var{base-uri}, which should be a string, specifies +the location of web resources specified through relative links, such +as the resource @samp{foo.png} in the HTML tag @samp{<img +src="foo.png">}. It defaults to @samp{about:blank}. +@end defun + @node Buttons @section Buttons @cindex buttons in buffers diff --git a/etc/NEWS b/etc/NEWS index 3cad0995ac..ae318be1c0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -796,6 +796,11 @@ what the widget will actually receive. On GTK+, only key and function key events are implemented. ++++ +*** New function 'xwidget-webkit-load-html'. +This function is used to load HTML text into WebKit xwidgets, without +having to create a temporary file to store the markup. + +++ *** New functions for performing searches on WebKit xwidgets. Some new functions, such as 'xwidget-webkit-search', have been added diff --git a/src/xwidget.c b/src/xwidget.c index fc76ce307e..2587b658e7 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2139,6 +2139,44 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +#ifdef USE_GTK +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, + Sxwidget_webkit_load_html, 2, 3, 0, + doc: /* Make XWIDGET's WebKit widget render TEXT. +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT +should be a string that will be displayed by XWIDGET as HTML markup. +BASE_URI should be a string containing a URI that is used to locate +resources described by relative URLs, and if not specified, defaults +to `about:blank'. */) + (Lisp_Object xwidget, Lisp_Object text, Lisp_Object base_uri) +{ + struct xwidget *xw; + WebKitWebView *webview; + char *data, *uri; + + CHECK_XWIDGET (xwidget); + CHECK_STRING (text); + if (NILP (base_uri)) + base_uri = build_string ("about:blank"); + else + CHECK_STRING (base_uri); + + base_uri = ENCODE_UTF_8 (base_uri); + text = ENCODE_UTF_8 (text); + xw = XXWIDGET (xwidget); + + data = SSDATA (text); + uri = SSDATA (base_uri); + webview = WEBKIT_WEB_VIEW (xw->widget_osr); + + block_input (); + webkit_web_view_load_html (webview, data, uri); + unblock_input (); + + return Qnil; +} +#endif + void syms_of_xwidget (void) { @@ -2177,6 +2214,9 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_next_result); defsubr (&Sxwidget_webkit_previous_result); defsubr (&Sset_xwidget_buffer); +#ifdef USE_GTK + defsubr (&Sxwidget_webkit_load_html); +#endif DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); -- 2.31.1 [-- Attachment #3: Type: text/plain, Size: 9 bytes --] Thanks. ^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 2:44 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 5:59 ` Lars Ingebrigtsen 2021-11-10 6:08 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 20+ messages in thread From: Lars Ingebrigtsen @ 2021-11-10 5:59 UTC (permalink / raw) To: Po Lu; +Cc: 51712 Po Lu <luangruo@yahoo.com> writes: > Hmm, OK, how's this? Looks good to me. One tiny thing: > +BASE_URI should be a string containing a URI that is used to locate > +resources described by relative URLs, and if not specified, defaults > +to `about:blank'. */) That should be \"about:blank\" instead, since it's a string and not a symbol. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 5:59 ` Lars Ingebrigtsen @ 2021-11-10 6:08 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 12:50 ` Eli Zaretskii 0 siblings, 1 reply; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 6:08 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, 51712 [-- Attachment #1: Type: text/plain, Size: 182 bytes --] Lars Ingebrigtsen <larsi@gnus.org> writes: > That should be \"about:blank\" instead, since it's a string and not a > symbol. Thanks, how's this? Eli, does this look good to you? [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-xwidget-webkit-load-html.patch --] [-- Type: text/x-patch, Size: 3591 bytes --] From 1d701339df5ed91ed730fb134976137bcf1e0ce6 Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Tue, 9 Nov 2021 21:36:40 +0800 Subject: [PATCH] Add `xwidget-webkit-load-html' * doc/lispref/display.texi (Xwidgets): Document new function. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_load_html): New function. (syms_of_xwidget): Define new subr. --- doc/lispref/display.texi | 11 +++++++++++ etc/NEWS | 5 +++++ src/xwidget.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index b6bd14f887..aa7d64493c 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6943,6 +6943,17 @@ Xwidgets signals an error. @end defun +@defun xwidget-webkit-load-html xwidget text &optional base-uri +Load @var{text}, a string, into @var{xwidget}, which should be a +WebKit xwidget. It treats @var{text} as HTML markup, which will be +rendered by @var{xwidget}. + +Optional argument @var{base-uri}, which should be a string, specifies +the location of web resources specified through relative links, such +as the resource @samp{foo.png} in the HTML tag @samp{<img +src="foo.png">}. It defaults to @samp{about:blank}. +@end defun + @node Buttons @section Buttons @cindex buttons in buffers diff --git a/etc/NEWS b/etc/NEWS index 3cad0995ac..ae318be1c0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -796,6 +796,11 @@ what the widget will actually receive. On GTK+, only key and function key events are implemented. ++++ +*** New function 'xwidget-webkit-load-html'. +This function is used to load HTML text into WebKit xwidgets, without +having to create a temporary file to store the markup. + +++ *** New functions for performing searches on WebKit xwidgets. Some new functions, such as 'xwidget-webkit-search', have been added diff --git a/src/xwidget.c b/src/xwidget.c index fc76ce307e..2587b658e7 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2139,6 +2139,44 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +#ifdef USE_GTK +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, + Sxwidget_webkit_load_html, 2, 3, 0, + doc: /* Make XWIDGET's WebKit widget render TEXT. +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT +should be a string that will be displayed by XWIDGET as HTML markup. +BASE_URI should be a string containing a URI that is used to locate +resources described by relative URLs, and if not specified, defaults +to "about:blank". */) + (Lisp_Object xwidget, Lisp_Object text, Lisp_Object base_uri) +{ + struct xwidget *xw; + WebKitWebView *webview; + char *data, *uri; + + CHECK_XWIDGET (xwidget); + CHECK_STRING (text); + if (NILP (base_uri)) + base_uri = build_string ("about:blank"); + else + CHECK_STRING (base_uri); + + base_uri = ENCODE_UTF_8 (base_uri); + text = ENCODE_UTF_8 (text); + xw = XXWIDGET (xwidget); + + data = SSDATA (text); + uri = SSDATA (base_uri); + webview = WEBKIT_WEB_VIEW (xw->widget_osr); + + block_input (); + webkit_web_view_load_html (webview, data, uri); + unblock_input (); + + return Qnil; +} +#endif + void syms_of_xwidget (void) { @@ -2177,6 +2214,9 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_next_result); defsubr (&Sxwidget_webkit_previous_result); defsubr (&Sset_xwidget_buffer); +#ifdef USE_GTK + defsubr (&Sxwidget_webkit_load_html); +#endif DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); -- 2.31.1 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 6:08 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 12:50 ` Eli Zaretskii 2021-11-10 13:03 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 20+ messages in thread From: Eli Zaretskii @ 2021-11-10 12:50 UTC (permalink / raw) To: Po Lu; +Cc: larsi, 51712 > From: Po Lu <luangruo@yahoo.com> > Cc: Eli Zaretskii <eliz@gnu.org>, 51712@debbugs.gnu.org > Date: Wed, 10 Nov 2021 14:08:59 +0800 > > > That should be \"about:blank\" instead, since it's a string and not a > > symbol. > > Thanks, how's this? Eli, does this look good to you? Almost: > +@defun xwidget-webkit-load-html xwidget text &optional base-uri > +Load @var{text}, a string, into @var{xwidget}, which should be a > +WebKit xwidget. It treats @var{text} as HTML markup, which will be > +rendered by @var{xwidget}. Instead of the last sentence: Any HTML markup in @var{text} will be processed by @var{xwidget} while rendering the text. > +Optional argument @var{base-uri}, which should be a string, specifies > +the location of web resources specified through relative links, such > +as the resource @samp{foo.png} in the HTML tag @samp{<img > +src="foo.png">}. It defaults to @samp{about:blank}. > +@end defun Optional argument @var{base-uri}, which should be a string, specifies the absolute location of the web resources referenced by @var{text}, to be used for resolving relative links in @var{text}. > +*** New function 'xwidget-webkit-load-html'. > +This function is used to load HTML text into WebKit xwidgets, without > +having to create a temporary file to store the markup. Here' I'd like to say something like This is in contrast with loading HTML using ... which requires to create temporary files for storing the markup. But I don't know what to write instead of "...". What was the method which existed earlier that you wanted to improve? > +BASE_URI should be a string containing a URI that is used to locate > +resources described by relative URLs, and if not specified, defaults ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "resources with relative URLs" sounds better to me. Thanks. ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 12:50 ` Eli Zaretskii @ 2021-11-10 13:03 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 14:25 ` Eli Zaretskii 0 siblings, 1 reply; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 13:03 UTC (permalink / raw) To: Eli Zaretskii; +Cc: larsi, 51712 [-- Attachment #1: Type: text/plain, Size: 103 bytes --] Eli Zaretskii <eliz@gnu.org> writes: > Thanks. Thank you! How does the attached patch look to you? [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-Add-xwidget-webkit-load-html.patch --] [-- Type: text/x-patch, Size: 3614 bytes --] From ae73e4478a3fd7de2fc279122dc61e02ea66b217 Mon Sep 17 00:00:00 2001 From: Po Lu <luangruo@yahoo.com> Date: Wed, 10 Nov 2021 21:01:40 +0800 Subject: [PATCH] Add `xwidget-webkit-load-html' * doc/lispref/display.texi (Xwidgets): Document new function. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_load_html): New function. (syms_of_xwidget): Define new subr. --- doc/lispref/display.texi | 9 +++++++++ etc/NEWS | 7 +++++++ src/xwidget.c | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index b6bd14f887..b7d12269ae 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6943,6 +6943,15 @@ Xwidgets signals an error. @end defun +@defun xwidget-webkit-load-html xwidget text &optional base-uri +Load @var{text}, a string, into @var{xwidget}, which should be a +WebKit xwidget. Any HTML markup in @var{text} will be processed +by @var{xwidget} while rendering the text. + +Optional argument @var{base-uri}, which should be a string, specifies +the absolute location of the web resources referenced by @var{text}, +to be used for resolving relative links in @var{text}. + @node Buttons @section Buttons @cindex buttons in buffers diff --git a/etc/NEWS b/etc/NEWS index 3cad0995ac..bc693b3205 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -796,6 +796,13 @@ what the widget will actually receive. On GTK+, only key and function key events are implemented. ++++ +*** New function 'xwidget-webkit-load-html'. +This function is used to load HTML text into WebKit xwidgets +directly, in contrast to creating a temporary file to hold the +markup, and passing the URI of the file as an argument to +'xwidget-webkit-goto-uri'. + +++ *** New functions for performing searches on WebKit xwidgets. Some new functions, such as 'xwidget-webkit-search', have been added diff --git a/src/xwidget.c b/src/xwidget.c index 2ae635092d..fc05f4f570 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2278,6 +2278,44 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +#ifdef USE_GTK +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html, + Sxwidget_webkit_load_html, 2, 3, 0, + doc: /* Make XWIDGET's WebKit widget render TEXT. +XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT +should be a string that will be displayed by XWIDGET as HTML markup. +BASE_URI should be a string containing a URI that is used to locate +resources with relative URLs, and if not specified, defaults +to "about:blank". */) + (Lisp_Object xwidget, Lisp_Object text, Lisp_Object base_uri) +{ + struct xwidget *xw; + WebKitWebView *webview; + char *data, *uri; + + CHECK_XWIDGET (xwidget); + CHECK_STRING (text); + if (NILP (base_uri)) + base_uri = build_string ("about:blank"); + else + CHECK_STRING (base_uri); + + base_uri = ENCODE_UTF_8 (base_uri); + text = ENCODE_UTF_8 (text); + xw = XXWIDGET (xwidget); + + data = SSDATA (text); + uri = SSDATA (base_uri); + webview = WEBKIT_WEB_VIEW (xw->widget_osr); + + block_input (); + webkit_web_view_load_html (webview, data, uri); + unblock_input (); + + return Qnil; +} +#endif + void syms_of_xwidget (void) { @@ -2316,6 +2354,9 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_next_result); defsubr (&Sxwidget_webkit_previous_result); defsubr (&Sset_xwidget_buffer); +#ifdef USE_GTK + defsubr (&Sxwidget_webkit_load_html); +#endif DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); -- 2.31.1 ^ permalink raw reply related [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 13:03 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 14:25 ` Eli Zaretskii 2021-11-11 0:31 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 1 reply; 20+ messages in thread From: Eli Zaretskii @ 2021-11-10 14:25 UTC (permalink / raw) To: Po Lu; +Cc: larsi, 51712 > From: Po Lu <luangruo@yahoo.com> > Cc: larsi@gnus.org, 51712@debbugs.gnu.org > Date: Wed, 10 Nov 2021 21:03:26 +0800 > > Thank you! How does the attached patch look to you? LGTM, thanks. But please fix this gotcha when you push: > +@defun xwidget-webkit-load-html xwidget text &optional base-uri > +Load @var{text}, a string, into @var{xwidget}, which should be a > +WebKit xwidget. Any HTML markup in @var{text} will be processed > +by @var{xwidget} while rendering the text. > + > +Optional argument @var{base-uri}, which should be a string, specifies > +the absolute location of the web resources referenced by @var{text}, > +to be used for resolving relative links in @var{text}. > + This lacks "@end defun" at the end. ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 14:25 ` Eli Zaretskii @ 2021-11-11 0:31 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 0 siblings, 0 replies; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-11 0:31 UTC (permalink / raw) To: Eli Zaretskii; +Cc: larsi, 51712 Eli Zaretskii <eliz@gnu.org> writes: >> From: Po Lu <luangruo@yahoo.com> >> Cc: larsi@gnus.org, 51712@debbugs.gnu.org >> Date: Wed, 10 Nov 2021 21:03:26 +0800 >> >> Thank you! How does the attached patch look to you? > > LGTM, thanks. But please fix this gotcha when you push: > >> +@defun xwidget-webkit-load-html xwidget text &optional base-uri >> +Load @var{text}, a string, into @var{xwidget}, which should be a >> +WebKit xwidget. Any HTML markup in @var{text} will be processed >> +by @var{xwidget} while rendering the text. >> + >> +Optional argument @var{base-uri}, which should be a string, specifies >> +the absolute location of the web resources referenced by @var{text}, >> +to be used for resolving relative links in @var{text}. >> + > > This lacks "@end defun" at the end. Thanks, fixed and pushed. ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-09 10:26 ` bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-09 13:21 ` Eli Zaretskii @ 2021-11-10 4:34 ` Richard Stallman 2021-11-10 4:37 ` Lars Ingebrigtsen 2021-11-10 4:47 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-09-09 18:26 ` Lars Ingebrigtsen 2 siblings, 2 replies; 20+ messages in thread From: Richard Stallman @ 2021-11-10 4:34 UTC (permalink / raw) To: Po Lu; +Cc: 51712 [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > Hopefully this allows to reduce the amount of JavaScript hacks needed to > load HTML into a widget. Would you please explain the role of JavaScript code in use of xwidget? In particular, will this JavaScript code be written specifically for use with Emacs? Or will it be found on the net? -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 4:34 ` Richard Stallman @ 2021-11-10 4:37 ` Lars Ingebrigtsen 2021-11-11 3:37 ` Richard Stallman 2021-11-10 4:47 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 1 sibling, 1 reply; 20+ messages in thread From: Lars Ingebrigtsen @ 2021-11-10 4:37 UTC (permalink / raw) To: Richard Stallman; +Cc: Po Lu, 51712 Richard Stallman <rms@gnu.org> writes: > Would you please explain the role of JavaScript code in use of xwidget? > In particular, will this JavaScript code be written specifically for > use with Emacs? Or will it be found on the net? It's JS written by me included in Emacs. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 4:37 ` Lars Ingebrigtsen @ 2021-11-11 3:37 ` Richard Stallman 0 siblings, 0 replies; 20+ messages in thread From: Richard Stallman @ 2021-11-11 3:37 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: luangruo, 51712 [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > It's JS written by me included in Emacs. Running free JS code included in Emacs is not, in itself, a bad thing. JS is not inherently worse than any other language. But it presupposes that there is a JS interpreter in Emacs, and including that would be taking a big moral risk. Users are likely to use it to run nonfree JS sent by web sites. We must should not make Emacs into a platform for that. It would corrupt the purpose of Emacs. Web browsers which can run Javascript from web sites should take steps to block the Javascript programs which are nonfree. -- Dr Richard Stallman (https://stallman.org) Chief GNUisance of the GNU Project (https://gnu.org) Founder, Free Software Foundation (https://fsf.org) Internet Hall-of-Famer (https://internethalloffame.org) ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-10 4:34 ` Richard Stallman 2021-11-10 4:37 ` Lars Ingebrigtsen @ 2021-11-10 4:47 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 1 sibling, 0 replies; 20+ messages in thread From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-11-10 4:47 UTC (permalink / raw) To: Richard Stallman; +Cc: 51712 Richard Stallman <rms@gnu.org> writes: > Would you please explain the role of JavaScript code in use of xwidget? > In particular, will this JavaScript code be written specifically for > use with Emacs? Or will it be found on the net? It will be JavaScript code written specifically for use with Emacs, used to manipulate the DOM tree of the widget. Thanks. ^ permalink raw reply [flat|nested] 20+ messages in thread
* bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' 2021-11-09 10:26 ` bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-09 13:21 ` Eli Zaretskii 2021-11-10 4:34 ` Richard Stallman @ 2022-09-09 18:26 ` Lars Ingebrigtsen 2 siblings, 0 replies; 20+ messages in thread From: Lars Ingebrigtsen @ 2022-09-09 18:26 UTC (permalink / raw) To: Po Lu; +Cc: 51712 Po Lu <luangruo@yahoo.com> writes: > Hopefully this allows to reduce the amount of JavaScript hacks needed to > load HTML into a widget. It also lets you customize the base URI WebKit > uses to find web resources, which you can't do from JavaScript. [...] > +@defun xwidget-webkit-load-html xwidget text base-uri Looks like this was applied at the time, but the bug report was left open, so I'm closing it now. ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2022-09-09 18:26 UTC | newest] Thread overview: 20+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <878rxx8w1i.fsf.ref@yahoo.com> 2021-11-09 10:26 ` bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-09 13:21 ` Eli Zaretskii 2021-11-09 13:42 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-09 14:07 ` Eli Zaretskii 2021-11-09 23:56 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 0:02 ` Lars Ingebrigtsen 2021-11-10 0:14 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 0:22 ` Lars Ingebrigtsen 2021-11-10 2:44 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 5:59 ` Lars Ingebrigtsen 2021-11-10 6:08 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 12:50 ` Eli Zaretskii 2021-11-10 13:03 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 14:25 ` Eli Zaretskii 2021-11-11 0:31 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2021-11-10 4:34 ` Richard Stallman 2021-11-10 4:37 ` Lars Ingebrigtsen 2021-11-11 3:37 ` Richard Stallman 2021-11-10 4:47 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors 2022-09-09 18:26 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.