Ensure base64 encoding happens after coding the string with UTF8 (#111)

* Fixes #110

Ensure base64 encoding happens after coding the string with UTF8

* Avoid line breaks in base64 encoding
This commit is contained in:
Carlo Sciolla 2019-08-30 22:54:26 +02:00 committed by GitHub
parent 2f8170b30b
commit 19e268c0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -406,13 +406,20 @@ Put the result into buffer BUF. Window is selected according to PREFIX:
(error "PLANTUML Preview failed: %s" event))
(plantuml-update-preview-buffer prefix buf)))))
(defun plantuml-server-encode-url (string)
"Encode the string STRING into a URL suitable for PlantUML server interactions."
(let* ((coding-system (or buffer-file-coding-system
"utf8"))
(encoded-string (base64-encode-string (encode-coding-string string coding-system) t)))
(concat plantuml-server-url "/" plantuml-output-type "/-base64-" encoded-string)))
(defun plantuml-server-preview-string (prefix string buf)
"Preview the diagram from STRING as rendered by the PlantUML server.
Put the result into buffer BUF and place it according to PREFIX:
- 4 (when prefixing the command with C-u) -> new window
- 16 (when prefixing the command with C-u C-u) -> new frame.
- else -> new buffer"
(let* ((url-request-location (concat plantuml-server-url "/" plantuml-output-type "/-base64-" (base64-encode-string string t))))
(let* ((url-request-location (plantuml-server-encode-url string)))
(save-current-buffer
(save-match-data
(url-retrieve url-request-location