Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inbox remove html tags #348

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions sx-inbox.el
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
:type 'integer
:group 'sx)

(defface sx-inbox-item-type
'((t :inherit font-lock-keyword-face)) "")

(defface sx-inbox-item-type-unread
'((t :inherit font-lock-keyword-face :weight bold)) "")

(defface sx-inbox-link
'((t :inherit link)) "")

(defun sx-inbox-get (&optional notifications page keywords)
"Get an array of inbox items for the current user.
If NOTIFICATIONS is non-nil, query from `notifications' method,
Expand Down Expand Up @@ -161,23 +170,33 @@ is an alist containing the elements:
(cond (.answer_id " on Answer at:")
(.question_id " on:")
(t ":")))
'face 'font-lock-keyword-face)
'face (if .is_unread 'sx-inbox-item-type-unread 'sx-inbox-item-type))
(list
(concat (sx-time-since .creation_date)
sx-question-list-ago-string)
'face 'sx-question-list-date)
(list
(propertize
" " 'display
(concat "\n " (propertize (or .title "") 'face 'sx-question-list-date) "\n"
(when .body
(let ((col fill-column))
(with-temp-buffer
(setq fill-column col)
(insert " " .body)
(fill-region (point-min) (point-max))
(buffer-string))))
'face 'default)))))))
(propertize " " 'display
(concat " " (propertize (or .title "") 'face 'sx-question-list-date) "\n"
(when .body
(let (end-1 start-2 text)
(while (and
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think there's any functionality in html-parsing elisp libraries that can help us out here? For example, maybe there's something in eww that will take this HTML string and turn it into displayable text for free.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. Also, it so happens that I'm a contributor to the emacs-w3m' project, and I use emacs as my main internet browser. In fact, my interest in sx.elis because the stackexchange internet interface requires javascript support which emacs browsers don't (can't?) offer. It's been years since I evaluated (and rejected)eww' for my personal use, but my memory is that it uses a package called `shr.el' and at least one other support package.

As for it being "free", nothing is really "free" from an efficiency standpoint, but I have no fundamental objection to using those libraries. A first-glance assessment of things to consider in making that decision:

  1. Does the project need "alot" of html support, or just rare minimal snippets? If the latter, do you want to add a dependency to the package for those minimal snippets? For dependencies outside of mainline emacs, this becomes an install/sync consideration, but if the dependencies are part of main-line emacs (and I think they are), it's only an additional (load ...)(require ...) for an already bloated emacs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By 'free' I tend to mean 'this package doesn't try to do a thing another package will do for us'. Eww is certainly not the most efficient piece of software I've ever seen :-)

If there is minimal support that can be had, I'd prefer to pull that minimal support out into a separate package and depend on that.

(string-match "<a[^>]+>" .body)
(setq end-1 (match-end 0))
(string-match "</a[^>]*>" .body)
(setq start-2 (match-beginning 0)))
(setq .body (replace-regexp-in-string "\\(<a[^<]+</a[^>]*>\\).*\\'"
(setq text (substring .body end-1 start-2)) .body nil nil 1))
(when (string-match text .body)
(add-face-text-property
(match-beginning 0) (match-end 0) 'sx-inbox-link nil .body))))
(let ((col fill-column))
(with-temp-buffer
(setq fill-column col)
(insert " " .body)
(fill-region (point-min) (point-max))
(buffer-string))))
"\n" ) 'face (if .is_unread 'bold 'default) ))))))


;;; Entry commands
Expand Down