astoff / devdocs.el

Emacs viewer for DevDocs
279 stars 16 forks source link

FIX: add a colon for `classifier` spans #40

Open jdtsmith opened 2 weeks ago

jdtsmith commented 2 weeks ago

It seems some docs (e.g. matplotlib) make heavy use of dl/dt with a classifier class set in a span inside the dt, e.g.:

<dt>
<strong>x</strong><span class="classifier">float, default: 0</span>
</dt>

In the devdocs css (at least for sphinx-derived docs), there is:

._python .classifier:before, ._sphinx .classifier:before {
content: ": ";
}

which magically adds a colon before the content. This is ignored by shr, resulting in:

image

This can be fixed by helping shr out:

(defun devdocs-tag-span (dom)
  (when-let ((attrs (nth 1 dom))
         (class (alist-get 'class attrs))
         ((member "classifier" (split-string class " "))))
    (shr-insert ": "))
  (shr-tag-span dom))

(setf (alist-get 'span shr-external-rendering-functions) #'devdocs-tag-span)

After:

image

This same technique could be used to patch any obvious deficiencies in the CSS styling (though this is the one I notice most).

astoff commented 1 week ago

Thanks for the detailed info. This recent PR allows handling these kinds of situation. I will work on it, but probably not in the near future :-).

jdtsmith commented 1 week ago

Ok thanks. Do you plan pulling a collection of "fixes" into a future version, or just document on the wiki?