@bcc-code/vue-bcc-chat-ui 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@bcc-code/vue-bcc-chat-ui",
3
3
  "author": "bcc-code",
4
4
  "license": "Apache-2.0",
5
- "version": "2.1.0",
5
+ "version": "2.1.2",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "files": [
@@ -22,6 +22,7 @@
22
22
  "vue": "^3.0.0"
23
23
  },
24
24
  "devDependencies": {
25
+ "@types/markdown-it": "^13.0.7",
25
26
  "@types/node": "^20.11.25",
26
27
  "@vitejs/plugin-vue": "^4.6.2",
27
28
  "path": "^0.12.7",
@@ -37,7 +38,7 @@
37
38
  "@cometchat/uikit-resources": "^4.2.2",
38
39
  "@cometchat/uikit-shared": "^4.2.2",
39
40
  "jwt-decode": "^4.0.0",
40
- "vue-markdown-render": "^2.1.1"
41
+ "markdown-it": "npm:@esm-bundle/markdown-it@^13.0.1"
41
42
  },
42
43
  "scripts": {
43
44
  "dev": "vite",
@@ -1,16 +1,37 @@
1
1
  <script setup lang="ts">
2
- import VueMarkdown from 'vue-markdown-render'
2
+ import markdownit from 'markdown-it/esm';
3
3
 
4
4
  defineProps<{
5
5
  text: string
6
6
  }>()
7
+
8
+ function toMarkdownHtml(str: string) {
9
+ // Regex to match URLs that may or may not start with "www." and are not already part of a Markdown link
10
+ const urlRegex = /(?<!\]\()((?:https?|ftp):\/\/[^\s\]\)]*|www\.[^\s\]\)]+)(?=[\s\]\)](?!\()|$)/g;
11
+
12
+ // Function to format a URL into a Markdown link
13
+ const formatUrlToMarkdown = (match: string) => {
14
+ let url = match;
15
+ // Prepend "http://" to URLs starting with "www."
16
+ if (url.startsWith('www.')) {
17
+ url = 'http://' + url;
18
+ }
19
+ const hostname = new URL(url).hostname;
20
+ return `[${hostname}](${url})`;
21
+ };
22
+
23
+ // Replacing URLs in the string with Markdown links
24
+ const outStr = str.replace(urlRegex, formatUrlToMarkdown);
25
+ const md = new markdownit({
26
+ typographer: true,
27
+ });
28
+
29
+ return md.render(outStr);
30
+ }
7
31
  </script>
8
32
 
9
33
  <template>
10
- <vue-markdown :source="text" :options="{
11
- linkify: true,
12
- typographer: true,
13
- }" class="bcc-chat-msg-bubble" />
34
+ <div v-html="toMarkdownHtml(text)" class="bcc-chat-msg-bubble" />
14
35
  </template>
15
36
 
16
37
  <style lang="scss">
@@ -18,11 +39,12 @@ defineProps<{
18
39
  padding: 8px 12px;
19
40
  width: auto;
20
41
  max-width: 500px;
42
+ line-height: 1.2;
21
43
  font: 400 14px Archivo, sans-serif, Inter;
22
44
 
23
45
  p {
24
46
  color: var(--cc__text-color);
25
-
47
+ line-height: 1.2;
26
48
  word-break: break-word;
27
49
  text-align: left;
28
50
  white-space: pre-line;