aprog 1.6.8 → 1.6.9

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export {
2
2
  div, span, button, a, img, meta, label, input, select, option, options, form, hr, textarea,
3
3
  table, caption, thead, tbody, tr, th, td, pre,
4
- attachCustomTitle, _get, _getAll, GUID, isEmpty, apState, date, pause, apFetch,
4
+ attachCustomTitle, _get, _getAll, GUID, isEmpty, apState, date, pause, apFetch, parseCustomMarkup,
5
5
  chars, isNull, isFloat, isNumeric, isObject, elementToObject, copyText, scrollToTop, scrollToBottom,
6
6
  firstKey, isArray, checkArrays, isNumber, isString, isPromise, ucfirst, deepEqual, nodeListToObject
7
7
  } from './src/aprog.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aprog",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
4
4
  "description": "Допоміжна бібліотека js",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/OpenAI.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {loadCacheDB, saveCacheDB} from "./indexDB.js";
2
+ import {parseCustomMarkup} from "./aprog.js";
2
3
 
3
4
  const empty = (variable) => {
4
5
  if (typeof variable === 'object' && !Array.isArray(variable) && Object.keys(variable).length === 0) {
@@ -17,7 +18,7 @@ export const gemini = async (content) => {
17
18
 
18
19
  if (cache.messages[content]) {
19
20
  console.warn("Відповідь знайдена у кеші");
20
- return cache.messages[content];
21
+ // return cache.messages[content];
21
22
  }
22
23
 
23
24
  const apiKey = import.meta.env.VITE_GEMINI_KEY;
@@ -39,7 +40,7 @@ export const gemini = async (content) => {
39
40
  return data.error.message;
40
41
  }
41
42
 
42
- const answer = data.candidates?.[0]?.content?.parts?.[0]?.text || null;
43
+ const answer = parseCustomMarkup(data.candidates?.[0]?.content?.parts?.[0]?.text || null);
43
44
 
44
45
  if (answer) {
45
46
  cache.messages[content] = answer;
package/src/aprog.js CHANGED
@@ -1347,3 +1347,13 @@ export const attachCustomTitle = (element, text) => {
1347
1347
  tooltip.style.display = "none";
1348
1348
  });
1349
1349
  };
1350
+
1351
+ export const parseCustomMarkup = (text) => {
1352
+ text = text.replace(/```([\s\S]*?)```/g, (match, p1) => {
1353
+ return `<pre><code>${p1.trim()}</code></pre>`;
1354
+ });
1355
+ text = text.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
1356
+ text = text.replace(/`([^`]+?)`/g, '<code>$1</code>');
1357
+ text = text.replace(/^\* (.+)$/gm, '<li>$1</li>');
1358
+ return text;
1359
+ }