;ELC ;;; Compiled ;;; in Emacs version 28.0.50 ;;; with all optimizations. (byte-code "\300\301!\210\300\302!\210\303\304\305\306\307\310\311\312&\210\313\314\315\316\317DD\320\321\322%\210\313\323\315\316\324DD\325\321\322%\210\313\326\315\316\327DD\330\321\322%\210\313\331\315\316\332DD\333\321\322%\210\313\334\315\316\335DD\336\321\337%\210\340\341\342\343#\207" [require url dom custom-declare-group wikinfo nil "Wikipedia infobox to Elisp bridge" :group development :prefix "wikinfo-" custom-declare-variable wikinfo-base-url funcall function #[0 "\300\207" [#1="https://en.wikipedia.org"] 1 #1#] "Base URL used for API URLS." :type string wikinfo-api-endpoint #[0 "\300\207" [#2="/w/api.php?"] 1 #2#] "API endpoint for queries and searches." wikinfo-search-params #[0 "\300\207" [("&action=query" "&generator=search" "&gsrsearch=%s hastemplate:\"infobox\"" "&gsrlimit=20" "&gsrinfo=suggestion" "&gsrnamespace=0" "&gsrwhat=text" "&prop=extracts" "&exintro" "&explaintext" "&exlimit=max" "&exsentences=3" "&format=json")] 1] "Search query parameters." wikinfo-parse-params #[0 "\300\207" [("&action=parse" "&pageid=" "%s" "&prop=text" "§ion=0" "&format=json")] 1] "Page parsing query parameters." wikinfo-ignored-targets #[0 "\300\207" [(style br hr "reference" "plainlinks" "NavHead")] 1] "List of targets for `wikinfo--remove-targets'." list custom-declare-face wikinfo-search-title ((t (:weight bold :height 1.05))) "Face for search result extracts."] 8) #@61 Recusrively retrive PATH from PLIST. (fn PLIST &rest PATH) (defalias 'wikinfo--plist-path #[385 "<\204 \300\301!\210\211\203\302\211A\262\242\"\262\202 \207" [user-error "Plist is not a list" plist-get] 6 (#$ . 1481)]) #@78 Replace query symbol in PARAM-LIST with QUERY string. (fn PARAM-LIST QUERY) (defalias 'wikinfo--url-params #[514 "\300\301\302\303#\266\202\"\207" [format nil mapconcat identity] 9 (#$ . 1717)]) #@28 RETURN base URL for QUERY. (defalias 'wikinfo--url #[0 " P\207" [wikinfo-base-url wikinfo-api-endpoint] 2 (#$ . 1923)]) #@52 Get JSON from URL. Return a JSON object. (fn URL) (defalias 'wikinfo--json #[257 "r\300!q\210\301e\302 \303\304\"\216\305\306\307\310#\210`)\262\"\210\311\312 \313\314#)\207" [url-retrieve-synchronously kill-region match-data make-closure #[0 "\301\300\302\"\207" [V0 set-match-data evaporate] 3] re-search-forward "^\n" nil t json-parse-string buffer-string :object-type plist] 8 (#$ . 2050)]) #@222 Search wikipedia for QUERY. Return plist with page metadata. FILTER must be a unary function which accepts the QUERY result list. It must return a single result. If nil, the user is prompted. (fn &optional QUERY FILTER) (defalias 'wikinfo-search #[512 "\206\301\302!\211\205\303 \304\"P\211\205\305!\211\205#\306\307\310#A\211\205+\311\312\"\211\2056\313\314\315\"\316\"\211\203]\203G\311\317\"!\207\320\321\322\311\323\"\315\324$\315\211\325%\206b\326\327!\207\326\330\"\207" [wikinfo-search-params read-string "Query: " wikinfo--url wikinfo--url-params wikinfo--json wikinfo--plist-path :query :pages mapcar #[257 "\300\301\"\211\205\f\300\302\"\211\205\300\303\"\211\205\300\304\"\211\205:\305!\262\306\307\310#\311Q\301\304\303\312\n\257B\207" [plist-get :extract :pageid :title :index wikinfo--sanitize-data propertize face wikinfo-search-title "\n" :id] 14 "\n\n(fn PAGE)"] sort delq nil #[514 "\300A\301\"\300A\301\"W\207" [plist-get :index] 6 "\n\n(fn A B)"] cdr alist-get completing-read "wikinfo: " car t string= user-error "No candidate selected" "Query %S failed"] 14 (#$ . 2456)]) #@42 Return santizied th STRING. (fn STRING) (defalias 'wikinfo--santize-header-text #[257 "\300\301\302\300\303\302\300\304\305\300\306\302\300\307\305\227#####\207" [replace-regexp-in-string "^-" "" "-$" "--" "-" "[^[:alnum:]-]" "\\(?:[[:space:]]\\| \\)"] 17 (#$ . 3607)]) #@39 Return sanitized STRING. (fn STRING) (defalias 'wikinfo--sanitize-data #[257 "\300\301\302\303\301\304\305\301\306\303\301\307\303\301\310\311\301\312\311\301\313\314\301\315\316\301\317\311\301\320\311\301\321\322\301\323\322\301\324\322\301\325\314+##############!\207" [string-trim replace-regexp-in-string "\\(?:\\[[[:digit:]]*]\\)" "" "\\(?:\\(,\\)\\([^[:space:]]+\\)\\)" "\\1 \\2" "\\(?:^[[:space:]]*,[[:space:]]*\\)" "\\(?:,[[:space:]]*$\\)" "\\(?:[[:space:]]+\\(/[[:alpha:]]*\\)[[:space:]]*\\)" "\\1" "\\(?: \\([,:;.]\\)\\)" ",\\{2,\\}" "," "\\(?:\\([[:digit:]]+\\)[[:space:]]*\\(:\\)[[:space:]]*\\([[:digit:]]+\\)\\)" "\\1\\2\\3" "\\(?: \\([])>}]\\)\\)" "\\(?:\\([(<[{]\\) \\)" "[[:space:]]\\{2,\\}" " " " " "\\(?:\n\\)" "\\(?:[[:space:]]+\n[[:space:]]+\\)"] 45 (#$ . 3887)]) #@191 Remove list of TARGETS from DOM. TARGETS must one of the following: - a symbol representing a tag (e.g. `style`) - a regexp matching a class name Returns altered DOM. (fn DOM TARGETS) (defalias 'wikinfo--remove-targets #[514 "\300\301\302\303\304\305\306\307 \"\"\"\"!\211\211\203$\211@\310\"\210A\266\202\202\207" [delete-dups apply append delq nil mapcar make-closure #[257 "\211;\211\203\n\301\202 \302\300\"\207" [V0 dom-by-class dom-by-tag] 5 "\n\n(fn TARGET)"] dom-remove-node] 11 (#$ . 4682)]) #@62 Return wikipedia infobox as plist for page with ID. (fn ID) (defalias 'wikinfo-infobox #[257 "\302 \303\"P\304!\305\306\307\310$\311\312\313\"r\211q\210\314\315\"\216c\210\316ed\"*\262\317\320\321\" \"\2064\322\323!\324\325\326\327\"@A@\"\326\330\"\331\211\203\216\211@\326\332\"\211\205W\333\334!!\211\205a\334\326\335\"!\211\203\205\211\336\230\262\204\205\211\211\336\230\262\204\205\337\340\341P!\342!#\262\266A\266\202\202D\210\324\325\326\327\"@A@\"\211\203\254\203\254\337\343\344P#\262\210\207" [wikinfo-parse-params wikinfo-ignored-targets wikinfo--url wikinfo--url-params wikinfo--json wikinfo--plist-path :parse :text :* generate-new-buffer " *temp*" t make-closure #[0 "\301\300!\205 \302\300!\207" [V0 buffer-name kill-buffer] 2] libxml-parse-html-region wikinfo--remove-targets dom-by-class "infobox.*" error "Infobox not found" alist-get src dom-by-tag img tr nil th wikinfo--santize-header-text dom-texts td "" plist-put intern ":" wikinfo--sanitize-data :thumbnail "https:"] 19 (#$ . 5208)]) #@114 Return infobox plist for SEARCH. FILTER and SEARCH are passed to `wikinfo-search'. (fn &optional SEARCH FILTER) (defalias 'wikinfo #[512 "\300\"\301\302\303\"!\304\305#\207" [wikinfo-search wikinfo-infobox plist-get :id plist-put :wikinfo] 8 (#$ . 6267)]) (provide 'wikinfo)