mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Fixes to editing of profiles
This commit is contained in:
parent
22ebf72b6b
commit
c8ffca37b1
2 changed files with 32 additions and 4 deletions
29
utils/formatting.ts
Normal file
29
utils/formatting.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { sanitizeHtml } from "@sanitization";
|
||||
import linkifyHtml from "linkify-html";
|
||||
import linkifyStr from "linkify-string";
|
||||
import { parse } from "marked";
|
||||
|
||||
/**
|
||||
* Converts plaintext, MFM or Markdown to HTML
|
||||
* @param text Text to convert
|
||||
* @param content_type Content type of the text (optional, defaults to plaintext)
|
||||
* @returns HTML
|
||||
*/
|
||||
export const convertTextToHtml = async (
|
||||
text: string,
|
||||
content_type?: string
|
||||
) => {
|
||||
if (content_type === "text/markdown") {
|
||||
return linkifyHtml(await sanitizeHtml(parse(text)));
|
||||
} else if (content_type === "text/x.misskeymarkdown") {
|
||||
// Parse as MFM
|
||||
// TODO: Implement MFM
|
||||
return text;
|
||||
} else {
|
||||
// Parse as plaintext
|
||||
return linkifyStr(text)
|
||||
.split("\n")
|
||||
.map(line => `<p>${line}</p>`)
|
||||
.join("\n");
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue