Skip to content

Commit

Permalink
retain super/subscripts in markdown conversion (#1170)
Browse files Browse the repository at this point in the history
* retain super/subscripts in markdown conversion

* formatting

* changelog

* fix with_pp issue

* promote ts tests
  • Loading branch information
jfeser committed Jul 28, 2023
1 parent b6c9142 commit 0e86a79
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

## Fixes

- Fix missing super & subscripts in markdown documentation. (#1170)

## Features

- Display text of references in doc strings (#1166)
Expand Down
10 changes: 10 additions & 0 deletions ocaml-lsp-server/src/doc_to_md.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ let rec inline_element_to_inline
raw markups, only for blocks. *)
let meta = loc_to_meta location in
Inline.Text (text, meta)
| { value = `Styled (`Superscript, inlines); location } ->
let text = inline_element_list_to_inlines inlines in
let meta = loc_to_meta location in
Inline.Inlines
([ Inline.Text ("^{", meta); text; Inline.Text ("}", meta) ], meta)
| { value = `Styled (`Subscript, inlines); location } ->
let text = inline_element_list_to_inlines inlines in
let meta = loc_to_meta location in
Inline.Inlines
([ Inline.Text ("_{", meta); text; Inline.Text ("}", meta) ], meta)
| { value = `Styled (style, inlines); location } ->
let text = inline_element_list_to_inlines inlines in
let meta = loc_to_meta location in
Expand Down
1 change: 1 addition & 0 deletions ocaml-lsp-server/src/ocaml_lsp_server.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
open Import
module Version = Version
module Diagnostics = Diagnostics
module Doc_to_md = Doc_to_md
module Diff = Diff
open Fiber.O

Expand Down
1 change: 1 addition & 0 deletions ocaml-lsp-server/src/ocaml_lsp_server.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ val run : Lsp.Cli.Channel.t -> read_dot_merlin:bool -> unit -> unit

module Diagnostics = Diagnostics
module Version = Version
module Doc_to_md = Doc_to_md
17 changes: 17 additions & 0 deletions ocaml-lsp-server/test/e2e-new/doc_to_md.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
open Ocaml_lsp_server.Doc_to_md

let print_doc = function
| Raw s -> print_endline s
| Markdown s -> print_endline s

let%expect_test "superscript" =
let doc = {| 2{^30} |} in

translate doc |> print_doc;
[%expect {| 2^{30} |}]

let%expect_test "subscript" =
let doc = {| a{_b} |} in

translate doc |> print_doc;
[%expect {| a\_{b} |}]
2 changes: 2 additions & 0 deletions ocaml-lsp-server/test/e2e-new/dune
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
jsonrpc
lsp
lsp_fiber
ocaml_lsp_server
;; This is because of the (implicit_transitive_deps false)
;; in dune-project
base
Expand All @@ -41,6 +42,7 @@
action_extract
action_inline
code_actions
doc_to_md
document_flow
for_ppx
hover_extended
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe_opt("textDocument/completion", () => {
#### Inline Formatting
**Bold**, *Italic*, *Emphasize*, Superscript, Subscript, and \`inline code\`
**Bold**, *Italic*, *Emphasize*, ^{Superscript}, \\_{Subscript}, and \`inline code\`
#### Text Alignment
Expand Down

0 comments on commit 0e86a79

Please sign in to comment.