Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9583035
markdown.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
949 B
Referenced Files
None
Subscribers
None
markdown.ts
View Options
import
{
Parser
,
HtmlRenderer
}
from
"commonmark"
;
import
{
Field
,
type
Context
,
type
ValidationResult
}
from
"../../../main.js"
;
import
{
OpenApiTypes
}
from
"../../../schemas/open-api-types.js"
;
const
parser
=
new
Parser
();
const
renderer
=
new
HtmlRenderer
();
export
default
class
Markdown
extends
Field
<
string
>
{
typeName
=
"markdown"
;
open_api_type
:
OpenApiTypes
=
OpenApiTypes
.
STR
;
constructor
()
{
super
();
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
async
decode
(
_
:
Context
,
db_value
:
string
|
null
,
__
:
unknown
,
format
?:
"markdown"
|
"html"
)
{
if
(
db_value
===
null
)
{
return
null
;
}
if
(
format
===
"html"
)
{
const
parsed
=
parser
.
parse
(
db_value
);
return
renderer
.
render
(
parsed
);
}
if
(
format
===
"markdown"
)
{
return
db_value
;
}
return
db_value
;
}
protected
isProperValue
()
:
Promise
<
ValidationResult
>
{
return
Promise
.
resolve
(
Field
.
valid
());
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Oct 11, 08:33 (11 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
984056
Default Alt Text
markdown.ts (949 B)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment