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

text/html displayed too small #4

Closed
non-Jedi opened this issue Nov 6, 2018 · 5 comments
Closed

text/html displayed too small #4

non-Jedi opened this issue Nov 6, 2018 · 5 comments

Comments

@non-Jedi
Copy link
Contributor

non-Jedi commented Nov 6, 2018

Since jupyter--debug doesn't seem to log incoming requests (can't look at the metadata associated with svg myself), I haven't been able to get very far in debugging this myself. You're a julia user, so I'll give repro steps in terms of julia code (and an image to let you see what I'm talking about).

using Pkg; Pkg.add.(("Gadfly", "RDatasets"));
using Gadfly, RDatasets;
df = dataset("datasets", "iris")
plot(df, x=:SepalLength, y=:SepalWidth)

jupyter-emacs-small-svg

@nnicandro
Copy link
Collaborator

I can confirm this. The issue is that the plot call returns both text/html and image/svg+xml but the function which inserts the message data, jupyter-repl-insert-data, prioritizes text/html over image/svg+xml. To insert html I use the shr library and it looks like it's default handling of images is not sufficient for our case.

In the meantime, you can make the priority of image/svg+xml higher than text/html by moving its cond clause above text/html in jupyter-repl-insert-data. I will write a shr-put-image-function that will insert the image properly.

@non-Jedi non-Jedi changed the title image/svg+xml displayed too small text/html displayed too small Nov 8, 2018
@nnicandro
Copy link
Collaborator

Actually I spoke too soon. It looks like some of the xml tags are being converted to all lowercase when sending the html to shr. This is an issue because xml is case sensitive. Could you run the following functions after evaluating the first three lines of your reproduction code in a REPL buffer so that I can confirm that this is happening on another system. The first function should raise a search-failed error while the second one should print viewbox found!.

Note the (jupyter-repl-available-repl-buffers 'julia-mode 'first) lines are attempting to get the right REPL buffer and may not work if you have multiple Julia REPL buffers open. You can just replace these lines with the name of the REPL buffer in that case.

(defun search-for-viewbox-raw-html ()
 (let ((jupyter-inhibit-handlers t)
       (jupyter-current-client
        (with-current-buffer
            (jupyter-repl-available-repl-buffers 'julia-mode 'first)
          jupyter-current-client)))
   (jupyter-with-message-data
       (jupyter-wait-until-received :execute-result
         (jupyter-send-execute-request jupyter-current-client
           :code "plot(df, x=:SepalLength, y=:SepalWidth)"))
       ((html text/html))
     (with-temp-buffer
       (insert html)
       (goto-char (point-min))
       (let (case-fold-search)      ; Ensure we care about case when searching
         ;; Should error since it should be viewBox
         (re-search-forward "viewbox")
         (message "viewbox found!"))))))
(defun search-for-viewbox-svg-from-html ()
  (let ((jupyter-inhibit-handlers t)
        (jupyter-current-client
         (with-current-buffer
             (jupyter-repl-available-repl-buffers 'julia-mode 'first)
           jupyter-current-client)))
    (jupyter-with-message-data
        (jupyter-wait-until-received :execute-result
          (jupyter-send-execute-request jupyter-current-client
            :code "plot(df, x=:SepalLength, y=:SepalWidth)"))
        ((html text/html))
      (with-temp-buffer
        (insert html)
        (goto-char (point-min))
        (let* ((svg-data)
               (shr-put-image-function
                (lambda (spec &rest _) (setq svg-data (car spec)))))
          (shr-render-region (point-min) (point-max))
          (erase-buffer)
          (let (case-fold-search)    ; Ensure we care about case when searching
            (insert svg-data)
            (goto-char (point-min))
            ;; Doesn't error here but it should be viewBox
            (re-search-forward "viewbox")
            (message "viewbox found!")))))))

@non-Jedi
Copy link
Contributor Author

non-Jedi commented Nov 16, 2018

@dzop on latest master, anything that returns something with mimetype "text/html" now doesn't display anything at all:

Base.show(io, ::MIME"text/html", x::String) = print(io, "<p>$x<p>")
"hello"

jupyter-text-html-broken

Debug:

SENDING: :is-complete-request (:code Base.show(io, ::MIME"text/html", x::String) = print(io, "<p>$x<p>"))
SENT: (:shell 26787151-7d41-4614-808b-dc6f9c59be1e)
MESSAGE: (:iopub :status (:execution_state busy))
DROPPING-REQ: 6f2867cc-2fd9-4acf-9d3b-843cde167a83
MESSAGE: (:shell :is-complete-reply (:status complete :indent ))
MESSAGE: (:iopub :status (:execution_state idle))
RUN-HOOK: jupyter-shell-message-hook
SENDING: :execute-request (:code Base.show(io, ::MIME"text/html", x::String) = print(io, "<p>$x<p>") :silent :json-false :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell d33c88aa-4af9-4b20-8b1b-75f055c1b67e)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:iopub :execute-input (:code Base.show(io, ::MIME"text/html", x::String) = print(io, "<p>$x<p>") :execution_count 9))
MESSAGE: (:shell :execute-reply (:status ok :payload [] :user_expressions nil :execution_count 9))
RUN-HOOK: jupyter-iopub-message-hook
DROPPING-REQ: 26787151-7d41-4614-808b-dc6f9c59be1e
RUN-HOOK: jupyter-iopub-message-hook
RUN-HOOK: jupyter-shell-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
RUN-HOOK: jupyter-iopub-message-hook
SENDING: :is-complete-request (:code "hello")
SENT: (:shell f86a44ac-d431-4320-91cb-b81c2e5cf3ea)
MESSAGE: (:iopub :status (:execution_state busy))
DROPPING-REQ: d33c88aa-4af9-4b20-8b1b-75f055c1b67e
MESSAGE: (:iopub :status (:execution_state idle))
MESSAGE: (:shell :is-complete-reply (:status complete :indent ))
RUN-HOOK: jupyter-shell-message-hook
SENDING: :execute-request (:code "hello" :silent :json-false :store_history t :user_expressions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :allow_stdin t :stop_on_error :json-false)
SENT: (:shell 9e3e455f-16f2-46de-9366-ddc12f677d0d)
MESSAGE: (:iopub :status (:execution_state busy))
MESSAGE: (:iopub :execute-input (:code "hello" :execution_count 10))
RUN-HOOK: jupyter-iopub-message-hook
DROPPING-REQ: f86a44ac-d431-4320-91cb-b81c2e5cf3ea
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :execute-result (:data (:text/plain "hello" :text/html hello) :metadata nil :execution_count 10))
RUN-HOOK: jupyter-iopub-message-hook
MESSAGE: (:iopub :status (:execution_state idle))
MESSAGE: (:shell :execute-reply (:status ok :payload [] :user_expressions nil :execution_count 10))
RUN-HOOK: jupyter-iopub-message-hook
RUN-HOOK: jupyter-shell-message-hook

@nnicandro
Copy link
Collaborator

nnicandro commented Nov 17, 2018

I can confirm this.

It is because the html doesn't have any html tags so shr-render-region just deletes the text when it tries to render the region in jupyter-insert-html. This happens since jupyter-insert-html is using libxml-parse-xml-region now instead of libxml-parse-html-region. Parsing it as html does give the right results, but we need to also be able to parse the text/html mimetype as XML since the Julia kernel seems to send SVG images using this mimetype.

Thanks, I will find a fix for this. I am not too familiar with xml/html so it might take some.

@nnicandro nnicandro reopened this Nov 17, 2018
@nnicandro
Copy link
Collaborator

OK I believe I have fixed this by parsing as XML if an XML prolog is given, i.e. if the text/html results start with something like <?xml version="1.0" encoding="UTF-8"?> and parsing as HTML otherwise.

Let me know if this is still an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants