Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22423146
code-snippet.jdd.tsx
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
code-snippet.jdd.tsx
View Options
import
{
TempstreamJSX
}
from
"tempstream"
;
import
type
{
ComponentToHTMLArgs
}
from
"@sealcode/jdd"
;
import
{
Component
,
ComponentArguments
}
from
"@sealcode/jdd"
;
import
hljs
from
"highlight.js"
;
const
component_arguments
=
{
codeWithLanguage
:
new
ComponentArguments
.
CodeWithCustomLanguage
(),
}
as
const
;
export
class
CodeSnippet
extends
Component
<
typeof
component_arguments
>
{
getArguments
()
{
return
component_arguments
;
}
async
toHTML
({
args
:
{
codeWithLanguage
},
classes
,
}
:
ComponentToHTMLArgs
<
typeof
component_arguments
>
)
:
Promise
<
string
>
{
let
highlightedCode
:
string
;
let
languageNotFoundMessage
:
string
=
""
;
const
language
=
codeWithLanguage
.
language
?
.
toLowerCase
()
||
"plaintext"
;
if
(
hljs
.
getLanguage
(
language
))
{
highlightedCode
=
hljs
.
highlight
(
codeWithLanguage
.
code
,
{
language
,
}).
value
;
}
else
{
highlightedCode
=
hljs
.
highlight
(
codeWithLanguage
.
code
,
{
language
:
"plaintext"
,
}).
value
;
languageNotFoundMessage
=
`Language "
${
language
}
" not found`
;
}
return
(
<
div
class
=
{[
"code-snippet"
,
...
classes
]}
data
-
controller
=
"code-snippet"
>
<
h2
>
CodeSnippet
<
/h2>
{
languageNotFoundMessage
?
(
<
p
class
=
"code-snippet__language-error"
>
{
languageNotFoundMessage
}
<
/p>
)
:
(
<>
<
pre
>
<
code
data
-
code
-
snippet
-
target
=
"code"
>
{
highlightedCode
}
<
/code>
<
/pre>
<
div
class
=
"code-snippet__language"
>
<
span
>
{
codeWithLanguage
.
language
}
<
/span>
<
button
data
-
action
=
"code-snippet#copyCode"
>
Copy
<
/button>
<
/div>
<
/>
)}
<
/div>
);
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sat, Nov 28, 03:31 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1218297
Default Alt Text
code-snippet.jdd.tsx (1 KB)
Attached To
Mode
rREWRITE Configurable rewriter
Attached
Detach File
Event Timeline