forked from Effect-TS/effect
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode2jsdoc-example.html
More file actions
Latest commit
69 lines (67 loc) · 1.9 KB
/
Copy pathcode2jsdoc-example.html
File metadata and controls
69 lines (67 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!doctype html>
<html>
<head>
<metacharset="UTF-8" />
<title>code 2 jsdoc @example</title>
<style>
body {
font-family: Arial;
}
textarea {
font-family: Courier, monospace;
border:1px solid #ccc;
border-radius:4px;
margin:0.5rem;
padding:0.5rem;
font-size: medium;
}
</style>
</head>
<body>
<center>
<h1>code 2 jsdoc @example</h1>
<p>
Given an example pasted in the left textarea, will generate a result
ready to be pasted into a JSDoc comment.
</p>
<divid="app">
<textarea
id="code"
cols="80"
rows="40"
onkeyup="document.getElementById('comment').value = t(this.value)"
></textarea>
<textareaid="comment" cols="80" rows="40" style="color: green">
</textarea>
</div>
</center>
<script>
constcode=document.getElementById("code")
constcomment=document.getElementById("comment")
functiont(src){
// Replace multiline comments with lines prefixed by '// ' and preserve indentation
constwithoutMultilineComments=src.replace(
/\/\*([\s\S]*?)\*\//g,
(_,content)=>{
constcommentLines=content
.split("\n")
.filter((line)=>line.trim()!=="")
returncommentLines
.map((line)=>{
consttrimmedLine=line.replace(/^\s*\*/,"").trim()
constindent=line.match(/^\s*/)[0]
return`// ${indent}${trimmedLine}`
})
.join("\n")
}
)
constlines=withoutMultilineComments
.split("\n")
.map((line)=>" * "+line)
return(
" *\n * @example\n * ```ts\n"+lines.join("\n")+"\n * ```\n *\n"
)
}
</script>
</body>
</html>