mirror of
https://github.com/RGBCube/cinny
synced 2025-08-01 17:37:46 +00:00
added markdown support
This commit is contained in:
parent
0286a51525
commit
92ba6c9802
3 changed files with 38 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
|||
import EventEmitter from 'events';
|
||||
import { Parser, HtmlRenderer } from 'commonmark';
|
||||
import encrypt from 'browser-encrypt-attachment';
|
||||
import cons from './cons';
|
||||
import settings from './settings';
|
||||
|
||||
function getImageDimension(file) {
|
||||
return new Promise((resolve) => {
|
||||
|
@ -78,6 +80,13 @@ function getVideoThumbnail(video, width, height, mimeType) {
|
|||
});
|
||||
}
|
||||
|
||||
function getFormatedBody(markdown) {
|
||||
const reader = new Parser();
|
||||
const writer = new HtmlRenderer();
|
||||
const parsed = reader.parse(markdown);
|
||||
return writer.render(parsed);
|
||||
}
|
||||
|
||||
class RoomsInput extends EventEmitter {
|
||||
constructor(mx) {
|
||||
super();
|
||||
|
@ -163,6 +172,10 @@ class RoomsInput extends EventEmitter {
|
|||
body: input.message,
|
||||
msgtype: 'm.text',
|
||||
};
|
||||
if (settings.isMarkdown) {
|
||||
content.format = 'org.matrix.custom.html';
|
||||
content.formatted_body = getFormatedBody(input.message);
|
||||
}
|
||||
this.matrixClient.sendMessage(roomId, content);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue