-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: render text inserted from assistant
Signed-off-by: Luka Trovic <[email protected]>
- Loading branch information
1 parent
0a2b5bf
commit 8391675
Showing
4 changed files
with
52 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
/** | ||
* Check if the content has Markdown syntax | ||
* | ||
* @param {string} content Markdown object | ||
*/ | ||
export default function hasMarkdownSyntax(content) { | ||
// Regular expressions for common Markdown patterns | ||
const markdownPatterns = [ | ||
/\*\*.*?\*\*/, // Bold: **text** | ||
/\*.*?\*/, // Italics: *text* | ||
/\[.*?\(.*?\)/, // Links: [text](url) | ||
/^#{1,6}\s.*$/, // Headings: # text | ||
/^\s*[-+*]\s.*/m, // Unordered list: - item | ||
/^\s\d\..*/m, // Ordered list: 1. item | ||
/^>+\s.*/, // Blockquote: > text | ||
/`.*?`/, // Code: `code` | ||
] | ||
|
||
return markdownPatterns.some(pattern => pattern.test(content)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import markdownit from './index.js' | ||
|
||
/** | ||
* Check if the content is valid Markdown syntax | ||
* | ||
* @param {string} content Markdown object | ||
*/ | ||
export default function isValidMarkdown(content) { | ||
try { | ||
markdownit.parse(content) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} |