(defun chunyang-eww-import-bookmarks (bookmarks-html-file)
"Import bookmarks from BOOKMARKS-HTML-FILE."
(interactive "fBookmarks HTML File: ")
;; Check if some libraries exist
(require 'eww)
(unless (require 'dom nil 'no-error)
(user-error "dom.el not available, it was added in Emacs 25.1"))
(unless (fboundp 'libxml-parse-html-region)
(user-error "`libxml-parse-html-region' not available, \
your Emacs doesn't have libxml2 support"))
(with-temp-buffer
(insert-file-contents bookmarks-html-file)
(setq eww-bookmarks
(loop with dom = (libxml-parse-html-region (point-min) (point-max))
for a in (dom-by-tag dom 'a)
for url = (dom-attr a 'href)
for title = (dom-text a)
for time = (current-time-string
(seconds-to-time
(string-to-number
(dom-attr a 'add_date))))
collect (list :url url
:title title
:time time)))
(eww-write-bookmarks))
(use-package eww
:defer t
:preface
(defun helm-eww-bookmarks ()
"Alternative to `eww-list-bookmarks'."
(interactive)
(require 'helm)
(require 'eww)
(helm :sources
(helm-build-sync-source "EWW Bookmarks"
:candidates
(lambda ()
(cl-loop for elt in (eww-read-bookmarks)
collect (cons (plist-get elt :title)
(plist-get elt :url))))
:action #'eww)
:buffer "*Helm EWW Bookmarks*"))
(defun chunyang-eww-import-bookmarks (bookmarks-html-file)
"Import bookmarks from BOOKMARKS-HTML-FILE."
(interactive "fBookmarks HTML File: ")
;; Check if some libraries exist
(require 'eww)
(unless (require 'dom nil 'no-error)
(user-error "dom.el not available, it was added in Emacs 25.1"))
(unless (fboundp 'libxml-parse-html-region)
(user-error "`libxml-parse-html-region' not available, \
your Emacs doesn't have libxml2 support"))
(with-temp-buffer
(insert-file-contents bookmarks-html-file)
(setq eww-bookmarks
(loop with dom = (libxml-parse-html-region (point-min) (point-max))
for a in (dom-by-tag dom 'a)
for url = (dom-attr a 'href)
for title = (dom-text a)
for time = (current-time-string
(seconds-to-time
(string-to-number
(dom-attr a 'add_date))))
collect (list :url url
:title title
:time time)))
(eww-write-bookmarks)))
:config
;; XXX Both Google & DuckDuckGo are currently bocked in China
(setq eww-search-prefix "https://duckduckgo.com/html/?q=")
;; Eww doesn't support Javascript, but HTTPS version of Google requires it (?)
;; (setq eww-search-prefix "https://www.google.com.hk/search?q=")
(setq eww-search-prefix "http://www.google.com.hk/search?q=")
(setq eww-search-prefix "https://www.bing.com/search?q="))
(use-package shr-tag-pre-highlight
:ensure t
:after shr
:config
(add-to-list 'shr-external-rendering-functions
'(pre . shr-tag-pre-highlight))
(when (version< emacs-version "26")
(with-eval-after-load 'eww
(advice-add 'eww-display-html :around
'eww-display-html--override-shr-external-rendering-functions))))
(use-package shr
:defer t
:config
;; Don't use proportional fonts for text
(setq shr-use-fonts nil))
(use-package shr-color
:defer t
:preface
(defun chunyang-theme-dark-p ()
"Return t if using Dark theme."
;; FIXME: Use a proper way for this
(let ((theme (car custom-enabled-themes)))
(and theme
(or (string-match-p (rx (or "night" "eighties" "dark" "deep"))
(symbol-name theme))
(string= (symbol-name theme) "wombat"))
t)))
:config
(when (chunyang-theme-dark-p)
;; (info "(Mu4e) Displaying rich-text messages")
(setq shr-color-visible-luminance-min 75)))