astoff / devdocs.el

Emacs viewer for DevDocs
279 stars 16 forks source link

Add customization for extra rendering functions #38

Closed xendk closed 2 months ago

xendk commented 3 months ago

As requested in #37. This works for me, together with:

  :init
  (defun xen-crystal-tag-a (dom)
    (let ((class (dom-attr dom 'class)))
      (when (string= class "view-source")
        (insert " ")))
    (shr-tag-a dom))
  :custom
  (devdocs-extra-rendering-functions '((crystal (a . xen-crystal-tag-a))))

Haven't figured out the PyTorch issue yet, as I don't seem to be able to find an example.

Could use better documentation for the custom var, but I'm already flirting with the 15 line limit, and the paperwork is going to take some time.

astoff commented 3 months ago

Nice, I'll have a closer look soon. I'm debating a bit whether to include those workarounds in the package, or as copy-and-paste examples in the wiki...

Also, regarding PyTorch, here's [one example])https://devdocs.io/pytorch/generated/torch.nn.crossentropyloss#torch.nn.CrossEntropyLoss). In Emacs it displays as

 input has to be a Tensor of size either (minibatch,C)(minibatch, C) or
 (minibatch,C,d1,d2,...,dK)(minibatch, C, d_1, d_2, ..., d_K) with K≥1K \geq 1 for the
 K-dimensional case (described later).
xendk commented 3 months ago

I'm debating a bit whether to include those workarounds in the package, or as copy-and-paste examples in the wiki...

Well, as long it's a few style bug fixes, the best new user experience would be to include them.

one example

Hmm, both missing stuff and duplicated stuff. I'll look into it a day when I'm not as tired. But not being a math geek, what would be the most apropiate rendering (minibatch,C,d1,d2,...,dK) or (minibatch, C, d_1, d_2, ..., d_K)?

xendk commented 3 months ago

I've changed the defcustom to defvar.

After a bit of experimenting on pytorch, I've come up with this quick hack:

(defun devdocs--sphinx-tag-math (dom)
  (when-let (semantics (dom-child-by-tag dom 'semantics))
    (when-let (annotation (dom-child-by-tag semantics 'annotation))
      (insert (dom-text annotation)))))

(setq devdocs-extra-rendering-functions '((sphinx (math . devdocs--sphinx-tag-math))))

It replaces the math block with the TeX annotation element. Requires that one is capable of reading TeX, but it's the best representation in the HTML. I don't know if there's any TeX packages that could be helpful with rendering.

astoff commented 2 months ago

Hi again, and sorry for the delay to react.

Note that you should actually write

(push '(a . xen-crystal-tag-a) (alist-get 'crystal devdocs-extra-rendering-functions))

otherwise you risk overwriting other special rendering functions. I will comment about it in the README.

xendk commented 2 months ago

Excellent.

Note that you should actually write

Thanks, I've adjusted my init file (in the process of replacing use-package with setup.el).