Skip to content

Commit

Permalink
fix indent breaking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Seasawher committed Feb 4, 2025
1 parent 194c47f commit acdf321
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Mdgen/Analyze.lean
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private def preprocess (lines : Array String) : Array Nat × Array String := Id.
let token := "/-⋆-//--"
let filtered : Array (Option Nat × String) :=
lines.mapIdx (fun idx line =>
if line.startsWith token then
if line.trimLeft.startsWith token then
(some idx, line.replace token "/--")
else
(none, line)
Expand All @@ -49,7 +49,7 @@ private def preprocess (lines : Array String) : Array Nat × Array String := Id.
/-- postprocess for converting doc comment to block comment -/
private def postprocess (indexes : Array Nat) (i : Nat) (line : String) : String :=
if indexes.contains i then
"/-" ++ line.drop "/--".length
line.replace "/--" "/-"
else
line

Expand Down
17 changes: 17 additions & 0 deletions Mdgen/ConvertToMd.lean
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ def runTest (input : List String) (expected : List String) (title := "") : IO Un
"```"
]

#eval runTest
(title := "convert doc comment syntax - indent")
[
"namespace Foo",
" /-⋆-//-- doc comment -/",
" def zero := 0",
"end Foo",
]
[
"```lean",
"namespace Foo",
" /- doc comment -/",
" def zero := 0",
"end Foo",
"```"
]

#eval runTest
(title := "multiple leading block comments in doc comment")
[
Expand Down
8 changes: 8 additions & 0 deletions Test/Exp/First.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ inductive MyNat where
-- Here is a sample of converting doc comment to block comment
/- info: MyNat.zero : MyNat -/
#check MyNat.zero
namespace MyNat
/- ## indent block -/
/- info: zero.succ : MyNat -/
#check MyNat.succ MyNat.zero
end MyNat
```

## nested comment
Expand Down
9 changes: 9 additions & 0 deletions Test/Src/First.lean
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ inductive MyNat where
#guard_msgs in --#
#check MyNat.zero

namespace MyNat
/- ## indent block -/

/-⋆-//-- info: zero.succ : MyNat -/
#guard_msgs in --#
#check MyNat.succ MyNat.zero

end MyNat

/- ## nested comment
Here is a sample of nested block comment:
/- Hi. I am a nested comment! -/
Expand Down

0 comments on commit acdf321

Please sign in to comment.