1
1
<script setup lang="ts">
2
2
import JSStack from ' jsstack.js' ;
3
+ import JavaStack from ' javastack.js' ;
4
+ import PythonStack from ' pythonstack.js' ;
3
5
import NetStack from ' netstack.js' ;
4
6
import domtoimage from ' dom-to-image-more' ;
5
7
import { useQueryParamOrStorage } from ' @/composable/queryParams' ;
@@ -8,7 +10,7 @@ import { useCopy } from '@/composable/copy';
8
10
9
11
const styleStore = useStyleStore ();
10
12
11
- const stackType = useQueryParamOrStorage <' net' | ' js' >({ name: ' type' , storageName: ' stackfmt:type' , defaultValue: ' net' });
13
+ const stackType = useQueryParamOrStorage <' net' | ' js' | ' java ' | ' python ' >({ name: ' type' , storageName: ' stackfmt:type' , defaultValue: ' net' });
12
14
const stackTrace = ref (' ' );
13
15
const formatedStackTrace = ref <HTMLElement >();
14
16
@@ -17,13 +19,28 @@ watchEffect(() => {
17
19
if (! formatedStackTrace .value ) {
18
20
return ;
19
21
}
22
+ let cleanedStackTrace;
23
+ try {
24
+ cleanedStackTrace = JSON .parse (stackTrace .value );
25
+ }
26
+ catch (_ ) {
27
+ cleanedStackTrace = stackTrace .value .replace (/ (\\ r)? \\ n/ g , ' \n ' ).replace (/ (?:^ ['"] )| (?:['"] $ )/ , ' ' );
28
+ };
20
29
try {
21
30
if (stackType .value === ' js' ) {
22
- formatedStackTrace .value .textContent = stackTrace . value ;
31
+ formatedStackTrace .value .textContent = cleanedStackTrace ;
23
32
JSStack (' .stacktrace' );
24
33
}
34
+ else if (stackType .value === ' java' ) {
35
+ formatedStackTrace .value .textContent = cleanedStackTrace ;
36
+ JavaStack (' .stacktrace' , { prettyprint: true });
37
+ }
38
+ else if (stackType .value === ' python' ) {
39
+ formatedStackTrace .value .textContent = cleanedStackTrace ;
40
+ PythonStack (' .stacktrace' , { prettyprint: true });
41
+ }
25
42
else if (stackType .value === ' net' ) {
26
- formatedStackTrace .value .innerText = stackTrace . value ;
43
+ formatedStackTrace .value .innerText = cleanedStackTrace ;
27
44
const _ = new NetStack (formatedStackTrace .value , { prettyprint: true });
28
45
}
29
46
stackTraceText .value = formatedStackTrace .value .innerText ;
@@ -32,7 +49,19 @@ watchEffect(() => {
32
49
});
33
50
34
51
const stackTraceMarkdown = computed (() => {
35
- const lang = stackType .value === ' net' ? ' csharp' : ' javascript' ;
52
+ let lang;
53
+ if (stackType .value === ' net' ) {
54
+ lang = ' csharp' ;
55
+ }
56
+ else if (stackType .value === ' js' ) {
57
+ lang = ' javascript' ;
58
+ }
59
+ else if (stackType .value === ' java' ) {
60
+ lang = ' java' ;
61
+ }
62
+ else if (stackType .value === ' python' ) {
63
+ lang = ' python' ;
64
+ }
36
65
return ` \`\`\` ${lang }\n ${formatedStackTrace .value ?.innerText }\n\`\`\` ` ;
37
66
});
38
67
@@ -46,10 +75,12 @@ async function downloadAsPNG() {
46
75
link .href = dataUrl ;
47
76
link .click ();
48
77
}
78
+
79
+ const wrap = ref (true );
49
80
</script >
50
81
51
82
<template >
52
- <div >
83
+ <div max-w-600px >
53
84
<n-radio-group v-model:value =" stackType" name =" radiogroup" mb-2 flex justify-center >
54
85
<n-space >
55
86
<n-radio
@@ -60,9 +91,22 @@ async function downloadAsPNG() {
60
91
value =" js"
61
92
label =" Javascript"
62
93
/>
94
+ <n-radio
95
+ value =" python"
96
+ label =" Python"
97
+ />
98
+ <n-radio
99
+ value =" java"
100
+ label =" Java"
101
+ />
63
102
</n-space >
64
103
</n-radio-group >
65
104
105
+ <div mb-2 flex justify-center >
106
+ <n-checkbox v-model:checked =" wrap" >
107
+ Wrap lines?
108
+ </n-checkbox >
109
+ </div >
66
110
<c-input-text
67
111
v-model:value =" stackTrace"
68
112
label =" Stacktrace"
@@ -73,7 +117,7 @@ async function downloadAsPNG() {
73
117
74
118
<n-divider />
75
119
76
- <pre ref =" formatedStackTrace" class =" stacktrace" style =" padding : 20px ; " />
120
+ <pre ref =" formatedStackTrace" class =" stacktrace" : style =" { padding: ' 20px', whiteSpace: wrap ? 'pre-wrap' : 'pre', overflowX: 'auto', wordBreak: 'break-all' } " />
77
121
78
122
<div v-if =" stackTraceText" flex justify-center gap-1 >
79
123
<c-button @click =" copyText()" >
@@ -103,5 +147,7 @@ pre, code {background-color:#333 !important; color: #fff !important;}
103
147
.st-column {color : #f8b068 ;}
104
148
.st-lineNumber {color : #ff4f68 ;}
105
149
.st-fileName {color : #85dbff ;}
150
+ .st-intro {color : #0044dd ;}
151
+ .st-exception {color : #e40000 ;}
106
152
}
107
153
</style >
0 commit comments