Skip to content

Commit 177c31e

Browse files
authored
Fix styling for webkit documentation (emacs-lsp#645)
1 parent 4283414 commit 177c31e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lsp-ui-doc.el

+15-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ This only takes effect when `lsp-ui-doc-position' is 'top or 'bottom."
113113
:type 'integer
114114
:group 'lsp-ui-doc)
115115

116+
(defcustom lsp-ui-doc-webkit-max-width-px 600
117+
"Maximum width in pixels for the webkit frame."
118+
:type 'integer
119+
:group 'lsp-ui-doc)
120+
116121
(defcustom lsp-ui-doc-max-height 13
117122
"Maximum number of lines in the frame."
118123
:type 'integer
@@ -305,7 +310,9 @@ Because some variables are buffer local.")
305310
(markdown-hr-display-char nil))
306311
(cond
307312
(lsp-ui-doc-use-webkit
308-
(if (and language (not (string= "text" language)))
313+
(if (and language
314+
(not (string= "text" language))
315+
(not (string= lsp/markup-kind-markdown language)))
309316
(format "```%s\n%s\n```" language string)
310317
string))
311318
;; For other programming languages
@@ -364,9 +371,16 @@ We don't extract the string that `lps-line' is already displaying."
364371
(xwidget-webkit-mode)
365372
(xwidget-webkit-goto-uri (xwidget-at 1)
366373
lsp-ui-doc-webkit-client-path)
374+
(lsp-ui-doc--webkit-set-width)
367375
(lsp-ui-doc--webkit-set-background)
368376
(lsp-ui-doc--webkit-set-foreground)))))
369377

378+
(defun lsp-ui-doc--webkit-set-width ()
379+
"Set webkit document max-width CSS property."
380+
(lsp-ui-doc--webkit-execute-script
381+
(format "document.documentElement.style.setProperty('--webkit-max-width-px', %d + 'px');"
382+
lsp-ui-doc-webkit-max-width-px)))
383+
370384
(defun lsp-ui-doc--webkit-set-background ()
371385
"Set background color of the WebKit widget."
372386
(lsp-ui-doc--webkit-execute-script

lsp-ui-doc.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@
77
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.css">
88
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/default.min.css">
99
<style>
10+
11+
:root {
12+
--webkit-max-width-px: 600px;
13+
}
14+
1015
.markdown-body {
1116
box-sizing: border-box;
12-
min-width: 400px;
13-
max-width: 600px;
17+
min-width: var(--webkit-max-width-px);
18+
max-width: var(--webkit-max-width-px);
1419
margin: 0 auto;
1520
padding: 10px;
1621
}
22+
23+
.markdown-body pre code {
24+
white-space: pre-wrap;
25+
}
1726
</style>
1827
</head>
1928
<body>

0 commit comments

Comments
 (0)