-
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 <luka@nextcloud.com>
- Loading branch information
1 parent
2870198
commit 9f7ef4a
Showing
5 changed files
with
67 additions
and
27 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 | ||
} | ||
} |
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,16 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import hasMarkdownSyntax from './hasMarkdownSyntax.js' | ||
import isValidMarkdown from './isValidMarkdown.js' | ||
|
||
/** | ||
* Check if the content has Markdown syntax | ||
* | ||
* @param {string} content Markdown object | ||
*/ | ||
export default function shouldInterpretAsMarkdown(content) { | ||
return hasMarkdownSyntax(content) && isValidMarkdown(content) | ||
} |