Created
November 4, 2024 11:41
-
-
Save deton/0417088bee82a7894bb3a7f9d94be444 to your computer and use it in GitHub Desktop.
Lynx patch to support scroll to text fragment #:~:text=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lynx-textfragment.patch | |
Lynx patch to support scroll to text fragment #:~:text= | |
## Limitations | |
* Not support prefix, suffix, textEnd, multiple text fragments(&). | |
* Not support word boundary. | |
(for example, | |
https://blog.chromium.org/2019/12/chrome-80-content-indexing-es-modules.html#:~:text=text | |
matches `context` before `text`) | |
## See also | |
* https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments | |
--- LYMainLoop.c.orig 2024-06-08 11:48:48.920695414 +0900 | |
+++ LYMainLoop.c 2024-11-02 18:28:01.228006209 +0900 | |
@@ -5875,7 +5875,7 @@ int mainloop(void) | |
tmpDocInfo = newdoc; | |
tmpNewline = -1; | |
fill_JUMP_Params(&newdoc.address); | |
- getresult = getfile(&newdoc, &tmpNewline); | |
+ getresult = getfile(&newdoc, &tmpNewline, &prev_target); | |
if (!reloading && !popped_doc && (tmpNewline >= 0)) { | |
LYSetNewline(tmpNewline); | |
} else { | |
@@ -5886,7 +5886,7 @@ int mainloop(void) | |
tmpDocInfo = newdoc; | |
tmpNewline = -1; | |
fill_JUMP_Params(&newdoc.address); | |
- getresult = getfile(&newdoc, &tmpNewline); | |
+ getresult = getfile(&newdoc, &tmpNewline, &prev_target); | |
if (!reloading && !popped_doc && (tmpNewline >= 0)) { | |
LYSetNewline(tmpNewline); | |
} else { | |
--- LYGetFile.h.orig 2005-01-03 08:49:58.000000000 +0900 | |
+++ LYGetFile.h 2024-11-02 18:12:11.328006153 +0900 | |
@@ -9,7 +9,7 @@ extern "C" { | |
#define NOT_FOUND 0 | |
#define NORMAL 1 | |
#define NULLFILE 3 | |
- extern int getfile(DocInfo *doc, int *target); | |
+ extern int getfile(DocInfo *doc, int *target, bstring **prev_target); | |
extern void srcmode_for_next_retrieval(int); | |
extern int follow_link_number(int c, | |
int cur, | |
--- LYGetFile.c.orig 2024-01-15 05:02:21.000000000 +0900 | |
+++ LYGetFile.c 2024-11-04 20:38:54.458000466 +0900 | |
@@ -67,7 +67,7 @@ int HTNoDataOK = 0; | |
* inappropriately with -traversal, and from sending bogus error mail with | |
* MAIL_SYSTEM_ERROR_LOGGING:TRUE. - kw | |
*/ | |
-int getfile(DocInfo *doc, int *target) | |
+int getfile(DocInfo *doc, int *target, bstring **prev_target) | |
{ | |
UrlTypes url_type = NOT_A_URL_TYPE; | |
char *pound; | |
@@ -749,7 +749,7 @@ int getfile(DocInfo *doc, int *target) | |
StrAllocCopy(doc->address, tmp + 1); | |
FREE(tmp); | |
CTRACE((tfp, " changed to '%s'\n", doc->address)); | |
- return getfile(doc, target); | |
+ return getfile(doc, target, prev_target); | |
} else | |
FREE(tmp); | |
} | |
@@ -1058,6 +1058,28 @@ int getfile(DocInfo *doc, int *target) | |
if (!HTMainText) { /* this should not happen... */ | |
return (NULLFILE); /* but it can. - kw */ | |
} | |
+ /* scroll to text fragment */ | |
+ if (!strncmp(pound, "#:~:text=", (size_t) 9)) { | |
+ int offset = 0; | |
+ StrAllocCopy(temp, pound + 9); | |
+ /* not support multiple text fragments */ | |
+ if ((cp = StrChr(temp, '&')) != NULL) | |
+ *cp = '\0'; | |
+ /* not support prefix (need whitespace skip) */ | |
+ if ((cp = strstr(temp, "-,")) != NULL) | |
+ offset = cp + 2 - temp; | |
+ /* not support textEnd */ | |
+ if ((cp = StrChr(temp + offset, ',')) != NULL) | |
+ *cp = '\0'; | |
+ cp = temp + offset; | |
+ HTUnEscape(cp); | |
+ www_user_search(0, doc, cp, 0); | |
+ *target = www_search_result; | |
+ if (www_search_result > 0) { | |
+ BStrCopy0(*prev_target, cp); /* emphasize */ | |
+ } | |
+ FREE(temp); | |
+ } else | |
/* | |
* May set www_search_result. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment