[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Gavin D. Smith |
Date: |
Sun, 20 Mar 2022 04:55:20 -0400 (EDT) |
branch: master
commit 59b97ea6098348a9d59f6b43031ef50c3d490c14
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Thu Oct 17 14:05:11 2019 +0100
start at creating a toc sidebar - get the toc from the top node
---
js/infog/extension.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-
js/infog/main.c | 11 +++++++++++
2 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/js/infog/extension.c b/js/infog/extension.c
index 82e79d9bfd..34e6231731 100644
--- a/js/infog/extension.c
+++ b/js/infog/extension.c
@@ -110,7 +110,9 @@ request_callback (WebKitWebPage *web_page,
debug (1, "Intercepting link <%s>\n", uri);
- /* Clear flags on WebKitWebPage object. */
+ /* Clear flags on WebKitWebPage object. These flags are checked after
+ the page is actually loaded. We can't use global variables for this
+ because multiple WebKitWebViews may share them. */
g_object_set_data (G_OBJECT(web_page), "top-node",
GINT_TO_POINTER(0));
g_object_set_data (G_OBJECT(web_page), "send-index",
@@ -286,6 +288,57 @@ send_index (WebKitDOMHTMLCollection *links, gulong
num_links)
debug (1, "index sent\n");
}
+void
+packetize (char *msg_type, GString *msg)
+{
+ GString *s;
+ s = g_string_new (NULL);
+ g_string_append (s, msg_type);
+ g_string_append (s, "\n");
+ g_string_append_len (s, msg->str, msg->len);
+ send_datagram (s);
+ g_string_free (s, TRUE);
+}
+
+void
+send_toc (WebKitDOMDocument *dom_document)
+{
+ GString *toc;
+ WebKitDOMElement *e, *e1;
+ int level = 0;
+ char *s, *s1, *s2, *s3;
+
+ WebKitDOMElement *toc_elt = webkit_dom_document_query_selector
+ (dom_document, "div.contents ul", NULL);
+ if (!toc_elt)
+ return;
+
+ toc = g_string_new (NULL);
+
+ e = webkit_dom_element_get_first_element_child (toc_elt);
+ while (e)
+ {
+ s = webkit_dom_element_get_tag_name (e);
+ if (!strcmp (s, "LI") || !strcmp (s, "li"))
+ {
+ e1 = webkit_dom_element_get_first_element_child (e);
+ s2 = webkit_dom_element_get_tag_name (e1);
+ if (!strcmp (s2, "a") || !strcmp (s2, "A"))
+ {
+ s3 = webkit_dom_element_get_inner_html (e1);
+ g_string_append (toc, s3);
+ g_string_append (toc, "\n");
+ }
+ }
+
+ e = webkit_dom_element_get_next_element_sibling (e);
+ }
+
+ g_print ("BUILT TOC %s\n", toc->str);
+ packetize ("toc", toc);
+ g_string_free (toc, TRUE);
+}
+
void
document_loaded_callback (WebKitWebPage *web_page,
gpointer user_data)
@@ -328,6 +381,7 @@ document_loaded_callback (WebKitWebPage *web_page,
if (top_node_p)
{
+ send_toc (dom_document);
find_indices (links, num_links);
return;
}
diff --git a/js/infog/main.c b/js/infog/main.c
index 50f1c41c94..9fa86aaed9 100644
--- a/js/infog/main.c
+++ b/js/infog/main.c
@@ -219,6 +219,12 @@ load_index_nodes (char *p)
continue_to_load_index_nodes ();
}
+void
+load_toc (char *p)
+{
+ g_print ("ASKED TO LOAD TOC |%s|\n", p);
+}
+
gboolean
socket_cb (GSocket *socket,
@@ -293,6 +299,11 @@ socket_cb (GSocket *socket,
webkit_web_view_load_uri (hiddenWebView, s->str);
g_string_free (s, TRUE);
}
+ else if (!strcmp (buffer, "toc"))
+ {
+ p++;
+ load_toc (p);
+ }
else if (!strcmp (buffer, "index-nodes"))
{
/* Receive URL of files containing an index. */
- [no subject], (continued)
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject],
Gavin D. Smith <=
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20