mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
fix pmp new lines
This commit is contained in:
5 files changed
+21
-5
No files matched your search
@@ -399,6 +399,7 @@ export const domToEditorInput = (
|
||||
|
||||
domNodes.forEach((node) => {
|
||||
if (isText(node)) {
|
||||
if (node.data.trim() === '' && node.data.includes('\n')) return;
|
||||
if (lineHolder.length === 0) {
|
||||
// we are inserting first part of line
|
||||
// it may contain block markdown starting data
|
||||
|
||||
@@ -26,10 +26,17 @@ export type OutputOptions = {
|
||||
* a map of regex patterns to replace nicknames with, used when stripNickname is true
|
||||
*/
|
||||
nickNameReplacement?: Map<RegExp, string>;
|
||||
/**
|
||||
* if true, we are inside a <pre> block and should not convert newlines to <br/>
|
||||
*/
|
||||
insidePre?: boolean;
|
||||
};
|
||||
|
||||
const textToCustomHtml = (node: Text, opts: OutputOptions): string => {
|
||||
let string = sanitizeText(node.text);
|
||||
if (!opts.insidePre && !opts.allowBlockMarkdown) {
|
||||
string = string.replaceAll("\n", "<br/>");
|
||||
}
|
||||
if (opts.allowTextFormatting) {
|
||||
if (node.bold) string = `<strong>${string}</strong>`;
|
||||
if (node.italic) string = `<i>${string}</i>`;
|
||||
@@ -60,8 +67,14 @@ const elementToCustomHtml = (node: CustomElement, children: string): string => {
|
||||
return `<h${node.level}>${children}</h${node.level}>`;
|
||||
case BlockType.CodeLine:
|
||||
return `${children}\n`;
|
||||
case BlockType.CodeBlock:
|
||||
return `<pre><code>${children}</code></pre>`;
|
||||
case BlockType.CodeBlock: {
|
||||
const childrenInsidePre = node.children
|
||||
.map((element, index, array) =>
|
||||
toMatrixCustomHTML(element, { ...opts, insidePre: true }),
|
||||
)
|
||||
.join("");
|
||||
return `<pre><code>${childrenInsidePre}</code></pre>`;
|
||||
}
|
||||
case BlockType.QuoteLine:
|
||||
return `${children}<br/>`;
|
||||
case BlockType.BlockQuote:
|
||||
@@ -140,7 +153,7 @@ export const toMatrixCustomHTML = (
|
||||
allowInlineMarkdown: false,
|
||||
allowBlockMarkdown: false,
|
||||
})
|
||||
.replace(/<br\/>$/, "\n")
|
||||
.replace(/<br\/>$/, "\n\n")
|
||||
.replace(/^(\\*)>/, "$1>");
|
||||
|
||||
// strip nicknames if needed
|
||||
|
||||
@@ -852,7 +852,8 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
} else {
|
||||
// we don't have a formatted body, but we need one
|
||||
content.format = 'org.matrix.custom.html';
|
||||
content.formatted_body = `${htmlPrefix}${plainText}`;
|
||||
const escapedBody = sanitizeText(plainText).replaceAll('\n', '<br/>');
|
||||
content.formatted_body = `${htmlPrefix}${escapedBody}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
|
||||
const links = getLinks(editor.children);
|
||||
|
||||
if (!customHtmlEqualsPlainText(customHtml, plainText)) {
|
||||
if (pmpDisplayname || !customHtmlEqualsPlainText(customHtml, plainText)) {
|
||||
newContent.format = 'org.matrix.custom.html';
|
||||
newContent.formatted_body = customHtml;
|
||||
contentBody.format = 'org.matrix.custom.html';
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
|
||||
// Configure marked with Matrix extensions
|
||||
const processor = marked.use({
|
||||
breaks: true,
|
||||
extensions: [
|
||||
matrixSpoilerExtension,
|
||||
matrixMathExtension,
|
||||
|
||||
Reference in new issue
Block a user