Skip to content

Commit be8657f

Browse files
committed
support more rescript lang tags
1 parent 0462aa7 commit be8657f

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

tests/tools_tests/src/docstrings-format/FormatDocstringsTest1.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
This is the first docstring with unformatted ReScript code.
33
4-
```rescript
4+
```res example
55
let badly_formatted=(x,y)=>{
66
let result=x+y
77
if result>0{Console.log("positive")}else{Console.log("negative")}
@@ -24,7 +24,7 @@ module Nested = {
2424
2525
But if I add another line here it should be fine.
2626
27-
```rescript
27+
```res info
2828
module UserService={
2929
let validate=user => user.age>=18 && user.name !== ""
3030
let getName = user=>user.name

tests/tools_tests/src/expected/FormatDocstringsTest1.res.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
This is the first docstring with unformatted ReScript code.
33

4-
```rescript
4+
```res example
55
let badly_formatted = (x, y) => {
66
let result = x + y
77
if result > 0 {
@@ -28,7 +28,7 @@ module Nested = {
2828

2929
But if I add another line here it should be fine.
3030

31-
```rescript
31+
```res info
3232
module UserService = {
3333
let validate = user => user.age >= 18 && user.name !== ""
3434
let getName = user => user.name

tools/src/tools.ml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,14 +726,24 @@ module FormatCodeblocks = struct
726726
in
727727
mapper.structure mapper ast
728728
end
729+
730+
let isResLang lang =
731+
match String.lowercase_ascii lang with
732+
| "res" | "rescript" | "resi" -> true
733+
| lang ->
734+
(* Cover ```res example, and similar *)
735+
String.starts_with ~prefix:"res " lang
736+
|| String.starts_with ~prefix:"rescript " lang
737+
|| String.starts_with ~prefix:"resi " lang
738+
729739
let formatRescriptCodeBlocks content ~transformAssertEqual ~displayFilename
730740
~addError ~markdownBlockStartLine =
731741
(* Detect ReScript code blocks. *)
732742
let hadCodeBlocks = ref false in
733743
let block _m = function
734744
| Cmarkit.Block.Code_block (codeBlock, meta) -> (
735745
match Cmarkit.Block.Code_block.info_string codeBlock with
736-
| Some ((("rescript" | "res"), _) as info_string) ->
746+
| Some ((lang, _) as info_string) when isResLang lang ->
737747
hadCodeBlocks := true;
738748

739749
let currentLine =

0 commit comments

Comments
 (0)