Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F1262612
jdd-context.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
jdd-context.ts
View Options
import
{
FileManager
,
FilePointer
,
PathFilePointer
,
}
from
"@sealcode/file-manager"
;
import
type
{
KoaResponsiveImageRouter
}
from
"koa-responsive-image-router"
;
import
{
marked
}
from
"marked"
;
import
{
FlatTemplatable
}
from
"tempstream"
;
import
{
insert_nbsp
}
from
"./utils/insert_nbsp.js"
;
import
{
get_hyphenator
}
from
"./hyphenation.js"
;
export
interface
JDDContext
{
render_image
:
(
file_id
:
FilePointer
|
string
|
null
,
args
:
Parameters
<
KoaResponsiveImageRouter
[
"image"
]
>
[
1
]
)
=>
FlatTemplatable
;
render_markdown
:
(
language
:
string
,
markdown
:
string
)
=>
FlatTemplatable
;
hyphenate
:
(
language
:
string
,
text
:
string
)
=>
Promise
<
string
>
;
encode_file
:
(
photo
:
FilePointer
,
persistent
:
boolean
)
=>
Promise
<
string
>
;
decode_file
:
(
token
:
string
)
=>
Promise
<
PathFilePointer
|
null
>
;
file_manager
:
FileManager
;
language
:
string
;
}
export
const
makeSimpleJDDContext
:
(
file_manager
:
FileManager
)
=>
Omit
<
JDDContext
,
"language"
>
=
(
file_manager
)
=>
({
render_image
:
async
(
file
)
=>
{
if
(
typeof
file
==
"string"
)
{
file
=
await
file_manager
.
fromToken
(
file
);
}
const
path
=
(
await
file
?
.
getPath
())
||
"/some-path"
;
return
file
?
/* HTML */
`<img src="file://
${
path
}
}" />`
:
""
;
},
hyphenate
:
async
(
language
:
string
,
text
:
string
)
=>
{
const
hyphenator
=
await
get_hyphenator
(
language
);
return
hyphenator
(
text
);
},
render_markdown
:
async
(
language
,
string
)
=>
{
const
hyphenator
=
await
get_hyphenator
(
language
);
return
string
?
marked
.
parse
(
insert_nbsp
(
hyphenator
(
string
)))
:
""
;
},
encode_file
:
(
photo
:
FilePointer
,
persistent
:
boolean
)
=>
{
return
photo
.
save
(
persistent
);
},
decode_file
:
(
token
:
string
)
=>
{
return
file_manager
.
fromToken
(
token
);
},
file_manager
,
});
export
const
makeSimpleEnglishJDDContext
:
(
file_manager
:
FileManager
)
=>
JDDContext
=
(
file_manager
)
=>
({
...
makeSimpleJDDContext
(
file_manager
),
language
:
"en-us"
,
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Fri, Jan 24, 15:15 (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
600137
Default Alt Text
jdd-context.ts (1 KB)
Attached To
Mode
rJDD jdd
Attached
Detach File
Event Timeline
Log In to Comment