ai-error-assistant-pro 0.0.6 → 0.0.7

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.
@@ -6546,7 +6546,7 @@ if (typeof window !== 'undefined') {
6546
6546
  // Indicate to webpack that this file can be concatenated
6547
6547
  /* harmony default export */ var setPublicPath = (null);
6548
6548
 
6549
- ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/main.vue?vue&type=template&id=63ef79ac&scoped=true
6549
+ ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/main.vue?vue&type=template&id=3f590f5c&scoped=true
6550
6550
  var render = function render() {
6551
6551
  var _vm = this,
6552
6552
  _c = _vm._self._c;
@@ -6563,7 +6563,11 @@ var render = function render() {
6563
6563
  }
6564
6564
  }, [_c('i', {
6565
6565
  staticClass: "el-icon-close"
6566
- })])]), _c('div', {
6566
+ })])]), !_vm.courseFlag ? _c('div', {
6567
+ staticClass: "message-wrap"
6568
+ }, [_c('div', {
6569
+ staticClass: "message-line"
6570
+ }, [_vm._v(_vm._s(_vm.message))])]) : [_c('div', {
6567
6571
  staticClass: "ai-main-content"
6568
6572
  }, [_c('chat', {
6569
6573
  ref: "chatRef",
@@ -6620,7 +6624,7 @@ var render = function render() {
6620
6624
  }
6621
6625
  })])], 1), _c('p', {
6622
6626
  staticClass: "disclaimer"
6623
- }, [_vm._v(" 此功能公测期间对正式版用户开放 ")])]) : _vm._e();
6627
+ }, [_vm._v(" 此功能公测期间对正式版用户开放 ")])]], 2) : _vm._e();
6624
6628
  };
6625
6629
  var staticRenderFns = [function () {
6626
6630
  var _vm = this,
@@ -6641,10 +6645,10 @@ var staticRenderFns = [function () {
6641
6645
  }, [_vm._v("智能解析")])]);
6642
6646
  }];
6643
6647
 
6644
- ;// CONCATENATED MODULE: ./components/demo/src/main.vue?vue&type=template&id=63ef79ac&scoped=true
6648
+ ;// CONCATENATED MODULE: ./components/demo/src/main.vue?vue&type=template&id=3f590f5c&scoped=true
6645
6649
 
6646
- ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat.vue?vue&type=template&id=8e426b78&scoped=true
6647
- var chatvue_type_template_id_8e426b78_scoped_true_render = function render() {
6650
+ ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat.vue?vue&type=template&id=d21026be&scoped=true
6651
+ var chatvue_type_template_id_d21026be_scoped_true_render = function render() {
6648
6652
  var _vm = this,
6649
6653
  _c = _vm._self._c;
6650
6654
  return _c('div', {
@@ -6681,9 +6685,9 @@ var chatvue_type_template_id_8e426b78_scoped_true_render = function render() {
6681
6685
  }
6682
6686
  }), list.type === 'robot' && list.links.length > 0 ? _c('div', {
6683
6687
  staticClass: "link"
6684
- }, [_c('div', {
6688
+ }, [!list.allIdWithStart ? _c('div', [_c('div', {
6685
6689
  staticClass: "link-title"
6686
- }, [_vm._v("相关链接")]), _c('div', {
6690
+ }, [_vm._v("参考文件")]), _c('div', {
6687
6691
  staticClass: "link-content"
6688
6692
  }, [_vm._l(list.links, function (item) {
6689
6693
  return [!item.title.startsWith(_vm.chatMajorId) ? _c('div', {
@@ -6694,11 +6698,43 @@ var chatvue_type_template_id_8e426b78_scoped_true_render = function render() {
6694
6698
  "target": "_blank"
6695
6699
  }
6696
6700
  }, [_c('span', [_vm._v(_vm._s(item.title))])])]) : _vm._e()];
6697
- })], 2)]) : _vm._e(), list.type === 'robot' ? _c('chat-tools', {
6701
+ })], 2)]) : _vm._e()]) : _vm._e(), list.type === 'robot' && list.connectUrl.length > 0 ? _c('div', {
6702
+ staticClass: "link"
6703
+ }, [_c('div', {
6704
+ staticClass: "link-title"
6705
+ }, [_vm._v("相关链接")]), _c('div', {
6706
+ staticClass: "link-content"
6707
+ }, [_vm._l(list.connectUrl, function (item) {
6708
+ return [_c('div', {
6709
+ staticClass: "links"
6710
+ }, [_c('a', {
6711
+ attrs: {
6712
+ "href": item.iaUrl,
6713
+ "target": "_blank"
6714
+ }
6715
+ }, [_c('span', [_vm._v(_vm._s(item.iaUrlName))])])])];
6716
+ })], 2)]) : _vm._e(), list.type === 'robot' && _vm.finish && list.followUps && list.followUps.length > 0 ? _c('div', [_c('div', {
6717
+ staticClass: "link-title"
6718
+ }, [_vm._v("智能追问")]), _c('div', {
6719
+ staticClass: "link-content"
6720
+ }, _vm._l(list.followUps, function (list, index) {
6721
+ return _c('div', {
6722
+ key: index,
6723
+ staticClass: "hot-list",
6724
+ on: {
6725
+ "click": function ($event) {
6726
+ return _vm.selectModule(list);
6727
+ }
6728
+ }
6729
+ }, [_vm._v(" " + _vm._s(list) + " "), _c('i', {
6730
+ staticClass: "el-icon-arrow-right go-icon"
6731
+ })]);
6732
+ }), 0)]) : _vm._e(), list.type === 'robot' ? _c('chat-tools', {
6698
6733
  attrs: {
6699
6734
  "chatId": _vm.chatId,
6700
6735
  "detail-data": list,
6701
- "sending": list.sending
6736
+ "sending": list.sending,
6737
+ "is-last": index === _vm.messageData.length - 1
6702
6738
  },
6703
6739
  on: {
6704
6740
  "on-reanswer": list => _vm.reanswer(list, index),
@@ -6707,7 +6743,7 @@ var chatvue_type_template_id_8e426b78_scoped_true_render = function render() {
6707
6743
  }) : _vm._e()], 1)]);
6708
6744
  })], 2);
6709
6745
  };
6710
- var chatvue_type_template_id_8e426b78_scoped_true_staticRenderFns = [];
6746
+ var chatvue_type_template_id_d21026be_scoped_true_staticRenderFns = [];
6711
6747
 
6712
6748
  ;// CONCATENATED MODULE: ./node_modules/axios/lib/helpers/bind.js
6713
6749
 
@@ -10482,17 +10518,17 @@ const iv = crypto_js_default().enc.Utf8.parse(n);
10482
10518
  // 解密方法
10483
10519
  function decrypt(word) {
10484
10520
  const stringToEncode = 'Hello, World!'; // 要进行 Base64 编码的字符串
10485
- const encodedString = gBase64.encode(stringToEncode); // 进行 Base64 编码
10486
- const decodedString = gBase64.decode(encodedString); // 进行 Base64 解码
10521
+ const encodedString = Base64.encode(stringToEncode); // 进行 Base64 编码
10522
+ const decodedString = Base64.decode(encodedString); // 进行 Base64 解码
10487
10523
 
10488
- let base64 = crypto_js_default().enc.Base64.parse(word);
10489
- let src = crypto_js_default().enc.Base64.stringify(base64);
10490
- let decrypt = crypto_js_default().AES.decrypt(src, key, {
10524
+ let base64 = CryptoJS.enc.Base64.parse(word);
10525
+ let src = CryptoJS.enc.Base64.stringify(base64);
10526
+ let decrypt = CryptoJS.AES.decrypt(src, key, {
10491
10527
  iv: iv,
10492
- mode: (crypto_js_default()).mode.CBC,
10493
- padding: (crypto_js_default()).pad.Pkcs7
10528
+ mode: CryptoJS.mode.CBC,
10529
+ padding: CryptoJS.pad.Pkcs7
10494
10530
  });
10495
- let decryptedStr = decrypt.toString((crypto_js_default()).enc.Utf8);
10531
+ let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
10496
10532
  return decryptedStr.toString();
10497
10533
  }
10498
10534
  ;// CONCATENATED MODULE: ./components/demo/utils/constants.js
@@ -10526,7 +10562,9 @@ const service = lib_axios.create({
10526
10562
  });
10527
10563
  service.interceptors.request.use(config => {
10528
10564
  if (cache.session.getJSON('SRKJ_TOKEN_CACHE')) {
10529
- config.headers["X-Id-Token"] = cache.session.getJSON('SRKJ_TOKEN_CACHE');
10565
+ // config.headers["X-Id-Token"] = cache.session.getJSON('SRKJ_TOKEN_CACHE');
10566
+ if (!config.params) config.params = {};
10567
+ config.params.token = cache.session.getJSON('SRKJ_TOKEN_CACHE');
10530
10568
  }
10531
10569
  // 是否需要防止数据重复提交
10532
10570
  const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
@@ -10559,12 +10597,12 @@ service.interceptors.response.use(res => {
10559
10597
  return res.data;
10560
10598
  }
10561
10599
  let srkjData = res.data;
10562
- if (srkjData) {
10563
- const respData = decrypt(srkjData);
10564
- try {
10565
- srkjData = JSON.parse(respData);
10566
- } catch (e) {}
10567
- }
10600
+ // if (srkjData) {
10601
+ // const respData = decrypt(srkjData);
10602
+ // try {
10603
+ // srkjData = JSON.parse(respData);
10604
+ // } catch (e) {}
10605
+ // }
10568
10606
  if (res.status === 401) {
10569
10607
  external_element_ui_namespaceObject.Message.warning(srkjData.message.description);
10570
10608
  return;
@@ -10574,7 +10612,7 @@ service.interceptors.response.use(res => {
10574
10612
  }
10575
10613
  return srkjData.queryData || srkjData.data || srkjData.token;
10576
10614
  });
10577
- /* harmony default export */ var request = (service);
10615
+ /* harmony default export */ var utils_request = (service);
10578
10616
  ;// CONCATENATED MODULE: ./node_modules/@microsoft/fetch-event-source/lib/esm/parse.js
10579
10617
  async function getBytes(stream, onChunk) {
10580
10618
  const reader = stream.getReader();
@@ -10780,11 +10818,14 @@ function defaultOnOpen(response) {
10780
10818
 
10781
10819
 
10782
10820
 
10821
+
10783
10822
  const baseURL = sessionStorage.getItem('AI-INTELLIGENT-TOOLS_BASE_URL') || constants.publicPath;
10784
- const prefix = sessionStorage.getItem('AI-INTELLIGENT-TOOLS_PRE_FIX') || constants.publicPrefix;
10823
+ let prefix = sessionStorage.getItem('AI-INTELLIGENT-TOOLS_PRE_FIX') || constants.publicPrefix;
10785
10824
 
10825
+ // 0.0.7 版本接口升级
10826
+ prefix += '/plugin/v2';
10786
10827
  const ssoAuth = token => {
10787
- return request({
10828
+ return utils_request({
10788
10829
  url: prefix + '/sso/assistant',
10789
10830
  method: 'get',
10790
10831
  params: {
@@ -10800,14 +10841,14 @@ const authUser = headers => {
10800
10841
  });
10801
10842
  };
10802
10843
  const erranalysis = data => {
10803
- return request({
10844
+ return utils_request({
10804
10845
  url: prefix + '/erranalysis/send',
10805
10846
  method: 'post',
10806
10847
  data
10807
10848
  });
10808
10849
  };
10809
10850
  const retryAnalysis = errId => {
10810
- return request({
10851
+ return utils_request({
10811
10852
  url: prefix + '/erranalysis/retry',
10812
10853
  method: 'post',
10813
10854
  params: {
@@ -10816,39 +10857,58 @@ const retryAnalysis = errId => {
10816
10857
  });
10817
10858
  };
10818
10859
  const chatEvaluateAdd = params => {
10819
- return request({
10860
+ return utils_request({
10820
10861
  url: prefix + `/assistant/chatEvaluateAdd`,
10821
10862
  method: 'post',
10822
10863
  data: params
10823
10864
  });
10824
10865
  };
10825
10866
  const stopChat = chatId => {
10826
- return request({
10867
+ return utils_request({
10827
10868
  url: prefix + `/assistant/stop/${chatId}`,
10828
10869
  method: 'post'
10829
10870
  });
10830
10871
  };
10831
10872
  const chatEvaluateCancel = params => {
10832
- return request({
10873
+ return utils_request({
10833
10874
  url: prefix + `/assistant/chatEvaluateCancel`,
10834
10875
  method: 'post',
10835
10876
  data: params
10836
10877
  });
10837
10878
  };
10838
10879
  const chartClear = chatId => {
10839
- return request({
10880
+ return utils_request({
10840
10881
  url: prefix + `/assistant/chartClear/${chatId}`,
10841
10882
  method: 'post'
10842
10883
  });
10843
10884
  };
10885
+ const checkCourseIdIsExist = resId => {
10886
+ return utils_request({
10887
+ url: prefix + `/ia/hasPermission?courseId=${resId}`,
10888
+ method: 'get'
10889
+ });
10890
+ };
10891
+
10892
+ /**
10893
+ * 自动追问
10894
+ * @param iaId 请求参数id
10895
+ * @param message 对话对
10896
+ * @returns 返回节点详情数据
10897
+ */
10898
+ async function getAutoQuestioning(iaId, message) {
10899
+ return utils_request.post(`${prefix}/ia/autoFollowUp`, {
10900
+ iaId,
10901
+ messages: message
10902
+ });
10903
+ }
10844
10904
  async function sendMessageEventSource(params, signal, onmessage) {
10845
- return fetchEventSource(`${baseURL}${prefix}/assistant/conversation`, {
10905
+ return fetchEventSource(`${baseURL}${prefix}/assistant/conversation?token=${cache.session.getJSON('SRKJ_TOKEN_CACHE')}`, {
10846
10906
  method: 'POST',
10847
10907
  signal: signal,
10848
10908
  openWhenHidden: true,
10849
10909
  headers: {
10850
- 'Content-Type': 'application/json',
10851
- 'X-Id-Token': cache.session.getJSON('SRKJ_TOKEN_CACHE')
10910
+ 'Content-Type': 'application/json'
10911
+ // 'X-Id-Token': cache.session.getJSON('SRKJ_TOKEN_CACHE'),
10852
10912
  },
10853
10913
  body: JSON.stringify(params),
10854
10914
  onmessage
@@ -10856,7 +10916,7 @@ async function sendMessageEventSource(params, signal, onmessage) {
10856
10916
  }
10857
10917
  ;// CONCATENATED MODULE: ./components/demo/utils/config.js
10858
10918
 
10859
-
10919
+ // import constants from '../utils/constants';
10860
10920
 
10861
10921
  const errorList = [{
10862
10922
  name: "格式问题",
@@ -10916,25 +10976,29 @@ const cacheMessageList = [{
10916
10976
  // studentAnswer: '错误的简答题简答题错误错误的简答题简答题错误错误的简答题简答题错误错误的简答题简答题错误',
10917
10977
  // }
10918
10978
 
10979
+ // export const getUserInfo = async (token) => {
10980
+ // const ssoRes = await ssoAuth(token);
10981
+ // const userRes = await authUser({
10982
+ // 'X-Auth-User': encodeURIComponent(ssoRes.name),
10983
+ // 'X-Auth-Token': ssoRes.password,
10984
+ // 'X-Enterprise-Id': `${constants['X-Enterprise-Id']}`,
10985
+ // 'X-App-Id': `${constants['X-App-Id']}`,
10986
+ // 'X-App-Secret': `${constants['X-App-Secret']}`,
10987
+ // 'X-Auth-User-Type': '1',
10988
+ // });
10989
+ // cache.session.setJSON('SRKJ_TOKEN_CACHE', userRes);
10990
+ // }
10919
10991
  const getUserInfo = async token => {
10920
- const ssoRes = await ssoAuth(token);
10921
- const userRes = await authUser({
10922
- 'X-Auth-User': encodeURIComponent(ssoRes.name),
10923
- 'X-Auth-Token': ssoRes.password,
10924
- 'X-Enterprise-Id': `${constants['X-Enterprise-Id']}`,
10925
- 'X-App-Id': `${constants['X-App-Id']}`,
10926
- 'X-App-Secret': `${constants['X-App-Secret']}`,
10927
- 'X-Auth-User-Type': '1'
10928
- });
10929
- cache.session.setJSON('SRKJ_TOKEN_CACHE', userRes);
10992
+ await ssoAuth(token);
10993
+ cache.session.setJSON('SRKJ_TOKEN_CACHE', token);
10930
10994
  };
10931
- ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat-tools.vue?vue&type=template&id=65c1d3ae&scoped=true
10932
- var chat_toolsvue_type_template_id_65c1d3ae_scoped_true_render = function render() {
10995
+ ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat-tools.vue?vue&type=template&id=a40a67cc&scoped=true
10996
+ var chat_toolsvue_type_template_id_a40a67cc_scoped_true_render = function render() {
10933
10997
  var _vm = this,
10934
10998
  _c = _vm._self._c;
10935
10999
  return _vm.listData ? _c('div', {
10936
11000
  staticClass: "robot-tools"
10937
- }, [_vm.listData.stop || _vm.listData.finish || _vm.type === 'error' && !_vm.sending ? _c('div', {
11001
+ }, [(_vm.listData.stop || _vm.listData.finish || _vm.type === 'error' && !_vm.sending) && _vm.isLast ? _c('div', {
10938
11002
  staticClass: "robot-reanswer",
10939
11003
  staticStyle: {
10940
11004
  "margin-bottom": "8px"
@@ -11091,9 +11155,9 @@ var chat_toolsvue_type_template_id_65c1d3ae_scoped_true_render = function render
11091
11155
  }
11092
11156
  }, [_vm._v("提交")])], 1)], 1)])])], 1)]) : _vm._e();
11093
11157
  };
11094
- var chat_toolsvue_type_template_id_65c1d3ae_scoped_true_staticRenderFns = [];
11158
+ var chat_toolsvue_type_template_id_a40a67cc_scoped_true_staticRenderFns = [];
11095
11159
 
11096
- ;// CONCATENATED MODULE: ./components/demo/src/chat-tools.vue?vue&type=template&id=65c1d3ae&scoped=true
11160
+ ;// CONCATENATED MODULE: ./components/demo/src/chat-tools.vue?vue&type=template&id=a40a67cc&scoped=true
11097
11161
 
11098
11162
  ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat-tools.vue?vue&type=script&lang=js
11099
11163
 
@@ -11116,6 +11180,10 @@ var chat_toolsvue_type_template_id_65c1d3ae_scoped_true_staticRenderFns = [];
11116
11180
  sending: {
11117
11181
  type: Boolean,
11118
11182
  default: false
11183
+ },
11184
+ isLast: {
11185
+ type: Boolean,
11186
+ default: false
11119
11187
  }
11120
11188
  },
11121
11189
  data() {
@@ -11190,10 +11258,10 @@ var chat_toolsvue_type_template_id_65c1d3ae_scoped_true_staticRenderFns = [];
11190
11258
  });
11191
11259
  ;// CONCATENATED MODULE: ./components/demo/src/chat-tools.vue?vue&type=script&lang=js
11192
11260
  /* harmony default export */ var src_chat_toolsvue_type_script_lang_js = (chat_toolsvue_type_script_lang_js);
11193
- ;// CONCATENATED MODULE: ./node_modules/mini-css-extract-plugin/dist/loader.js??clonedRuleSet-22.use[0]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-22.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-22.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-22.use[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat-tools.vue?vue&type=style&index=0&id=65c1d3ae&prod&lang=scss&scoped=true
11261
+ ;// CONCATENATED MODULE: ./node_modules/mini-css-extract-plugin/dist/loader.js??clonedRuleSet-22.use[0]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-22.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-22.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-22.use[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat-tools.vue?vue&type=style&index=0&id=a40a67cc&prod&lang=scss&scoped=true
11194
11262
  // extracted by mini-css-extract-plugin
11195
11263
 
11196
- ;// CONCATENATED MODULE: ./components/demo/src/chat-tools.vue?vue&type=style&index=0&id=65c1d3ae&prod&lang=scss&scoped=true
11264
+ ;// CONCATENATED MODULE: ./components/demo/src/chat-tools.vue?vue&type=style&index=0&id=a40a67cc&prod&lang=scss&scoped=true
11197
11265
 
11198
11266
  ;// CONCATENATED MODULE: ./node_modules/@vue/vue-loader-v15/lib/runtime/componentNormalizer.js
11199
11267
  /* globals __VUE_SSR_CONTEXT__ */
@@ -11304,18 +11372,18 @@ function normalizeComponent(
11304
11372
 
11305
11373
  var component = normalizeComponent(
11306
11374
  src_chat_toolsvue_type_script_lang_js,
11307
- chat_toolsvue_type_template_id_65c1d3ae_scoped_true_render,
11308
- chat_toolsvue_type_template_id_65c1d3ae_scoped_true_staticRenderFns,
11375
+ chat_toolsvue_type_template_id_a40a67cc_scoped_true_render,
11376
+ chat_toolsvue_type_template_id_a40a67cc_scoped_true_staticRenderFns,
11309
11377
  false,
11310
11378
  null,
11311
- "65c1d3ae",
11379
+ "a40a67cc",
11312
11380
  null
11313
11381
 
11314
11382
  )
11315
11383
 
11316
11384
  /* harmony default export */ var chat_tools = (component.exports);
11317
- ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/error-chat.vue?vue&type=template&id=3c02c55c&scoped=true
11318
- var error_chatvue_type_template_id_3c02c55c_scoped_true_render = function render() {
11385
+ ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/error-chat.vue?vue&type=template&id=72bccb65&scoped=true
11386
+ var error_chatvue_type_template_id_72bccb65_scoped_true_render = function render() {
11319
11387
  var _vm = this,
11320
11388
  _c = _vm._self._c;
11321
11389
  return _c('div', {
@@ -11431,9 +11499,9 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_render = function render
11431
11499
  domProps: {
11432
11500
  "innerHTML": _vm._s(_vm.analysisData.reason)
11433
11501
  }
11434
- }), _vm.analysisData.recommend && _vm.analysisData.recommend.length > 0 ? _c('div', {
11502
+ }), _vm.analysisData.recommend && _vm.analysisData.recommend.length > 0 && !_vm.allIdWithStart ? _c('div', {
11435
11503
  staticClass: "title-label"
11436
- }, [_vm._v("推荐资料")]) : _vm._e(), _c('div', {
11504
+ }, [_vm._v(" 推荐资料 ")]) : _vm._e(), _c('div', {
11437
11505
  staticClass: "answer-content"
11438
11506
  }, _vm._l(_vm.analysisData.recommend, function (list, index) {
11439
11507
  return _c('div', {
@@ -11441,12 +11509,12 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_render = function render
11441
11509
  staticStyle: {
11442
11510
  "margin-bottom": "8px"
11443
11511
  }
11444
- }, [_c('a', {
11512
+ }, [!list.title.startsWith(_vm.chatMajorId) ? _c('a', {
11445
11513
  attrs: {
11446
11514
  "href": 'https://ai-yuliao.hep.com.cn' + list.url,
11447
11515
  "target": "_blank"
11448
11516
  }
11449
- }, [_vm._v(_vm._s(list.title))])]);
11517
+ }, [_vm._v(_vm._s(list.title) + " ")]) : _vm._e()]);
11450
11518
  }), 0), _c('chat-tools', {
11451
11519
  attrs: {
11452
11520
  "type": "error",
@@ -11458,7 +11526,7 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_render = function render
11458
11526
  }
11459
11527
  })], 1)]);
11460
11528
  };
11461
- var error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns = [function () {
11529
+ var error_chatvue_type_template_id_72bccb65_scoped_true_staticRenderFns = [function () {
11462
11530
  var _vm = this,
11463
11531
  _c = _vm._self._c;
11464
11532
  return _c('div', {
@@ -11477,7 +11545,7 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns = [funct
11477
11545
  })]);
11478
11546
  }];
11479
11547
 
11480
- ;// CONCATENATED MODULE: ./components/demo/src/error-chat.vue?vue&type=template&id=3c02c55c&scoped=true
11548
+ ;// CONCATENATED MODULE: ./components/demo/src/error-chat.vue?vue&type=template&id=72bccb65&scoped=true
11481
11549
 
11482
11550
  ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/error-chat.vue?vue&type=script&lang=js
11483
11551
 
@@ -11496,7 +11564,11 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns = [funct
11496
11564
  // 记录页面点赞 踩情况
11497
11565
  analysisData: {},
11498
11566
  // 记录页面点赞 踩情况
11499
- chatId: '' // 对话id
11567
+ chatId: '',
11568
+ // 对话id
11569
+ chatMajorId: '',
11570
+ // 智能体id
11571
+ allIdWithStart: true // 智能体id
11500
11572
  };
11501
11573
  },
11502
11574
  watch: {
@@ -11530,6 +11602,7 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns = [funct
11530
11602
  }],
11531
11603
  xhModelDetailVoList
11532
11604
  } = analysisRes;
11605
+ if (xhModelDetailVoList) this.chatMajorId = xhModelDetailVoList[0].chatMajorId;
11533
11606
  // 传入工具中的值
11534
11607
  this.chatId = chatId;
11535
11608
  this.detailData = {
@@ -11541,6 +11614,11 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns = [funct
11541
11614
  try {
11542
11615
  this.analysisData = JSON.parse(content);
11543
11616
  this.detailData.errId = errId;
11617
+ for (let item of this.analysisData.recommend) {
11618
+ if (!item.title.startsWith(this.chatMajorId)) {
11619
+ this.allIdWithStart = false;
11620
+ }
11621
+ }
11544
11622
  } catch (e) {
11545
11623
  this.$message.warning('解析失败' + e);
11546
11624
  this.analysisData = {
@@ -11549,7 +11627,7 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns = [funct
11549
11627
  console.log(e);
11550
11628
  }
11551
11629
  } catch (e) {
11552
- return new Error(e);
11630
+ throw new Error(e);
11553
11631
  }
11554
11632
  },
11555
11633
  async reanswer(list) {
@@ -11592,10 +11670,10 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns = [funct
11592
11670
  });
11593
11671
  ;// CONCATENATED MODULE: ./components/demo/src/error-chat.vue?vue&type=script&lang=js
11594
11672
  /* harmony default export */ var src_error_chatvue_type_script_lang_js = (error_chatvue_type_script_lang_js);
11595
- ;// CONCATENATED MODULE: ./node_modules/mini-css-extract-plugin/dist/loader.js??clonedRuleSet-22.use[0]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-22.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-22.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-22.use[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/error-chat.vue?vue&type=style&index=0&id=3c02c55c&prod&lang=scss&scoped=true
11673
+ ;// CONCATENATED MODULE: ./node_modules/mini-css-extract-plugin/dist/loader.js??clonedRuleSet-22.use[0]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-22.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-22.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-22.use[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/error-chat.vue?vue&type=style&index=0&id=72bccb65&prod&lang=scss&scoped=true
11596
11674
  // extracted by mini-css-extract-plugin
11597
11675
 
11598
- ;// CONCATENATED MODULE: ./components/demo/src/error-chat.vue?vue&type=style&index=0&id=3c02c55c&prod&lang=scss&scoped=true
11676
+ ;// CONCATENATED MODULE: ./components/demo/src/error-chat.vue?vue&type=style&index=0&id=72bccb65&prod&lang=scss&scoped=true
11599
11677
 
11600
11678
  ;// CONCATENATED MODULE: ./components/demo/src/error-chat.vue
11601
11679
 
@@ -11608,175 +11686,2664 @@ var error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns = [funct
11608
11686
 
11609
11687
  var error_chat_component = normalizeComponent(
11610
11688
  src_error_chatvue_type_script_lang_js,
11611
- error_chatvue_type_template_id_3c02c55c_scoped_true_render,
11612
- error_chatvue_type_template_id_3c02c55c_scoped_true_staticRenderFns,
11689
+ error_chatvue_type_template_id_72bccb65_scoped_true_render,
11690
+ error_chatvue_type_template_id_72bccb65_scoped_true_staticRenderFns,
11613
11691
  false,
11614
11692
  null,
11615
- "3c02c55c",
11693
+ "72bccb65",
11616
11694
  null
11617
11695
 
11618
11696
  )
11619
11697
 
11620
11698
  /* harmony default export */ var error_chat = (error_chat_component.exports);
11621
- ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat.vue?vue&type=script&lang=js
11622
-
11699
+ ;// CONCATENATED MODULE: ./node_modules/marked/lib/marked.esm.js
11700
+ /**
11701
+ * marked v14.1.2 - a markdown parser
11702
+ * Copyright (c) 2011-2024, Christopher Jeffrey. (MIT Licensed)
11703
+ * https://github.com/markedjs/marked
11704
+ */
11623
11705
 
11706
+ /**
11707
+ * DO NOT EDIT THIS FILE
11708
+ * The code in this file is generated from files in ./src/
11709
+ */
11624
11710
 
11711
+ /**
11712
+ * Gets the original marked default options.
11713
+ */
11714
+ function _getDefaults() {
11715
+ return {
11716
+ async: false,
11717
+ breaks: false,
11718
+ extensions: null,
11719
+ gfm: true,
11720
+ hooks: null,
11721
+ pedantic: false,
11722
+ renderer: null,
11723
+ silent: false,
11724
+ tokenizer: null,
11725
+ walkTokens: null
11726
+ };
11727
+ }
11728
+ let _defaults = _getDefaults();
11729
+ function changeDefaults(newDefaults) {
11730
+ _defaults = newDefaults;
11731
+ }
11625
11732
 
11626
- const controller = new AbortController();
11627
- const signal = controller.signal;
11628
- /* harmony default export */ var chatvue_type_script_lang_js = ({
11629
- name: 'Chat',
11630
- components: {
11631
- ErrorChat: error_chat,
11632
- ChatTools: chat_tools
11633
- },
11634
- props: {
11635
- analyExercise: {},
11636
- keyWord: {
11637
- type: String,
11638
- default: ''
11639
- },
11640
- resId: {
11641
- type: String,
11642
- default: ''
11733
+ /**
11734
+ * Helpers
11735
+ */
11736
+ const escapeTest = /[&<>"']/;
11737
+ const escapeReplace = new RegExp(escapeTest.source, 'g');
11738
+ const escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
11739
+ const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
11740
+ const escapeReplacements = {
11741
+ '&': '&amp;',
11742
+ '<': '&lt;',
11743
+ '>': '&gt;',
11744
+ '"': '&quot;',
11745
+ "'": '&#39;'
11746
+ };
11747
+ const getEscapeReplacement = ch => escapeReplacements[ch];
11748
+ function escape$1(html, encode) {
11749
+ if (encode) {
11750
+ if (escapeTest.test(html)) {
11751
+ return html.replace(escapeReplace, getEscapeReplacement);
11752
+ }
11753
+ } else {
11754
+ if (escapeTestNoEncode.test(html)) {
11755
+ return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
11756
+ }
11757
+ }
11758
+ return html;
11759
+ }
11760
+ const caret = /(^|[^\[])\^/g;
11761
+ function edit(regex, opt) {
11762
+ let source = typeof regex === 'string' ? regex : regex.source;
11763
+ opt = opt || '';
11764
+ const obj = {
11765
+ replace: (name, val) => {
11766
+ let valSource = typeof val === 'string' ? val : val.source;
11767
+ valSource = valSource.replace(caret, '$1');
11768
+ source = source.replace(name, valSource);
11769
+ return obj;
11643
11770
  },
11644
- xtId: {
11645
- type: String,
11646
- default: ''
11771
+ getRegex: () => {
11772
+ return new RegExp(source, opt);
11647
11773
  }
11648
- },
11649
- data() {
11650
- return {
11651
- popover: false,
11652
- input: '',
11653
- errors: [],
11654
- errorList: errorList,
11655
- cacheKeyWord: '',
11656
- // 由于外部需要快速清掉 keyword 但是存在重新发送请求的情况,因此需要一个混存记录
11657
- messageData: [],
11658
- chatId: '',
11659
- // 对话id
11660
- chatMajorId: ''
11661
- };
11662
- },
11663
- computed: {
11664
- canSubmit() {
11665
- return this.errors.length === 0 && this.input === "";
11774
+ };
11775
+ return obj;
11776
+ }
11777
+ function cleanUrl(href) {
11778
+ try {
11779
+ href = encodeURI(href).replace(/%25/g, '%');
11780
+ } catch {
11781
+ return null;
11782
+ }
11783
+ return href;
11784
+ }
11785
+ const noopTest = {
11786
+ exec: () => null
11787
+ };
11788
+ function splitCells(tableRow, count) {
11789
+ // ensure that every cell-delimiting pipe has a space
11790
+ // before it to distinguish it from an escaped pipe
11791
+ const row = tableRow.replace(/\|/g, (match, offset, str) => {
11792
+ let escaped = false;
11793
+ let curr = offset;
11794
+ while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
11795
+ if (escaped) {
11796
+ // odd number of slashes means | is escaped
11797
+ // so we leave it alone
11798
+ return '|';
11799
+ } else {
11800
+ // add space before unescaped |
11801
+ return ' |';
11802
+ }
11803
+ }),
11804
+ cells = row.split(/ \|/);
11805
+ let i = 0;
11806
+ // First/last cell in a row cannot be empty if it has no leading/trailing pipe
11807
+ if (!cells[0].trim()) {
11808
+ cells.shift();
11809
+ }
11810
+ if (cells.length > 0 && !cells[cells.length - 1].trim()) {
11811
+ cells.pop();
11812
+ }
11813
+ if (count) {
11814
+ if (cells.length > count) {
11815
+ cells.splice(count);
11816
+ } else {
11817
+ while (cells.length < count) cells.push('');
11666
11818
  }
11667
- },
11668
- watch: {
11669
- keyWord: {
11670
- handler() {
11671
- if (this.keyWord) {
11672
- this.cacheKeyWord = this.keyWord;
11673
- this.postMessage();
11674
- }
11675
- },
11676
- immediate: true
11819
+ }
11820
+ for (; i < cells.length; i++) {
11821
+ // leading or trailing whitespace is ignored per the gfm spec
11822
+ cells[i] = cells[i].trim().replace(/\\\|/g, '|');
11823
+ }
11824
+ return cells;
11825
+ }
11826
+ /**
11827
+ * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
11828
+ * /c*$/ is vulnerable to REDOS.
11829
+ *
11830
+ * @param str
11831
+ * @param c
11832
+ * @param invert Remove suffix of non-c chars instead. Default falsey.
11833
+ */
11834
+ function rtrim(str, c, invert) {
11835
+ const l = str.length;
11836
+ if (l === 0) {
11837
+ return '';
11838
+ }
11839
+ // Length of suffix matching the invert condition.
11840
+ let suffLen = 0;
11841
+ // Step left until we fail to match the invert condition.
11842
+ while (suffLen < l) {
11843
+ const currChar = str.charAt(l - suffLen - 1);
11844
+ if (currChar === c && !invert) {
11845
+ suffLen++;
11846
+ } else if (currChar !== c && invert) {
11847
+ suffLen++;
11848
+ } else {
11849
+ break;
11677
11850
  }
11678
- },
11679
- methods: {
11680
- cancelPopover() {
11681
- this.popover = false;
11682
- },
11683
- openPopover() {
11684
- this.popover = true;
11685
- },
11686
- scrollToBottom() {
11687
- this.$refs.chatContainer.scrollTop = this.$refs.chatContainer.scrollHeight;
11688
- },
11689
- async postMessage(list, commonKey, parentMsgId) {
11690
- let reanswerParams = {};
11691
- if (list) {
11692
- list.sending = true;
11693
- reanswerParams = {
11694
- reStatus: 1,
11695
- parentMsgId: list.parentMsgId,
11696
- msgId: list.msgId,
11697
- content: this.messageData[list.index - 1].message
11698
- };
11699
- this.messageData[list.index].message = '';
11851
+ }
11852
+ return str.slice(0, l - suffLen);
11853
+ }
11854
+ function findClosingBracket(str, b) {
11855
+ if (str.indexOf(b[1]) === -1) {
11856
+ return -1;
11857
+ }
11858
+ let level = 0;
11859
+ for (let i = 0; i < str.length; i++) {
11860
+ if (str[i] === '\\') {
11861
+ i++;
11862
+ } else if (str[i] === b[0]) {
11863
+ level++;
11864
+ } else if (str[i] === b[1]) {
11865
+ level--;
11866
+ if (level < 0) {
11867
+ return i;
11700
11868
  }
11701
- const params = {
11702
- messageList: [{
11703
- content: this.keyWord || this.cacheKeyWord,
11704
- resId: this.resId,
11705
- chatId: this.chatId || undefined,
11706
- commonKey: commonKey || false,
11707
- parentMsgId: parentMsgId || undefined,
11708
- ...reanswerParams
11709
- }]
11869
+ }
11870
+ }
11871
+ return -1;
11872
+ }
11873
+ function outputLink(cap, link, raw, lexer) {
11874
+ const href = link.href;
11875
+ const title = link.title ? escape$1(link.title) : null;
11876
+ const text = cap[1].replace(/\\([\[\]])/g, '$1');
11877
+ if (cap[0].charAt(0) !== '!') {
11878
+ lexer.state.inLink = true;
11879
+ const token = {
11880
+ type: 'link',
11881
+ raw,
11882
+ href,
11883
+ title,
11884
+ text,
11885
+ tokens: lexer.inlineTokens(text)
11886
+ };
11887
+ lexer.state.inLink = false;
11888
+ return token;
11889
+ }
11890
+ return {
11891
+ type: 'image',
11892
+ raw,
11893
+ href,
11894
+ title,
11895
+ text: escape$1(text)
11896
+ };
11897
+ }
11898
+ function indentCodeCompensation(raw, text) {
11899
+ const matchIndentToCode = raw.match(/^(\s+)(?:```)/);
11900
+ if (matchIndentToCode === null) {
11901
+ return text;
11902
+ }
11903
+ const indentToCode = matchIndentToCode[1];
11904
+ return text.split('\n').map(node => {
11905
+ const matchIndentInNode = node.match(/^\s+/);
11906
+ if (matchIndentInNode === null) {
11907
+ return node;
11908
+ }
11909
+ const [indentInNode] = matchIndentInNode;
11910
+ if (indentInNode.length >= indentToCode.length) {
11911
+ return node.slice(indentToCode.length);
11912
+ }
11913
+ return node;
11914
+ }).join('\n');
11915
+ }
11916
+ /**
11917
+ * Tokenizer
11918
+ */
11919
+ class _Tokenizer {
11920
+ options;
11921
+ rules; // set by the lexer
11922
+ lexer; // set by the lexer
11923
+ constructor(options) {
11924
+ this.options = options || _defaults;
11925
+ }
11926
+ space(src) {
11927
+ const cap = this.rules.block.newline.exec(src);
11928
+ if (cap && cap[0].length > 0) {
11929
+ return {
11930
+ type: 'space',
11931
+ raw: cap[0]
11710
11932
  };
11711
- // list 存在说明是重新生成
11712
- if (!list && !commonKey) {
11713
- this.messageData.push({
11714
- type: 'user',
11715
- message: this.keyWord.replace(/\n/g, '<br>')
11716
- });
11717
- setTimeout(() => this.messageData.push({
11718
- type: 'robot',
11719
- message: '',
11720
- zan: false,
11721
- cai: false,
11722
- stop: false,
11723
- finish: false,
11724
- sending: true,
11725
- links: [],
11726
- reAnswerCount: 0
11727
- }));
11933
+ }
11934
+ }
11935
+ code(src) {
11936
+ const cap = this.rules.block.code.exec(src);
11937
+ if (cap) {
11938
+ const text = cap[0].replace(/^(?: {1,4}| {0,3}\t)/gm, '');
11939
+ return {
11940
+ type: 'code',
11941
+ raw: cap[0],
11942
+ codeBlockStyle: 'indented',
11943
+ text: !this.options.pedantic ? rtrim(text, '\n') : text
11944
+ };
11945
+ }
11946
+ }
11947
+ fences(src) {
11948
+ const cap = this.rules.block.fences.exec(src);
11949
+ if (cap) {
11950
+ const raw = cap[0];
11951
+ const text = indentCodeCompensation(raw, cap[3] || '');
11952
+ return {
11953
+ type: 'code',
11954
+ raw,
11955
+ lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, '$1') : cap[2],
11956
+ text
11957
+ };
11958
+ }
11959
+ }
11960
+ heading(src) {
11961
+ const cap = this.rules.block.heading.exec(src);
11962
+ if (cap) {
11963
+ let text = cap[2].trim();
11964
+ // remove trailing #s
11965
+ if (/#$/.test(text)) {
11966
+ const trimmed = rtrim(text, '#');
11967
+ if (this.options.pedantic) {
11968
+ text = trimmed.trim();
11969
+ } else if (!trimmed || / $/.test(trimmed)) {
11970
+ // CommonMark requires space before trailing #s
11971
+ text = trimmed.trim();
11972
+ }
11728
11973
  }
11729
- await sendMessageEventSource(params, signal, res => {
11730
- this.makeMessageLine(res, list);
11731
- });
11732
- },
11733
- makeMessageLine(res, list) {
11734
- const {
11735
- content,
11736
- status,
11737
- chatId,
11738
- msgId,
11739
- parentMsgId,
11740
- reference,
11741
- commonKey
11742
- } = JSON.parse(res.data);
11743
- let index = list ? list.index : this.messageData.length - 1;
11744
- const currentList = this.messageData[index];
11745
- // 结束标识
11746
- if (status === 2 || status === 1) {
11747
- if (commonKey) {
11748
- currentList.sending = true;
11749
- this.postMessage(list, commonKey, parentMsgId);
11750
- return;
11974
+ return {
11975
+ type: 'heading',
11976
+ raw: cap[0],
11977
+ depth: cap[1].length,
11978
+ text,
11979
+ tokens: this.lexer.inline(text)
11980
+ };
11981
+ }
11982
+ }
11983
+ hr(src) {
11984
+ const cap = this.rules.block.hr.exec(src);
11985
+ if (cap) {
11986
+ return {
11987
+ type: 'hr',
11988
+ raw: rtrim(cap[0], '\n')
11989
+ };
11990
+ }
11991
+ }
11992
+ blockquote(src) {
11993
+ const cap = this.rules.block.blockquote.exec(src);
11994
+ if (cap) {
11995
+ let lines = rtrim(cap[0], '\n').split('\n');
11996
+ let raw = '';
11997
+ let text = '';
11998
+ const tokens = [];
11999
+ while (lines.length > 0) {
12000
+ let inBlockquote = false;
12001
+ const currentLines = [];
12002
+ let i;
12003
+ for (i = 0; i < lines.length; i++) {
12004
+ // get lines up to a continuation
12005
+ if (/^ {0,3}>/.test(lines[i])) {
12006
+ currentLines.push(lines[i]);
12007
+ inBlockquote = true;
12008
+ } else if (!inBlockquote) {
12009
+ currentLines.push(lines[i]);
12010
+ } else {
12011
+ break;
12012
+ }
11751
12013
  }
11752
- currentList.finish = true;
11753
- if (reference) {
11754
- currentList.links = JSON.parse(reference);
12014
+ lines = lines.slice(i);
12015
+ const currentRaw = currentLines.join('\n');
12016
+ const currentText = currentRaw
12017
+ // precede setext continuation with 4 spaces so it isn't a setext
12018
+ .replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g, '\n $1').replace(/^ {0,3}>[ \t]?/gm, '');
12019
+ raw = raw ? `${raw}\n${currentRaw}` : currentRaw;
12020
+ text = text ? `${text}\n${currentText}` : currentText;
12021
+ // parse blockquote lines as top level tokens
12022
+ // merge paragraphs if this is a continuation
12023
+ const top = this.lexer.state.top;
12024
+ this.lexer.state.top = true;
12025
+ this.lexer.blockTokens(currentText, tokens, true);
12026
+ this.lexer.state.top = top;
12027
+ // if there is no continuation then we are done
12028
+ if (lines.length === 0) {
12029
+ break;
12030
+ }
12031
+ const lastToken = tokens[tokens.length - 1];
12032
+ if (lastToken?.type === 'code') {
12033
+ // blockquote continuation cannot be preceded by a code block
12034
+ break;
12035
+ } else if (lastToken?.type === 'blockquote') {
12036
+ // include continuation in nested blockquote
12037
+ const oldToken = lastToken;
12038
+ const newText = oldToken.raw + '\n' + lines.join('\n');
12039
+ const newToken = this.blockquote(newText);
12040
+ tokens[tokens.length - 1] = newToken;
12041
+ raw = raw.substring(0, raw.length - oldToken.raw.length) + newToken.raw;
12042
+ text = text.substring(0, text.length - oldToken.text.length) + newToken.text;
12043
+ break;
12044
+ } else if (lastToken?.type === 'list') {
12045
+ // include continuation in nested list
12046
+ const oldToken = lastToken;
12047
+ const newText = oldToken.raw + '\n' + lines.join('\n');
12048
+ const newToken = this.list(newText);
12049
+ tokens[tokens.length - 1] = newToken;
12050
+ raw = raw.substring(0, raw.length - lastToken.raw.length) + newToken.raw;
12051
+ text = text.substring(0, text.length - oldToken.raw.length) + newToken.raw;
12052
+ lines = newText.substring(tokens[tokens.length - 1].raw.length).split('\n');
12053
+ continue;
11755
12054
  }
11756
- this.cacheKeyWord = '';
11757
- this.$emit('on-message-finish', chatId);
11758
- return;
11759
- }
11760
- currentList.message += content.replace(/\n/g, '<br>');
11761
- currentList.msgId = msgId;
11762
- currentList.parentMsgId = parentMsgId;
11763
- currentList.chatId = chatId;
11764
- setTimeout(() => {
11765
- if (!list) this.scrollToBottom();
11766
- }, 100);
11767
- // 防止出现调用基础模型前导致停止回答id错误
11768
- setTimeout(() => currentList.sending = false, 500);
11769
- },
11770
- onStopChat(list) {
11771
- this.$emit('on-message-finish', list.chatId);
11772
- },
11773
- async clearChat() {
11774
- if (this.messageData.length < 1) {
11775
- this.$message.warning('当前对话为最新对话');
11776
- return;
11777
12055
  }
11778
- await chartClear(this.chatId);
11779
- this.messageData = [];
12056
+ return {
12057
+ type: 'blockquote',
12058
+ raw,
12059
+ tokens,
12060
+ text
12061
+ };
12062
+ }
12063
+ }
12064
+ list(src) {
12065
+ let cap = this.rules.block.list.exec(src);
12066
+ if (cap) {
12067
+ let bull = cap[1].trim();
12068
+ const isordered = bull.length > 1;
12069
+ const list = {
12070
+ type: 'list',
12071
+ raw: '',
12072
+ ordered: isordered,
12073
+ start: isordered ? +bull.slice(0, -1) : '',
12074
+ loose: false,
12075
+ items: []
12076
+ };
12077
+ bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
12078
+ if (this.options.pedantic) {
12079
+ bull = isordered ? bull : '[*+-]';
12080
+ }
12081
+ // Get next list item
12082
+ const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
12083
+ let endsWithBlankLine = false;
12084
+ // Check if current bullet point can start a new List Item
12085
+ while (src) {
12086
+ let endEarly = false;
12087
+ let raw = '';
12088
+ let itemContents = '';
12089
+ if (!(cap = itemRegex.exec(src))) {
12090
+ break;
12091
+ }
12092
+ if (this.rules.block.hr.test(src)) {
12093
+ // End list if bullet was actually HR (possibly move into itemRegex?)
12094
+ break;
12095
+ }
12096
+ raw = cap[0];
12097
+ src = src.substring(raw.length);
12098
+ let line = cap[2].split('\n', 1)[0].replace(/^\t+/, t => ' '.repeat(3 * t.length));
12099
+ let nextLine = src.split('\n', 1)[0];
12100
+ let blankLine = !line.trim();
12101
+ let indent = 0;
12102
+ if (this.options.pedantic) {
12103
+ indent = 2;
12104
+ itemContents = line.trimStart();
12105
+ } else if (blankLine) {
12106
+ indent = cap[1].length + 1;
12107
+ } else {
12108
+ indent = cap[2].search(/[^ ]/); // Find first non-space char
12109
+ indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
12110
+ itemContents = line.slice(indent);
12111
+ indent += cap[1].length;
12112
+ }
12113
+ if (blankLine && /^[ \t]*$/.test(nextLine)) {
12114
+ // Items begin with at most one blank line
12115
+ raw += nextLine + '\n';
12116
+ src = src.substring(nextLine.length + 1);
12117
+ endEarly = true;
12118
+ }
12119
+ if (!endEarly) {
12120
+ const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
12121
+ const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
12122
+ const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
12123
+ const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
12124
+ const htmlBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}<[a-z].*>`, 'i');
12125
+ // Check if following lines should be included in List Item
12126
+ while (src) {
12127
+ const rawLine = src.split('\n', 1)[0];
12128
+ let nextLineWithoutTabs;
12129
+ nextLine = rawLine;
12130
+ // Re-align to follow commonmark nesting rules
12131
+ if (this.options.pedantic) {
12132
+ nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
12133
+ nextLineWithoutTabs = nextLine;
12134
+ } else {
12135
+ nextLineWithoutTabs = nextLine.replace(/\t/g, ' ');
12136
+ }
12137
+ // End list item if found code fences
12138
+ if (fencesBeginRegex.test(nextLine)) {
12139
+ break;
12140
+ }
12141
+ // End list item if found start of new heading
12142
+ if (headingBeginRegex.test(nextLine)) {
12143
+ break;
12144
+ }
12145
+ // End list item if found start of html block
12146
+ if (htmlBeginRegex.test(nextLine)) {
12147
+ break;
12148
+ }
12149
+ // End list item if found start of new bullet
12150
+ if (nextBulletRegex.test(nextLine)) {
12151
+ break;
12152
+ }
12153
+ // Horizontal rule found
12154
+ if (hrRegex.test(nextLine)) {
12155
+ break;
12156
+ }
12157
+ if (nextLineWithoutTabs.search(/[^ ]/) >= indent || !nextLine.trim()) {
12158
+ // Dedent if possible
12159
+ itemContents += '\n' + nextLineWithoutTabs.slice(indent);
12160
+ } else {
12161
+ // not enough indentation
12162
+ if (blankLine) {
12163
+ break;
12164
+ }
12165
+ // paragraph continuation unless last line was a different block level element
12166
+ if (line.replace(/\t/g, ' ').search(/[^ ]/) >= 4) {
12167
+ // indented code block
12168
+ break;
12169
+ }
12170
+ if (fencesBeginRegex.test(line)) {
12171
+ break;
12172
+ }
12173
+ if (headingBeginRegex.test(line)) {
12174
+ break;
12175
+ }
12176
+ if (hrRegex.test(line)) {
12177
+ break;
12178
+ }
12179
+ itemContents += '\n' + nextLine;
12180
+ }
12181
+ if (!blankLine && !nextLine.trim()) {
12182
+ // Check if current line is blank
12183
+ blankLine = true;
12184
+ }
12185
+ raw += rawLine + '\n';
12186
+ src = src.substring(rawLine.length + 1);
12187
+ line = nextLineWithoutTabs.slice(indent);
12188
+ }
12189
+ }
12190
+ if (!list.loose) {
12191
+ // If the previous item ended with a blank line, the list is loose
12192
+ if (endsWithBlankLine) {
12193
+ list.loose = true;
12194
+ } else if (/\n[ \t]*\n[ \t]*$/.test(raw)) {
12195
+ endsWithBlankLine = true;
12196
+ }
12197
+ }
12198
+ let istask = null;
12199
+ let ischecked;
12200
+ // Check for task list items
12201
+ if (this.options.gfm) {
12202
+ istask = /^\[[ xX]\] /.exec(itemContents);
12203
+ if (istask) {
12204
+ ischecked = istask[0] !== '[ ] ';
12205
+ itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
12206
+ }
12207
+ }
12208
+ list.items.push({
12209
+ type: 'list_item',
12210
+ raw,
12211
+ task: !!istask,
12212
+ checked: ischecked,
12213
+ loose: false,
12214
+ text: itemContents,
12215
+ tokens: []
12216
+ });
12217
+ list.raw += raw;
12218
+ }
12219
+ // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
12220
+ list.items[list.items.length - 1].raw = list.items[list.items.length - 1].raw.trimEnd();
12221
+ list.items[list.items.length - 1].text = list.items[list.items.length - 1].text.trimEnd();
12222
+ list.raw = list.raw.trimEnd();
12223
+ // Item child tokens handled here at end because we needed to have the final item to trim it first
12224
+ for (let i = 0; i < list.items.length; i++) {
12225
+ this.lexer.state.top = false;
12226
+ list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
12227
+ if (!list.loose) {
12228
+ // Check if list should be loose
12229
+ const spacers = list.items[i].tokens.filter(t => t.type === 'space');
12230
+ const hasMultipleLineBreaks = spacers.length > 0 && spacers.some(t => /\n.*\n/.test(t.raw));
12231
+ list.loose = hasMultipleLineBreaks;
12232
+ }
12233
+ }
12234
+ // Set all items to loose if list is loose
12235
+ if (list.loose) {
12236
+ for (let i = 0; i < list.items.length; i++) {
12237
+ list.items[i].loose = true;
12238
+ }
12239
+ }
12240
+ return list;
12241
+ }
12242
+ }
12243
+ html(src) {
12244
+ const cap = this.rules.block.html.exec(src);
12245
+ if (cap) {
12246
+ const token = {
12247
+ type: 'html',
12248
+ block: true,
12249
+ raw: cap[0],
12250
+ pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
12251
+ text: cap[0]
12252
+ };
12253
+ return token;
12254
+ }
12255
+ }
12256
+ def(src) {
12257
+ const cap = this.rules.block.def.exec(src);
12258
+ if (cap) {
12259
+ const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
12260
+ const href = cap[2] ? cap[2].replace(/^<(.*)>$/, '$1').replace(this.rules.inline.anyPunctuation, '$1') : '';
12261
+ const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline.anyPunctuation, '$1') : cap[3];
12262
+ return {
12263
+ type: 'def',
12264
+ tag,
12265
+ raw: cap[0],
12266
+ href,
12267
+ title
12268
+ };
12269
+ }
12270
+ }
12271
+ table(src) {
12272
+ const cap = this.rules.block.table.exec(src);
12273
+ if (!cap) {
12274
+ return;
12275
+ }
12276
+ if (!/[:|]/.test(cap[2])) {
12277
+ // delimiter row must have a pipe (|) or colon (:) otherwise it is a setext heading
12278
+ return;
12279
+ }
12280
+ const headers = splitCells(cap[1]);
12281
+ const aligns = cap[2].replace(/^\||\| *$/g, '').split('|');
12282
+ const rows = cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : [];
12283
+ const item = {
12284
+ type: 'table',
12285
+ raw: cap[0],
12286
+ header: [],
12287
+ align: [],
12288
+ rows: []
12289
+ };
12290
+ if (headers.length !== aligns.length) {
12291
+ // header and align columns must be equal, rows can be different.
12292
+ return;
12293
+ }
12294
+ for (const align of aligns) {
12295
+ if (/^ *-+: *$/.test(align)) {
12296
+ item.align.push('right');
12297
+ } else if (/^ *:-+: *$/.test(align)) {
12298
+ item.align.push('center');
12299
+ } else if (/^ *:-+ *$/.test(align)) {
12300
+ item.align.push('left');
12301
+ } else {
12302
+ item.align.push(null);
12303
+ }
12304
+ }
12305
+ for (let i = 0; i < headers.length; i++) {
12306
+ item.header.push({
12307
+ text: headers[i],
12308
+ tokens: this.lexer.inline(headers[i]),
12309
+ header: true,
12310
+ align: item.align[i]
12311
+ });
12312
+ }
12313
+ for (const row of rows) {
12314
+ item.rows.push(splitCells(row, item.header.length).map((cell, i) => {
12315
+ return {
12316
+ text: cell,
12317
+ tokens: this.lexer.inline(cell),
12318
+ header: false,
12319
+ align: item.align[i]
12320
+ };
12321
+ }));
12322
+ }
12323
+ return item;
12324
+ }
12325
+ lheading(src) {
12326
+ const cap = this.rules.block.lheading.exec(src);
12327
+ if (cap) {
12328
+ return {
12329
+ type: 'heading',
12330
+ raw: cap[0],
12331
+ depth: cap[2].charAt(0) === '=' ? 1 : 2,
12332
+ text: cap[1],
12333
+ tokens: this.lexer.inline(cap[1])
12334
+ };
12335
+ }
12336
+ }
12337
+ paragraph(src) {
12338
+ const cap = this.rules.block.paragraph.exec(src);
12339
+ if (cap) {
12340
+ const text = cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1];
12341
+ return {
12342
+ type: 'paragraph',
12343
+ raw: cap[0],
12344
+ text,
12345
+ tokens: this.lexer.inline(text)
12346
+ };
12347
+ }
12348
+ }
12349
+ text(src) {
12350
+ const cap = this.rules.block.text.exec(src);
12351
+ if (cap) {
12352
+ return {
12353
+ type: 'text',
12354
+ raw: cap[0],
12355
+ text: cap[0],
12356
+ tokens: this.lexer.inline(cap[0])
12357
+ };
12358
+ }
12359
+ }
12360
+ escape(src) {
12361
+ const cap = this.rules.inline.escape.exec(src);
12362
+ if (cap) {
12363
+ return {
12364
+ type: 'escape',
12365
+ raw: cap[0],
12366
+ text: escape$1(cap[1])
12367
+ };
12368
+ }
12369
+ }
12370
+ tag(src) {
12371
+ const cap = this.rules.inline.tag.exec(src);
12372
+ if (cap) {
12373
+ if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
12374
+ this.lexer.state.inLink = true;
12375
+ } else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
12376
+ this.lexer.state.inLink = false;
12377
+ }
12378
+ if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
12379
+ this.lexer.state.inRawBlock = true;
12380
+ } else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
12381
+ this.lexer.state.inRawBlock = false;
12382
+ }
12383
+ return {
12384
+ type: 'html',
12385
+ raw: cap[0],
12386
+ inLink: this.lexer.state.inLink,
12387
+ inRawBlock: this.lexer.state.inRawBlock,
12388
+ block: false,
12389
+ text: cap[0]
12390
+ };
12391
+ }
12392
+ }
12393
+ link(src) {
12394
+ const cap = this.rules.inline.link.exec(src);
12395
+ if (cap) {
12396
+ const trimmedUrl = cap[2].trim();
12397
+ if (!this.options.pedantic && /^</.test(trimmedUrl)) {
12398
+ // commonmark requires matching angle brackets
12399
+ if (!/>$/.test(trimmedUrl)) {
12400
+ return;
12401
+ }
12402
+ // ending angle bracket cannot be escaped
12403
+ const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
12404
+ if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
12405
+ return;
12406
+ }
12407
+ } else {
12408
+ // find closing parenthesis
12409
+ const lastParenIndex = findClosingBracket(cap[2], '()');
12410
+ if (lastParenIndex > -1) {
12411
+ const start = cap[0].indexOf('!') === 0 ? 5 : 4;
12412
+ const linkLen = start + cap[1].length + lastParenIndex;
12413
+ cap[2] = cap[2].substring(0, lastParenIndex);
12414
+ cap[0] = cap[0].substring(0, linkLen).trim();
12415
+ cap[3] = '';
12416
+ }
12417
+ }
12418
+ let href = cap[2];
12419
+ let title = '';
12420
+ if (this.options.pedantic) {
12421
+ // split pedantic href and title
12422
+ const link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
12423
+ if (link) {
12424
+ href = link[1];
12425
+ title = link[3];
12426
+ }
12427
+ } else {
12428
+ title = cap[3] ? cap[3].slice(1, -1) : '';
12429
+ }
12430
+ href = href.trim();
12431
+ if (/^</.test(href)) {
12432
+ if (this.options.pedantic && !/>$/.test(trimmedUrl)) {
12433
+ // pedantic allows starting angle bracket without ending angle bracket
12434
+ href = href.slice(1);
12435
+ } else {
12436
+ href = href.slice(1, -1);
12437
+ }
12438
+ }
12439
+ return outputLink(cap, {
12440
+ href: href ? href.replace(this.rules.inline.anyPunctuation, '$1') : href,
12441
+ title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title
12442
+ }, cap[0], this.lexer);
12443
+ }
12444
+ }
12445
+ reflink(src, links) {
12446
+ let cap;
12447
+ if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
12448
+ const linkString = (cap[2] || cap[1]).replace(/\s+/g, ' ');
12449
+ const link = links[linkString.toLowerCase()];
12450
+ if (!link) {
12451
+ const text = cap[0].charAt(0);
12452
+ return {
12453
+ type: 'text',
12454
+ raw: text,
12455
+ text
12456
+ };
12457
+ }
12458
+ return outputLink(cap, link, cap[0], this.lexer);
12459
+ }
12460
+ }
12461
+ emStrong(src, maskedSrc, prevChar = '') {
12462
+ let match = this.rules.inline.emStrongLDelim.exec(src);
12463
+ if (!match) return;
12464
+ // _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
12465
+ if (match[3] && prevChar.match(/[\p{L}\p{N}]/u)) return;
12466
+ const nextChar = match[1] || match[2] || '';
12467
+ if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
12468
+ // unicode Regex counts emoji as 1 char; spread into array for proper count (used multiple times below)
12469
+ const lLength = [...match[0]].length - 1;
12470
+ let rDelim,
12471
+ rLength,
12472
+ delimTotal = lLength,
12473
+ midDelimTotal = 0;
12474
+ const endReg = match[0][0] === '*' ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
12475
+ endReg.lastIndex = 0;
12476
+ // Clip maskedSrc to same section of string as src (move to lexer?)
12477
+ maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
12478
+ while ((match = endReg.exec(maskedSrc)) != null) {
12479
+ rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
12480
+ if (!rDelim) continue; // skip single * in __abc*abc__
12481
+ rLength = [...rDelim].length;
12482
+ if (match[3] || match[4]) {
12483
+ // found another Left Delim
12484
+ delimTotal += rLength;
12485
+ continue;
12486
+ } else if (match[5] || match[6]) {
12487
+ // either Left or Right Delim
12488
+ if (lLength % 3 && !((lLength + rLength) % 3)) {
12489
+ midDelimTotal += rLength;
12490
+ continue; // CommonMark Emphasis Rules 9-10
12491
+ }
12492
+ }
12493
+ delimTotal -= rLength;
12494
+ if (delimTotal > 0) continue; // Haven't found enough closing delimiters
12495
+ // Remove extra characters. *a*** -> *a*
12496
+ rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
12497
+ // char length can be >1 for unicode characters;
12498
+ const lastCharLength = [...match[0]][0].length;
12499
+ const raw = src.slice(0, lLength + match.index + lastCharLength + rLength);
12500
+ // Create `em` if smallest delimiter has odd char count. *a***
12501
+ if (Math.min(lLength, rLength) % 2) {
12502
+ const text = raw.slice(1, -1);
12503
+ return {
12504
+ type: 'em',
12505
+ raw,
12506
+ text,
12507
+ tokens: this.lexer.inlineTokens(text)
12508
+ };
12509
+ }
12510
+ // Create 'strong' if smallest delimiter has even char count. **a***
12511
+ const text = raw.slice(2, -2);
12512
+ return {
12513
+ type: 'strong',
12514
+ raw,
12515
+ text,
12516
+ tokens: this.lexer.inlineTokens(text)
12517
+ };
12518
+ }
12519
+ }
12520
+ }
12521
+ codespan(src) {
12522
+ const cap = this.rules.inline.code.exec(src);
12523
+ if (cap) {
12524
+ let text = cap[2].replace(/\n/g, ' ');
12525
+ const hasNonSpaceChars = /[^ ]/.test(text);
12526
+ const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
12527
+ if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
12528
+ text = text.substring(1, text.length - 1);
12529
+ }
12530
+ text = escape$1(text, true);
12531
+ return {
12532
+ type: 'codespan',
12533
+ raw: cap[0],
12534
+ text
12535
+ };
12536
+ }
12537
+ }
12538
+ br(src) {
12539
+ const cap = this.rules.inline.br.exec(src);
12540
+ if (cap) {
12541
+ return {
12542
+ type: 'br',
12543
+ raw: cap[0]
12544
+ };
12545
+ }
12546
+ }
12547
+ del(src) {
12548
+ const cap = this.rules.inline.del.exec(src);
12549
+ if (cap) {
12550
+ return {
12551
+ type: 'del',
12552
+ raw: cap[0],
12553
+ text: cap[2],
12554
+ tokens: this.lexer.inlineTokens(cap[2])
12555
+ };
12556
+ }
12557
+ }
12558
+ autolink(src) {
12559
+ const cap = this.rules.inline.autolink.exec(src);
12560
+ if (cap) {
12561
+ let text, href;
12562
+ if (cap[2] === '@') {
12563
+ text = escape$1(cap[1]);
12564
+ href = 'mailto:' + text;
12565
+ } else {
12566
+ text = escape$1(cap[1]);
12567
+ href = text;
12568
+ }
12569
+ return {
12570
+ type: 'link',
12571
+ raw: cap[0],
12572
+ text,
12573
+ href,
12574
+ tokens: [{
12575
+ type: 'text',
12576
+ raw: text,
12577
+ text
12578
+ }]
12579
+ };
12580
+ }
12581
+ }
12582
+ url(src) {
12583
+ let cap;
12584
+ if (cap = this.rules.inline.url.exec(src)) {
12585
+ let text, href;
12586
+ if (cap[2] === '@') {
12587
+ text = escape$1(cap[0]);
12588
+ href = 'mailto:' + text;
12589
+ } else {
12590
+ // do extended autolink path validation
12591
+ let prevCapZero;
12592
+ do {
12593
+ prevCapZero = cap[0];
12594
+ cap[0] = this.rules.inline._backpedal.exec(cap[0])?.[0] ?? '';
12595
+ } while (prevCapZero !== cap[0]);
12596
+ text = escape$1(cap[0]);
12597
+ if (cap[1] === 'www.') {
12598
+ href = 'http://' + cap[0];
12599
+ } else {
12600
+ href = cap[0];
12601
+ }
12602
+ }
12603
+ return {
12604
+ type: 'link',
12605
+ raw: cap[0],
12606
+ text,
12607
+ href,
12608
+ tokens: [{
12609
+ type: 'text',
12610
+ raw: text,
12611
+ text
12612
+ }]
12613
+ };
12614
+ }
12615
+ }
12616
+ inlineText(src) {
12617
+ const cap = this.rules.inline.text.exec(src);
12618
+ if (cap) {
12619
+ let text;
12620
+ if (this.lexer.state.inRawBlock) {
12621
+ text = cap[0];
12622
+ } else {
12623
+ text = escape$1(cap[0]);
12624
+ }
12625
+ return {
12626
+ type: 'text',
12627
+ raw: cap[0],
12628
+ text
12629
+ };
12630
+ }
12631
+ }
12632
+ }
12633
+
12634
+ /**
12635
+ * Block-Level Grammar
12636
+ */
12637
+ const newline = /^(?:[ \t]*(?:\n|$))+/;
12638
+ const blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
12639
+ const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
12640
+ const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
12641
+ const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
12642
+ const bullet = /(?:[*+-]|\d{1,9}[.)])/;
12643
+ const lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g, bullet) // lists can interrupt
12644
+ .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
12645
+ .replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
12646
+ .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
12647
+ .replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
12648
+ .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
12649
+ .getRegex();
12650
+ const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
12651
+ const blockText = /^[^\n]+/;
12652
+ const _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
12653
+ const def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace('label', _blockLabel).replace('title', /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
12654
+ const list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, bullet).getRegex();
12655
+ const _tag = 'address|article|aside|base|basefont|blockquote|body|caption' + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption' + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe' + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option' + '|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title' + '|tr|track|ul';
12656
+ const _comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
12657
+ const html = edit('^ {0,3}(?:' // optional indentation
12658
+ + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
12659
+ + '|comment[^\\n]*(\\n+|$)' // (2)
12660
+ + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
12661
+ + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
12662
+ + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
12663
+ + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (6)
12664
+ + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) open tag
12665
+ + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) closing tag
12666
+ + ')', 'i').replace('comment', _comment).replace('tag', _tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
12667
+ const paragraph = edit(_paragraph).replace('hr', hr).replace('heading', ' {0,3}#{1,6}(?:\\s|$)').replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
12668
+ .replace('|table', '').replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
12669
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', _tag) // pars can be interrupted by type (6) html blocks
12670
+ .getRegex();
12671
+ const blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace('paragraph', paragraph).getRegex();
12672
+ /**
12673
+ * Normal Block Grammar
12674
+ */
12675
+ const blockNormal = {
12676
+ blockquote,
12677
+ code: blockCode,
12678
+ def,
12679
+ fences,
12680
+ heading,
12681
+ hr,
12682
+ html,
12683
+ lheading,
12684
+ list,
12685
+ newline,
12686
+ paragraph,
12687
+ table: noopTest,
12688
+ text: blockText
12689
+ };
12690
+ /**
12691
+ * GFM Block Grammar
12692
+ */
12693
+ const gfmTable = edit('^ *([^\\n ].*)\\n' // Header
12694
+ + ' {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)' // Align
12695
+ + '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)') // Cells
12696
+ .replace('hr', hr).replace('heading', ' {0,3}#{1,6}(?:\\s|$)').replace('blockquote', ' {0,3}>').replace('code', '(?: {4}| {0,3}\t)[^\\n]').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
12697
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', _tag) // tables can be interrupted by type (6) html blocks
12698
+ .getRegex();
12699
+ const blockGfm = {
12700
+ ...blockNormal,
12701
+ table: gfmTable,
12702
+ paragraph: edit(_paragraph).replace('hr', hr).replace('heading', ' {0,3}#{1,6}(?:\\s|$)').replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
12703
+ .replace('table', gfmTable) // interrupt paragraphs with table
12704
+ .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
12705
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', _tag) // pars can be interrupted by type (6) html blocks
12706
+ .getRegex()
12707
+ };
12708
+ /**
12709
+ * Pedantic grammar (original John Gruber's loose markdown specification)
12710
+ */
12711
+ const blockPedantic = {
12712
+ ...blockNormal,
12713
+ html: edit('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
12714
+ + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))').replace('comment', _comment).replace(/tag/g, '(?!(?:' + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub' + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)' + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b').getRegex(),
12715
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
12716
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
12717
+ fences: noopTest,
12718
+ // fences not supported
12719
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
12720
+ paragraph: edit(_paragraph).replace('hr', hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', lheading).replace('|table', '').replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').replace('|tag', '').getRegex()
12721
+ };
12722
+ /**
12723
+ * Inline-Level Grammar
12724
+ */
12725
+ const marked_esm_escape = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
12726
+ const inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
12727
+ const br = /^( {2,}|\\)\n(?!\s*$)/;
12728
+ const inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
12729
+ // list of unicode punctuation marks, plus any missing characters from CommonMark spec
12730
+ const _punctuation = '\\p{P}\\p{S}';
12731
+ const punctuation = edit(/^((?![*_])[\spunctuation])/, 'u').replace(/punctuation/g, _punctuation).getRegex();
12732
+ // sequences em should skip over [title](link), `code`, <html>
12733
+ const blockSkip = /\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g;
12734
+ const emStrongLDelim = edit(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/, 'u').replace(/punct/g, _punctuation).getRegex();
12735
+ const emStrongRDelimAst = edit('^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
12736
+ + '|[^*]+(?=[^*])' // Consume to delim
12737
+ + '|(?!\\*)[punct](\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
12738
+ + '|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)' // (2) a***#, a*** can only be a Right Delimiter
12739
+ + '|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])' // (3) #***a, ***a can only be Left Delimiter
12740
+ + '|[\\s](\\*+)(?!\\*)(?=[punct])' // (4) ***# can only be Left Delimiter
12741
+ + '|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])' // (5) #***# can be either Left or Right Delimiter
12742
+ + '|[^punct\\s](\\*+)(?=[^punct\\s])', 'gu') // (6) a***a can be either Left or Right Delimiter
12743
+ .replace(/punct/g, _punctuation).getRegex();
12744
+ // (6) Not allowed for _
12745
+ const emStrongRDelimUnd = edit('^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
12746
+ + '|[^_]+(?=[^_])' // Consume to delim
12747
+ + '|(?!_)[punct](_+)(?=[\\s]|$)' // (1) #___ can only be a Right Delimiter
12748
+ + '|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)' // (2) a___#, a___ can only be a Right Delimiter
12749
+ + '|(?!_)[punct\\s](_+)(?=[^punct\\s])' // (3) #___a, ___a can only be Left Delimiter
12750
+ + '|[\\s](_+)(?!_)(?=[punct])' // (4) ___# can only be Left Delimiter
12751
+ + '|(?!_)[punct](_+)(?!_)(?=[punct])', 'gu') // (5) #___# can be either Left or Right Delimiter
12752
+ .replace(/punct/g, _punctuation).getRegex();
12753
+ const anyPunctuation = edit(/\\([punct])/, 'gu').replace(/punct/g, _punctuation).getRegex();
12754
+ const autolink = edit(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace('scheme', /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace('email', /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
12755
+ const _inlineComment = edit(_comment).replace('(?:-->|$)', '-->').getRegex();
12756
+ const tag = edit('^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
12757
+ + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
12758
+ + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
12759
+ + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
12760
+ + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>') // CDATA section
12761
+ .replace('comment', _inlineComment).replace('attribute', /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
12762
+ const _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
12763
+ const marked_esm_link = edit(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace('label', _inlineLabel).replace('href', /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace('title', /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
12764
+ const reflink = edit(/^!?\[(label)\]\[(ref)\]/).replace('label', _inlineLabel).replace('ref', _blockLabel).getRegex();
12765
+ const nolink = edit(/^!?\[(ref)\](?:\[\])?/).replace('ref', _blockLabel).getRegex();
12766
+ const reflinkSearch = edit('reflink|nolink(?!\\()', 'g').replace('reflink', reflink).replace('nolink', nolink).getRegex();
12767
+ /**
12768
+ * Normal Inline Grammar
12769
+ */
12770
+ const inlineNormal = {
12771
+ _backpedal: noopTest,
12772
+ // only used for GFM url
12773
+ anyPunctuation,
12774
+ autolink,
12775
+ blockSkip,
12776
+ br,
12777
+ code: inlineCode,
12778
+ del: noopTest,
12779
+ emStrongLDelim,
12780
+ emStrongRDelimAst,
12781
+ emStrongRDelimUnd,
12782
+ escape: marked_esm_escape,
12783
+ link: marked_esm_link,
12784
+ nolink,
12785
+ punctuation,
12786
+ reflink,
12787
+ reflinkSearch,
12788
+ tag,
12789
+ text: inlineText,
12790
+ url: noopTest
12791
+ };
12792
+ /**
12793
+ * Pedantic Inline Grammar
12794
+ */
12795
+ const inlinePedantic = {
12796
+ ...inlineNormal,
12797
+ link: edit(/^!?\[(label)\]\((.*?)\)/).replace('label', _inlineLabel).getRegex(),
12798
+ reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', _inlineLabel).getRegex()
12799
+ };
12800
+ /**
12801
+ * GFM Inline Grammar
12802
+ */
12803
+ const inlineGfm = {
12804
+ ...inlineNormal,
12805
+ escape: edit(marked_esm_escape).replace('])', '~|])').getRegex(),
12806
+ url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, 'i').replace('email', /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
12807
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
12808
+ del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
12809
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
12810
+ };
12811
+ /**
12812
+ * GFM + Line Breaks Inline Grammar
12813
+ */
12814
+ const inlineBreaks = {
12815
+ ...inlineGfm,
12816
+ br: edit(br).replace('{2,}', '*').getRegex(),
12817
+ text: edit(inlineGfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
12818
+ };
12819
+ /**
12820
+ * exports
12821
+ */
12822
+ const block = {
12823
+ normal: blockNormal,
12824
+ gfm: blockGfm,
12825
+ pedantic: blockPedantic
12826
+ };
12827
+ const inline = {
12828
+ normal: inlineNormal,
12829
+ gfm: inlineGfm,
12830
+ breaks: inlineBreaks,
12831
+ pedantic: inlinePedantic
12832
+ };
12833
+
12834
+ /**
12835
+ * Block Lexer
12836
+ */
12837
+ class _Lexer {
12838
+ tokens;
12839
+ options;
12840
+ state;
12841
+ tokenizer;
12842
+ inlineQueue;
12843
+ constructor(options) {
12844
+ // TokenList cannot be created in one go
12845
+ this.tokens = [];
12846
+ this.tokens.links = Object.create(null);
12847
+ this.options = options || _defaults;
12848
+ this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
12849
+ this.tokenizer = this.options.tokenizer;
12850
+ this.tokenizer.options = this.options;
12851
+ this.tokenizer.lexer = this;
12852
+ this.inlineQueue = [];
12853
+ this.state = {
12854
+ inLink: false,
12855
+ inRawBlock: false,
12856
+ top: true
12857
+ };
12858
+ const rules = {
12859
+ block: block.normal,
12860
+ inline: inline.normal
12861
+ };
12862
+ if (this.options.pedantic) {
12863
+ rules.block = block.pedantic;
12864
+ rules.inline = inline.pedantic;
12865
+ } else if (this.options.gfm) {
12866
+ rules.block = block.gfm;
12867
+ if (this.options.breaks) {
12868
+ rules.inline = inline.breaks;
12869
+ } else {
12870
+ rules.inline = inline.gfm;
12871
+ }
12872
+ }
12873
+ this.tokenizer.rules = rules;
12874
+ }
12875
+ /**
12876
+ * Expose Rules
12877
+ */
12878
+ static get rules() {
12879
+ return {
12880
+ block,
12881
+ inline
12882
+ };
12883
+ }
12884
+ /**
12885
+ * Static Lex Method
12886
+ */
12887
+ static lex(src, options) {
12888
+ const lexer = new _Lexer(options);
12889
+ return lexer.lex(src);
12890
+ }
12891
+ /**
12892
+ * Static Lex Inline Method
12893
+ */
12894
+ static lexInline(src, options) {
12895
+ const lexer = new _Lexer(options);
12896
+ return lexer.inlineTokens(src);
12897
+ }
12898
+ /**
12899
+ * Preprocessing
12900
+ */
12901
+ lex(src) {
12902
+ src = src.replace(/\r\n|\r/g, '\n');
12903
+ this.blockTokens(src, this.tokens);
12904
+ for (let i = 0; i < this.inlineQueue.length; i++) {
12905
+ const next = this.inlineQueue[i];
12906
+ this.inlineTokens(next.src, next.tokens);
12907
+ }
12908
+ this.inlineQueue = [];
12909
+ return this.tokens;
12910
+ }
12911
+ blockTokens(src, tokens = [], lastParagraphClipped = false) {
12912
+ if (this.options.pedantic) {
12913
+ src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
12914
+ }
12915
+ let token;
12916
+ let lastToken;
12917
+ let cutSrc;
12918
+ while (src) {
12919
+ if (this.options.extensions && this.options.extensions.block && this.options.extensions.block.some(extTokenizer => {
12920
+ if (token = extTokenizer.call({
12921
+ lexer: this
12922
+ }, src, tokens)) {
12923
+ src = src.substring(token.raw.length);
12924
+ tokens.push(token);
12925
+ return true;
12926
+ }
12927
+ return false;
12928
+ })) {
12929
+ continue;
12930
+ }
12931
+ // newline
12932
+ if (token = this.tokenizer.space(src)) {
12933
+ src = src.substring(token.raw.length);
12934
+ if (token.raw.length === 1 && tokens.length > 0) {
12935
+ // if there's a single \n as a spacer, it's terminating the last line,
12936
+ // so move it there so that we don't get unnecessary paragraph tags
12937
+ tokens[tokens.length - 1].raw += '\n';
12938
+ } else {
12939
+ tokens.push(token);
12940
+ }
12941
+ continue;
12942
+ }
12943
+ // code
12944
+ if (token = this.tokenizer.code(src)) {
12945
+ src = src.substring(token.raw.length);
12946
+ lastToken = tokens[tokens.length - 1];
12947
+ // An indented code block cannot interrupt a paragraph.
12948
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
12949
+ lastToken.raw += '\n' + token.raw;
12950
+ lastToken.text += '\n' + token.text;
12951
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
12952
+ } else {
12953
+ tokens.push(token);
12954
+ }
12955
+ continue;
12956
+ }
12957
+ // fences
12958
+ if (token = this.tokenizer.fences(src)) {
12959
+ src = src.substring(token.raw.length);
12960
+ tokens.push(token);
12961
+ continue;
12962
+ }
12963
+ // heading
12964
+ if (token = this.tokenizer.heading(src)) {
12965
+ src = src.substring(token.raw.length);
12966
+ tokens.push(token);
12967
+ continue;
12968
+ }
12969
+ // hr
12970
+ if (token = this.tokenizer.hr(src)) {
12971
+ src = src.substring(token.raw.length);
12972
+ tokens.push(token);
12973
+ continue;
12974
+ }
12975
+ // blockquote
12976
+ if (token = this.tokenizer.blockquote(src)) {
12977
+ src = src.substring(token.raw.length);
12978
+ tokens.push(token);
12979
+ continue;
12980
+ }
12981
+ // list
12982
+ if (token = this.tokenizer.list(src)) {
12983
+ src = src.substring(token.raw.length);
12984
+ tokens.push(token);
12985
+ continue;
12986
+ }
12987
+ // html
12988
+ if (token = this.tokenizer.html(src)) {
12989
+ src = src.substring(token.raw.length);
12990
+ tokens.push(token);
12991
+ continue;
12992
+ }
12993
+ // def
12994
+ if (token = this.tokenizer.def(src)) {
12995
+ src = src.substring(token.raw.length);
12996
+ lastToken = tokens[tokens.length - 1];
12997
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
12998
+ lastToken.raw += '\n' + token.raw;
12999
+ lastToken.text += '\n' + token.raw;
13000
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
13001
+ } else if (!this.tokens.links[token.tag]) {
13002
+ this.tokens.links[token.tag] = {
13003
+ href: token.href,
13004
+ title: token.title
13005
+ };
13006
+ }
13007
+ continue;
13008
+ }
13009
+ // table (gfm)
13010
+ if (token = this.tokenizer.table(src)) {
13011
+ src = src.substring(token.raw.length);
13012
+ tokens.push(token);
13013
+ continue;
13014
+ }
13015
+ // lheading
13016
+ if (token = this.tokenizer.lheading(src)) {
13017
+ src = src.substring(token.raw.length);
13018
+ tokens.push(token);
13019
+ continue;
13020
+ }
13021
+ // top-level paragraph
13022
+ // prevent paragraph consuming extensions by clipping 'src' to extension start
13023
+ cutSrc = src;
13024
+ if (this.options.extensions && this.options.extensions.startBlock) {
13025
+ let startIndex = Infinity;
13026
+ const tempSrc = src.slice(1);
13027
+ let tempStart;
13028
+ this.options.extensions.startBlock.forEach(getStartIndex => {
13029
+ tempStart = getStartIndex.call({
13030
+ lexer: this
13031
+ }, tempSrc);
13032
+ if (typeof tempStart === 'number' && tempStart >= 0) {
13033
+ startIndex = Math.min(startIndex, tempStart);
13034
+ }
13035
+ });
13036
+ if (startIndex < Infinity && startIndex >= 0) {
13037
+ cutSrc = src.substring(0, startIndex + 1);
13038
+ }
13039
+ }
13040
+ if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
13041
+ lastToken = tokens[tokens.length - 1];
13042
+ if (lastParagraphClipped && lastToken?.type === 'paragraph') {
13043
+ lastToken.raw += '\n' + token.raw;
13044
+ lastToken.text += '\n' + token.text;
13045
+ this.inlineQueue.pop();
13046
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
13047
+ } else {
13048
+ tokens.push(token);
13049
+ }
13050
+ lastParagraphClipped = cutSrc.length !== src.length;
13051
+ src = src.substring(token.raw.length);
13052
+ continue;
13053
+ }
13054
+ // text
13055
+ if (token = this.tokenizer.text(src)) {
13056
+ src = src.substring(token.raw.length);
13057
+ lastToken = tokens[tokens.length - 1];
13058
+ if (lastToken && lastToken.type === 'text') {
13059
+ lastToken.raw += '\n' + token.raw;
13060
+ lastToken.text += '\n' + token.text;
13061
+ this.inlineQueue.pop();
13062
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
13063
+ } else {
13064
+ tokens.push(token);
13065
+ }
13066
+ continue;
13067
+ }
13068
+ if (src) {
13069
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
13070
+ if (this.options.silent) {
13071
+ console.error(errMsg);
13072
+ break;
13073
+ } else {
13074
+ throw new Error(errMsg);
13075
+ }
13076
+ }
13077
+ }
13078
+ this.state.top = true;
13079
+ return tokens;
13080
+ }
13081
+ inline(src, tokens = []) {
13082
+ this.inlineQueue.push({
13083
+ src,
13084
+ tokens
13085
+ });
13086
+ return tokens;
13087
+ }
13088
+ /**
13089
+ * Lexing/Compiling
13090
+ */
13091
+ inlineTokens(src, tokens = []) {
13092
+ let token, lastToken, cutSrc;
13093
+ // String with links masked to avoid interference with em and strong
13094
+ let maskedSrc = src;
13095
+ let match;
13096
+ let keepPrevChar, prevChar;
13097
+ // Mask out reflinks
13098
+ if (this.tokens.links) {
13099
+ const links = Object.keys(this.tokens.links);
13100
+ if (links.length > 0) {
13101
+ while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
13102
+ if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
13103
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
13104
+ }
13105
+ }
13106
+ }
13107
+ }
13108
+ // Mask out other blocks
13109
+ while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
13110
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
13111
+ }
13112
+ // Mask out escaped characters
13113
+ while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
13114
+ maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
13115
+ }
13116
+ while (src) {
13117
+ if (!keepPrevChar) {
13118
+ prevChar = '';
13119
+ }
13120
+ keepPrevChar = false;
13121
+ // extensions
13122
+ if (this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some(extTokenizer => {
13123
+ if (token = extTokenizer.call({
13124
+ lexer: this
13125
+ }, src, tokens)) {
13126
+ src = src.substring(token.raw.length);
13127
+ tokens.push(token);
13128
+ return true;
13129
+ }
13130
+ return false;
13131
+ })) {
13132
+ continue;
13133
+ }
13134
+ // escape
13135
+ if (token = this.tokenizer.escape(src)) {
13136
+ src = src.substring(token.raw.length);
13137
+ tokens.push(token);
13138
+ continue;
13139
+ }
13140
+ // tag
13141
+ if (token = this.tokenizer.tag(src)) {
13142
+ src = src.substring(token.raw.length);
13143
+ lastToken = tokens[tokens.length - 1];
13144
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
13145
+ lastToken.raw += token.raw;
13146
+ lastToken.text += token.text;
13147
+ } else {
13148
+ tokens.push(token);
13149
+ }
13150
+ continue;
13151
+ }
13152
+ // link
13153
+ if (token = this.tokenizer.link(src)) {
13154
+ src = src.substring(token.raw.length);
13155
+ tokens.push(token);
13156
+ continue;
13157
+ }
13158
+ // reflink, nolink
13159
+ if (token = this.tokenizer.reflink(src, this.tokens.links)) {
13160
+ src = src.substring(token.raw.length);
13161
+ lastToken = tokens[tokens.length - 1];
13162
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
13163
+ lastToken.raw += token.raw;
13164
+ lastToken.text += token.text;
13165
+ } else {
13166
+ tokens.push(token);
13167
+ }
13168
+ continue;
13169
+ }
13170
+ // em & strong
13171
+ if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
13172
+ src = src.substring(token.raw.length);
13173
+ tokens.push(token);
13174
+ continue;
13175
+ }
13176
+ // code
13177
+ if (token = this.tokenizer.codespan(src)) {
13178
+ src = src.substring(token.raw.length);
13179
+ tokens.push(token);
13180
+ continue;
13181
+ }
13182
+ // br
13183
+ if (token = this.tokenizer.br(src)) {
13184
+ src = src.substring(token.raw.length);
13185
+ tokens.push(token);
13186
+ continue;
13187
+ }
13188
+ // del (gfm)
13189
+ if (token = this.tokenizer.del(src)) {
13190
+ src = src.substring(token.raw.length);
13191
+ tokens.push(token);
13192
+ continue;
13193
+ }
13194
+ // autolink
13195
+ if (token = this.tokenizer.autolink(src)) {
13196
+ src = src.substring(token.raw.length);
13197
+ tokens.push(token);
13198
+ continue;
13199
+ }
13200
+ // url (gfm)
13201
+ if (!this.state.inLink && (token = this.tokenizer.url(src))) {
13202
+ src = src.substring(token.raw.length);
13203
+ tokens.push(token);
13204
+ continue;
13205
+ }
13206
+ // text
13207
+ // prevent inlineText consuming extensions by clipping 'src' to extension start
13208
+ cutSrc = src;
13209
+ if (this.options.extensions && this.options.extensions.startInline) {
13210
+ let startIndex = Infinity;
13211
+ const tempSrc = src.slice(1);
13212
+ let tempStart;
13213
+ this.options.extensions.startInline.forEach(getStartIndex => {
13214
+ tempStart = getStartIndex.call({
13215
+ lexer: this
13216
+ }, tempSrc);
13217
+ if (typeof tempStart === 'number' && tempStart >= 0) {
13218
+ startIndex = Math.min(startIndex, tempStart);
13219
+ }
13220
+ });
13221
+ if (startIndex < Infinity && startIndex >= 0) {
13222
+ cutSrc = src.substring(0, startIndex + 1);
13223
+ }
13224
+ }
13225
+ if (token = this.tokenizer.inlineText(cutSrc)) {
13226
+ src = src.substring(token.raw.length);
13227
+ if (token.raw.slice(-1) !== '_') {
13228
+ // Track prevChar before string of ____ started
13229
+ prevChar = token.raw.slice(-1);
13230
+ }
13231
+ keepPrevChar = true;
13232
+ lastToken = tokens[tokens.length - 1];
13233
+ if (lastToken && lastToken.type === 'text') {
13234
+ lastToken.raw += token.raw;
13235
+ lastToken.text += token.text;
13236
+ } else {
13237
+ tokens.push(token);
13238
+ }
13239
+ continue;
13240
+ }
13241
+ if (src) {
13242
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
13243
+ if (this.options.silent) {
13244
+ console.error(errMsg);
13245
+ break;
13246
+ } else {
13247
+ throw new Error(errMsg);
13248
+ }
13249
+ }
13250
+ }
13251
+ return tokens;
13252
+ }
13253
+ }
13254
+
13255
+ /**
13256
+ * Renderer
13257
+ */
13258
+ class _Renderer {
13259
+ options;
13260
+ parser; // set by the parser
13261
+ constructor(options) {
13262
+ this.options = options || _defaults;
13263
+ }
13264
+ space(token) {
13265
+ return '';
13266
+ }
13267
+ code({
13268
+ text,
13269
+ lang,
13270
+ escaped
13271
+ }) {
13272
+ const langString = (lang || '').match(/^\S*/)?.[0];
13273
+ const code = text.replace(/\n$/, '') + '\n';
13274
+ if (!langString) {
13275
+ return '<pre><code>' + (escaped ? code : escape$1(code, true)) + '</code></pre>\n';
13276
+ }
13277
+ return '<pre><code class="language-' + escape$1(langString) + '">' + (escaped ? code : escape$1(code, true)) + '</code></pre>\n';
13278
+ }
13279
+ blockquote({
13280
+ tokens
13281
+ }) {
13282
+ const body = this.parser.parse(tokens);
13283
+ return `<blockquote>\n${body}</blockquote>\n`;
13284
+ }
13285
+ html({
13286
+ text
13287
+ }) {
13288
+ return text;
13289
+ }
13290
+ heading({
13291
+ tokens,
13292
+ depth
13293
+ }) {
13294
+ return `<h${depth}>${this.parser.parseInline(tokens)}</h${depth}>\n`;
13295
+ }
13296
+ hr(token) {
13297
+ return '<hr>\n';
13298
+ }
13299
+ list(token) {
13300
+ const ordered = token.ordered;
13301
+ const start = token.start;
13302
+ let body = '';
13303
+ for (let j = 0; j < token.items.length; j++) {
13304
+ const item = token.items[j];
13305
+ body += this.listitem(item);
13306
+ }
13307
+ const type = ordered ? 'ol' : 'ul';
13308
+ const startAttr = ordered && start !== 1 ? ' start="' + start + '"' : '';
13309
+ return '<' + type + startAttr + '>\n' + body + '</' + type + '>\n';
13310
+ }
13311
+ listitem(item) {
13312
+ let itemBody = '';
13313
+ if (item.task) {
13314
+ const checkbox = this.checkbox({
13315
+ checked: !!item.checked
13316
+ });
13317
+ if (item.loose) {
13318
+ if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
13319
+ item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
13320
+ if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
13321
+ item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
13322
+ }
13323
+ } else {
13324
+ item.tokens.unshift({
13325
+ type: 'text',
13326
+ raw: checkbox + ' ',
13327
+ text: checkbox + ' '
13328
+ });
13329
+ }
13330
+ } else {
13331
+ itemBody += checkbox + ' ';
13332
+ }
13333
+ }
13334
+ itemBody += this.parser.parse(item.tokens, !!item.loose);
13335
+ return `<li>${itemBody}</li>\n`;
13336
+ }
13337
+ checkbox({
13338
+ checked
13339
+ }) {
13340
+ return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox">';
13341
+ }
13342
+ paragraph({
13343
+ tokens
13344
+ }) {
13345
+ return `<p>${this.parser.parseInline(tokens)}</p>\n`;
13346
+ }
13347
+ table(token) {
13348
+ let header = '';
13349
+ // header
13350
+ let cell = '';
13351
+ for (let j = 0; j < token.header.length; j++) {
13352
+ cell += this.tablecell(token.header[j]);
13353
+ }
13354
+ header += this.tablerow({
13355
+ text: cell
13356
+ });
13357
+ let body = '';
13358
+ for (let j = 0; j < token.rows.length; j++) {
13359
+ const row = token.rows[j];
13360
+ cell = '';
13361
+ for (let k = 0; k < row.length; k++) {
13362
+ cell += this.tablecell(row[k]);
13363
+ }
13364
+ body += this.tablerow({
13365
+ text: cell
13366
+ });
13367
+ }
13368
+ if (body) body = `<tbody>${body}</tbody>`;
13369
+ return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
13370
+ }
13371
+ tablerow({
13372
+ text
13373
+ }) {
13374
+ return `<tr>\n${text}</tr>\n`;
13375
+ }
13376
+ tablecell(token) {
13377
+ const content = this.parser.parseInline(token.tokens);
13378
+ const type = token.header ? 'th' : 'td';
13379
+ const tag = token.align ? `<${type} align="${token.align}">` : `<${type}>`;
13380
+ return tag + content + `</${type}>\n`;
13381
+ }
13382
+ /**
13383
+ * span level renderer
13384
+ */
13385
+ strong({
13386
+ tokens
13387
+ }) {
13388
+ return `<strong>${this.parser.parseInline(tokens)}</strong>`;
13389
+ }
13390
+ em({
13391
+ tokens
13392
+ }) {
13393
+ return `<em>${this.parser.parseInline(tokens)}</em>`;
13394
+ }
13395
+ codespan({
13396
+ text
13397
+ }) {
13398
+ return `<code>${text}</code>`;
13399
+ }
13400
+ br(token) {
13401
+ return '<br>';
13402
+ }
13403
+ del({
13404
+ tokens
13405
+ }) {
13406
+ return `<del>${this.parser.parseInline(tokens)}</del>`;
13407
+ }
13408
+ link({
13409
+ href,
13410
+ title,
13411
+ tokens
13412
+ }) {
13413
+ const text = this.parser.parseInline(tokens);
13414
+ const cleanHref = cleanUrl(href);
13415
+ if (cleanHref === null) {
13416
+ return text;
13417
+ }
13418
+ href = cleanHref;
13419
+ let out = '<a href="' + href + '"';
13420
+ if (title) {
13421
+ out += ' title="' + title + '"';
13422
+ }
13423
+ out += '>' + text + '</a>';
13424
+ return out;
13425
+ }
13426
+ image({
13427
+ href,
13428
+ title,
13429
+ text
13430
+ }) {
13431
+ const cleanHref = cleanUrl(href);
13432
+ if (cleanHref === null) {
13433
+ return text;
13434
+ }
13435
+ href = cleanHref;
13436
+ let out = `<img src="${href}" alt="${text}"`;
13437
+ if (title) {
13438
+ out += ` title="${title}"`;
13439
+ }
13440
+ out += '>';
13441
+ return out;
13442
+ }
13443
+ text(token) {
13444
+ return 'tokens' in token && token.tokens ? this.parser.parseInline(token.tokens) : token.text;
13445
+ }
13446
+ }
13447
+
13448
+ /**
13449
+ * TextRenderer
13450
+ * returns only the textual part of the token
13451
+ */
13452
+ class _TextRenderer {
13453
+ // no need for block level renderers
13454
+ strong({
13455
+ text
13456
+ }) {
13457
+ return text;
13458
+ }
13459
+ em({
13460
+ text
13461
+ }) {
13462
+ return text;
13463
+ }
13464
+ codespan({
13465
+ text
13466
+ }) {
13467
+ return text;
13468
+ }
13469
+ del({
13470
+ text
13471
+ }) {
13472
+ return text;
13473
+ }
13474
+ html({
13475
+ text
13476
+ }) {
13477
+ return text;
13478
+ }
13479
+ text({
13480
+ text
13481
+ }) {
13482
+ return text;
13483
+ }
13484
+ link({
13485
+ text
13486
+ }) {
13487
+ return '' + text;
13488
+ }
13489
+ image({
13490
+ text
13491
+ }) {
13492
+ return '' + text;
13493
+ }
13494
+ br() {
13495
+ return '';
13496
+ }
13497
+ }
13498
+
13499
+ /**
13500
+ * Parsing & Compiling
13501
+ */
13502
+ class _Parser {
13503
+ options;
13504
+ renderer;
13505
+ textRenderer;
13506
+ constructor(options) {
13507
+ this.options = options || _defaults;
13508
+ this.options.renderer = this.options.renderer || new _Renderer();
13509
+ this.renderer = this.options.renderer;
13510
+ this.renderer.options = this.options;
13511
+ this.renderer.parser = this;
13512
+ this.textRenderer = new _TextRenderer();
13513
+ }
13514
+ /**
13515
+ * Static Parse Method
13516
+ */
13517
+ static parse(tokens, options) {
13518
+ const parser = new _Parser(options);
13519
+ return parser.parse(tokens);
13520
+ }
13521
+ /**
13522
+ * Static Parse Inline Method
13523
+ */
13524
+ static parseInline(tokens, options) {
13525
+ const parser = new _Parser(options);
13526
+ return parser.parseInline(tokens);
13527
+ }
13528
+ /**
13529
+ * Parse Loop
13530
+ */
13531
+ parse(tokens, top = true) {
13532
+ let out = '';
13533
+ for (let i = 0; i < tokens.length; i++) {
13534
+ const anyToken = tokens[i];
13535
+ // Run any renderer extensions
13536
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[anyToken.type]) {
13537
+ const genericToken = anyToken;
13538
+ const ret = this.options.extensions.renderers[genericToken.type].call({
13539
+ parser: this
13540
+ }, genericToken);
13541
+ if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(genericToken.type)) {
13542
+ out += ret || '';
13543
+ continue;
13544
+ }
13545
+ }
13546
+ const token = anyToken;
13547
+ switch (token.type) {
13548
+ case 'space':
13549
+ {
13550
+ out += this.renderer.space(token);
13551
+ continue;
13552
+ }
13553
+ case 'hr':
13554
+ {
13555
+ out += this.renderer.hr(token);
13556
+ continue;
13557
+ }
13558
+ case 'heading':
13559
+ {
13560
+ out += this.renderer.heading(token);
13561
+ continue;
13562
+ }
13563
+ case 'code':
13564
+ {
13565
+ out += this.renderer.code(token);
13566
+ continue;
13567
+ }
13568
+ case 'table':
13569
+ {
13570
+ out += this.renderer.table(token);
13571
+ continue;
13572
+ }
13573
+ case 'blockquote':
13574
+ {
13575
+ out += this.renderer.blockquote(token);
13576
+ continue;
13577
+ }
13578
+ case 'list':
13579
+ {
13580
+ out += this.renderer.list(token);
13581
+ continue;
13582
+ }
13583
+ case 'html':
13584
+ {
13585
+ out += this.renderer.html(token);
13586
+ continue;
13587
+ }
13588
+ case 'paragraph':
13589
+ {
13590
+ out += this.renderer.paragraph(token);
13591
+ continue;
13592
+ }
13593
+ case 'text':
13594
+ {
13595
+ let textToken = token;
13596
+ let body = this.renderer.text(textToken);
13597
+ while (i + 1 < tokens.length && tokens[i + 1].type === 'text') {
13598
+ textToken = tokens[++i];
13599
+ body += '\n' + this.renderer.text(textToken);
13600
+ }
13601
+ if (top) {
13602
+ out += this.renderer.paragraph({
13603
+ type: 'paragraph',
13604
+ raw: body,
13605
+ text: body,
13606
+ tokens: [{
13607
+ type: 'text',
13608
+ raw: body,
13609
+ text: body
13610
+ }]
13611
+ });
13612
+ } else {
13613
+ out += body;
13614
+ }
13615
+ continue;
13616
+ }
13617
+ default:
13618
+ {
13619
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
13620
+ if (this.options.silent) {
13621
+ console.error(errMsg);
13622
+ return '';
13623
+ } else {
13624
+ throw new Error(errMsg);
13625
+ }
13626
+ }
13627
+ }
13628
+ }
13629
+ return out;
13630
+ }
13631
+ /**
13632
+ * Parse Inline Tokens
13633
+ */
13634
+ parseInline(tokens, renderer) {
13635
+ renderer = renderer || this.renderer;
13636
+ let out = '';
13637
+ for (let i = 0; i < tokens.length; i++) {
13638
+ const anyToken = tokens[i];
13639
+ // Run any renderer extensions
13640
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[anyToken.type]) {
13641
+ const ret = this.options.extensions.renderers[anyToken.type].call({
13642
+ parser: this
13643
+ }, anyToken);
13644
+ if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(anyToken.type)) {
13645
+ out += ret || '';
13646
+ continue;
13647
+ }
13648
+ }
13649
+ const token = anyToken;
13650
+ switch (token.type) {
13651
+ case 'escape':
13652
+ {
13653
+ out += renderer.text(token);
13654
+ break;
13655
+ }
13656
+ case 'html':
13657
+ {
13658
+ out += renderer.html(token);
13659
+ break;
13660
+ }
13661
+ case 'link':
13662
+ {
13663
+ out += renderer.link(token);
13664
+ break;
13665
+ }
13666
+ case 'image':
13667
+ {
13668
+ out += renderer.image(token);
13669
+ break;
13670
+ }
13671
+ case 'strong':
13672
+ {
13673
+ out += renderer.strong(token);
13674
+ break;
13675
+ }
13676
+ case 'em':
13677
+ {
13678
+ out += renderer.em(token);
13679
+ break;
13680
+ }
13681
+ case 'codespan':
13682
+ {
13683
+ out += renderer.codespan(token);
13684
+ break;
13685
+ }
13686
+ case 'br':
13687
+ {
13688
+ out += renderer.br(token);
13689
+ break;
13690
+ }
13691
+ case 'del':
13692
+ {
13693
+ out += renderer.del(token);
13694
+ break;
13695
+ }
13696
+ case 'text':
13697
+ {
13698
+ out += renderer.text(token);
13699
+ break;
13700
+ }
13701
+ default:
13702
+ {
13703
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
13704
+ if (this.options.silent) {
13705
+ console.error(errMsg);
13706
+ return '';
13707
+ } else {
13708
+ throw new Error(errMsg);
13709
+ }
13710
+ }
13711
+ }
13712
+ }
13713
+ return out;
13714
+ }
13715
+ }
13716
+ class _Hooks {
13717
+ options;
13718
+ block;
13719
+ constructor(options) {
13720
+ this.options = options || _defaults;
13721
+ }
13722
+ static passThroughHooks = new Set(['preprocess', 'postprocess', 'processAllTokens']);
13723
+ /**
13724
+ * Process markdown before marked
13725
+ */
13726
+ preprocess(markdown) {
13727
+ return markdown;
13728
+ }
13729
+ /**
13730
+ * Process HTML after marked is finished
13731
+ */
13732
+ postprocess(html) {
13733
+ return html;
13734
+ }
13735
+ /**
13736
+ * Process all tokens before walk tokens
13737
+ */
13738
+ processAllTokens(tokens) {
13739
+ return tokens;
13740
+ }
13741
+ /**
13742
+ * Provide function to tokenize markdown
13743
+ */
13744
+ provideLexer() {
13745
+ return this.block ? _Lexer.lex : _Lexer.lexInline;
13746
+ }
13747
+ /**
13748
+ * Provide function to parse tokens
13749
+ */
13750
+ provideParser() {
13751
+ return this.block ? _Parser.parse : _Parser.parseInline;
13752
+ }
13753
+ }
13754
+ class Marked {
13755
+ defaults = _getDefaults();
13756
+ options = this.setOptions;
13757
+ parse = this.parseMarkdown(true);
13758
+ parseInline = this.parseMarkdown(false);
13759
+ Parser = _Parser;
13760
+ Renderer = _Renderer;
13761
+ TextRenderer = _TextRenderer;
13762
+ Lexer = _Lexer;
13763
+ Tokenizer = _Tokenizer;
13764
+ Hooks = _Hooks;
13765
+ constructor(...args) {
13766
+ this.use(...args);
13767
+ }
13768
+ /**
13769
+ * Run callback for every token
13770
+ */
13771
+ walkTokens(tokens, callback) {
13772
+ let values = [];
13773
+ for (const token of tokens) {
13774
+ values = values.concat(callback.call(this, token));
13775
+ switch (token.type) {
13776
+ case 'table':
13777
+ {
13778
+ const tableToken = token;
13779
+ for (const cell of tableToken.header) {
13780
+ values = values.concat(this.walkTokens(cell.tokens, callback));
13781
+ }
13782
+ for (const row of tableToken.rows) {
13783
+ for (const cell of row) {
13784
+ values = values.concat(this.walkTokens(cell.tokens, callback));
13785
+ }
13786
+ }
13787
+ break;
13788
+ }
13789
+ case 'list':
13790
+ {
13791
+ const listToken = token;
13792
+ values = values.concat(this.walkTokens(listToken.items, callback));
13793
+ break;
13794
+ }
13795
+ default:
13796
+ {
13797
+ const genericToken = token;
13798
+ if (this.defaults.extensions?.childTokens?.[genericToken.type]) {
13799
+ this.defaults.extensions.childTokens[genericToken.type].forEach(childTokens => {
13800
+ const tokens = genericToken[childTokens].flat(Infinity);
13801
+ values = values.concat(this.walkTokens(tokens, callback));
13802
+ });
13803
+ } else if (genericToken.tokens) {
13804
+ values = values.concat(this.walkTokens(genericToken.tokens, callback));
13805
+ }
13806
+ }
13807
+ }
13808
+ }
13809
+ return values;
13810
+ }
13811
+ use(...args) {
13812
+ const extensions = this.defaults.extensions || {
13813
+ renderers: {},
13814
+ childTokens: {}
13815
+ };
13816
+ args.forEach(pack => {
13817
+ // copy options to new object
13818
+ const opts = {
13819
+ ...pack
13820
+ };
13821
+ // set async to true if it was set to true before
13822
+ opts.async = this.defaults.async || opts.async || false;
13823
+ // ==-- Parse "addon" extensions --== //
13824
+ if (pack.extensions) {
13825
+ pack.extensions.forEach(ext => {
13826
+ if (!ext.name) {
13827
+ throw new Error('extension name required');
13828
+ }
13829
+ if ('renderer' in ext) {
13830
+ // Renderer extensions
13831
+ const prevRenderer = extensions.renderers[ext.name];
13832
+ if (prevRenderer) {
13833
+ // Replace extension with func to run new extension but fall back if false
13834
+ extensions.renderers[ext.name] = function (...args) {
13835
+ let ret = ext.renderer.apply(this, args);
13836
+ if (ret === false) {
13837
+ ret = prevRenderer.apply(this, args);
13838
+ }
13839
+ return ret;
13840
+ };
13841
+ } else {
13842
+ extensions.renderers[ext.name] = ext.renderer;
13843
+ }
13844
+ }
13845
+ if ('tokenizer' in ext) {
13846
+ // Tokenizer Extensions
13847
+ if (!ext.level || ext.level !== 'block' && ext.level !== 'inline') {
13848
+ throw new Error("extension level must be 'block' or 'inline'");
13849
+ }
13850
+ const extLevel = extensions[ext.level];
13851
+ if (extLevel) {
13852
+ extLevel.unshift(ext.tokenizer);
13853
+ } else {
13854
+ extensions[ext.level] = [ext.tokenizer];
13855
+ }
13856
+ if (ext.start) {
13857
+ // Function to check for start of token
13858
+ if (ext.level === 'block') {
13859
+ if (extensions.startBlock) {
13860
+ extensions.startBlock.push(ext.start);
13861
+ } else {
13862
+ extensions.startBlock = [ext.start];
13863
+ }
13864
+ } else if (ext.level === 'inline') {
13865
+ if (extensions.startInline) {
13866
+ extensions.startInline.push(ext.start);
13867
+ } else {
13868
+ extensions.startInline = [ext.start];
13869
+ }
13870
+ }
13871
+ }
13872
+ }
13873
+ if ('childTokens' in ext && ext.childTokens) {
13874
+ // Child tokens to be visited by walkTokens
13875
+ extensions.childTokens[ext.name] = ext.childTokens;
13876
+ }
13877
+ });
13878
+ opts.extensions = extensions;
13879
+ }
13880
+ // ==-- Parse "overwrite" extensions --== //
13881
+ if (pack.renderer) {
13882
+ const renderer = this.defaults.renderer || new _Renderer(this.defaults);
13883
+ for (const prop in pack.renderer) {
13884
+ if (!(prop in renderer)) {
13885
+ throw new Error(`renderer '${prop}' does not exist`);
13886
+ }
13887
+ if (['options', 'parser'].includes(prop)) {
13888
+ // ignore options property
13889
+ continue;
13890
+ }
13891
+ const rendererProp = prop;
13892
+ const rendererFunc = pack.renderer[rendererProp];
13893
+ const prevRenderer = renderer[rendererProp];
13894
+ // Replace renderer with func to run extension, but fall back if false
13895
+ renderer[rendererProp] = (...args) => {
13896
+ let ret = rendererFunc.apply(renderer, args);
13897
+ if (ret === false) {
13898
+ ret = prevRenderer.apply(renderer, args);
13899
+ }
13900
+ return ret || '';
13901
+ };
13902
+ }
13903
+ opts.renderer = renderer;
13904
+ }
13905
+ if (pack.tokenizer) {
13906
+ const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
13907
+ for (const prop in pack.tokenizer) {
13908
+ if (!(prop in tokenizer)) {
13909
+ throw new Error(`tokenizer '${prop}' does not exist`);
13910
+ }
13911
+ if (['options', 'rules', 'lexer'].includes(prop)) {
13912
+ // ignore options, rules, and lexer properties
13913
+ continue;
13914
+ }
13915
+ const tokenizerProp = prop;
13916
+ const tokenizerFunc = pack.tokenizer[tokenizerProp];
13917
+ const prevTokenizer = tokenizer[tokenizerProp];
13918
+ // Replace tokenizer with func to run extension, but fall back if false
13919
+ // @ts-expect-error cannot type tokenizer function dynamically
13920
+ tokenizer[tokenizerProp] = (...args) => {
13921
+ let ret = tokenizerFunc.apply(tokenizer, args);
13922
+ if (ret === false) {
13923
+ ret = prevTokenizer.apply(tokenizer, args);
13924
+ }
13925
+ return ret;
13926
+ };
13927
+ }
13928
+ opts.tokenizer = tokenizer;
13929
+ }
13930
+ // ==-- Parse Hooks extensions --== //
13931
+ if (pack.hooks) {
13932
+ const hooks = this.defaults.hooks || new _Hooks();
13933
+ for (const prop in pack.hooks) {
13934
+ if (!(prop in hooks)) {
13935
+ throw new Error(`hook '${prop}' does not exist`);
13936
+ }
13937
+ if (['options', 'block'].includes(prop)) {
13938
+ // ignore options and block properties
13939
+ continue;
13940
+ }
13941
+ const hooksProp = prop;
13942
+ const hooksFunc = pack.hooks[hooksProp];
13943
+ const prevHook = hooks[hooksProp];
13944
+ if (_Hooks.passThroughHooks.has(prop)) {
13945
+ // @ts-expect-error cannot type hook function dynamically
13946
+ hooks[hooksProp] = arg => {
13947
+ if (this.defaults.async) {
13948
+ return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
13949
+ return prevHook.call(hooks, ret);
13950
+ });
13951
+ }
13952
+ const ret = hooksFunc.call(hooks, arg);
13953
+ return prevHook.call(hooks, ret);
13954
+ };
13955
+ } else {
13956
+ // @ts-expect-error cannot type hook function dynamically
13957
+ hooks[hooksProp] = (...args) => {
13958
+ let ret = hooksFunc.apply(hooks, args);
13959
+ if (ret === false) {
13960
+ ret = prevHook.apply(hooks, args);
13961
+ }
13962
+ return ret;
13963
+ };
13964
+ }
13965
+ }
13966
+ opts.hooks = hooks;
13967
+ }
13968
+ // ==-- Parse WalkTokens extensions --== //
13969
+ if (pack.walkTokens) {
13970
+ const walkTokens = this.defaults.walkTokens;
13971
+ const packWalktokens = pack.walkTokens;
13972
+ opts.walkTokens = function (token) {
13973
+ let values = [];
13974
+ values.push(packWalktokens.call(this, token));
13975
+ if (walkTokens) {
13976
+ values = values.concat(walkTokens.call(this, token));
13977
+ }
13978
+ return values;
13979
+ };
13980
+ }
13981
+ this.defaults = {
13982
+ ...this.defaults,
13983
+ ...opts
13984
+ };
13985
+ });
13986
+ return this;
13987
+ }
13988
+ setOptions(opt) {
13989
+ this.defaults = {
13990
+ ...this.defaults,
13991
+ ...opt
13992
+ };
13993
+ return this;
13994
+ }
13995
+ lexer(src, options) {
13996
+ return _Lexer.lex(src, options ?? this.defaults);
13997
+ }
13998
+ parser(tokens, options) {
13999
+ return _Parser.parse(tokens, options ?? this.defaults);
14000
+ }
14001
+ parseMarkdown(blockType) {
14002
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14003
+ const parse = (src, options) => {
14004
+ const origOpt = {
14005
+ ...options
14006
+ };
14007
+ const opt = {
14008
+ ...this.defaults,
14009
+ ...origOpt
14010
+ };
14011
+ const throwError = this.onError(!!opt.silent, !!opt.async);
14012
+ // throw error if an extension set async to true but parse was called with async: false
14013
+ if (this.defaults.async === true && origOpt.async === false) {
14014
+ return throwError(new Error('marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.'));
14015
+ }
14016
+ // throw error in case of non string input
14017
+ if (typeof src === 'undefined' || src === null) {
14018
+ return throwError(new Error('marked(): input parameter is undefined or null'));
14019
+ }
14020
+ if (typeof src !== 'string') {
14021
+ return throwError(new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected'));
14022
+ }
14023
+ if (opt.hooks) {
14024
+ opt.hooks.options = opt;
14025
+ opt.hooks.block = blockType;
14026
+ }
14027
+ const lexer = opt.hooks ? opt.hooks.provideLexer() : blockType ? _Lexer.lex : _Lexer.lexInline;
14028
+ const parser = opt.hooks ? opt.hooks.provideParser() : blockType ? _Parser.parse : _Parser.parseInline;
14029
+ if (opt.async) {
14030
+ return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src).then(src => lexer(src, opt)).then(tokens => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens).then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens).then(tokens => parser(tokens, opt)).then(html => opt.hooks ? opt.hooks.postprocess(html) : html).catch(throwError);
14031
+ }
14032
+ try {
14033
+ if (opt.hooks) {
14034
+ src = opt.hooks.preprocess(src);
14035
+ }
14036
+ let tokens = lexer(src, opt);
14037
+ if (opt.hooks) {
14038
+ tokens = opt.hooks.processAllTokens(tokens);
14039
+ }
14040
+ if (opt.walkTokens) {
14041
+ this.walkTokens(tokens, opt.walkTokens);
14042
+ }
14043
+ let html = parser(tokens, opt);
14044
+ if (opt.hooks) {
14045
+ html = opt.hooks.postprocess(html);
14046
+ }
14047
+ return html;
14048
+ } catch (e) {
14049
+ return throwError(e);
14050
+ }
14051
+ };
14052
+ return parse;
14053
+ }
14054
+ onError(silent, async) {
14055
+ return e => {
14056
+ e.message += '\nPlease report this to https://github.com/markedjs/marked.';
14057
+ if (silent) {
14058
+ const msg = '<p>An error occurred:</p><pre>' + escape$1(e.message + '', true) + '</pre>';
14059
+ if (async) {
14060
+ return Promise.resolve(msg);
14061
+ }
14062
+ return msg;
14063
+ }
14064
+ if (async) {
14065
+ return Promise.reject(e);
14066
+ }
14067
+ throw e;
14068
+ };
14069
+ }
14070
+ }
14071
+ const markedInstance = new Marked();
14072
+ function marked(src, opt) {
14073
+ return markedInstance.parse(src, opt);
14074
+ }
14075
+ /**
14076
+ * Sets the default options.
14077
+ *
14078
+ * @param options Hash of options
14079
+ */
14080
+ marked.options = marked.setOptions = function (options) {
14081
+ markedInstance.setOptions(options);
14082
+ marked.defaults = markedInstance.defaults;
14083
+ changeDefaults(marked.defaults);
14084
+ return marked;
14085
+ };
14086
+ /**
14087
+ * Gets the original marked default options.
14088
+ */
14089
+ marked.getDefaults = _getDefaults;
14090
+ marked.defaults = _defaults;
14091
+ /**
14092
+ * Use Extension
14093
+ */
14094
+ marked.use = function (...args) {
14095
+ markedInstance.use(...args);
14096
+ marked.defaults = markedInstance.defaults;
14097
+ changeDefaults(marked.defaults);
14098
+ return marked;
14099
+ };
14100
+ /**
14101
+ * Run callback for every token
14102
+ */
14103
+ marked.walkTokens = function (tokens, callback) {
14104
+ return markedInstance.walkTokens(tokens, callback);
14105
+ };
14106
+ /**
14107
+ * Compiles markdown to HTML without enclosing `p` tag.
14108
+ *
14109
+ * @param src String of markdown source to be compiled
14110
+ * @param options Hash of options
14111
+ * @return String of compiled HTML
14112
+ */
14113
+ marked.parseInline = markedInstance.parseInline;
14114
+ /**
14115
+ * Expose
14116
+ */
14117
+ marked.Parser = _Parser;
14118
+ marked.parser = _Parser.parse;
14119
+ marked.Renderer = _Renderer;
14120
+ marked.TextRenderer = _TextRenderer;
14121
+ marked.Lexer = _Lexer;
14122
+ marked.lexer = _Lexer.lex;
14123
+ marked.Tokenizer = _Tokenizer;
14124
+ marked.Hooks = _Hooks;
14125
+ marked.parse = marked;
14126
+ const options = marked.options;
14127
+ const setOptions = marked.setOptions;
14128
+ const use = marked.use;
14129
+ const walkTokens = marked.walkTokens;
14130
+ const parseInline = marked.parseInline;
14131
+ const parse = (/* unused pure expression or super */ null && (marked));
14132
+ const parser = _Parser.parse;
14133
+ const lexer = _Lexer.lex;
14134
+
14135
+ ;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat.vue?vue&type=script&lang=js
14136
+
14137
+
14138
+
14139
+
14140
+
14141
+ const controller = new AbortController();
14142
+ const signal = controller.signal;
14143
+ /* harmony default export */ var chatvue_type_script_lang_js = ({
14144
+ name: 'Chat',
14145
+ components: {
14146
+ ErrorChat: error_chat,
14147
+ ChatTools: chat_tools
14148
+ },
14149
+ props: {
14150
+ analyExercise: {},
14151
+ keyWord: {
14152
+ type: String,
14153
+ default: ''
14154
+ },
14155
+ resId: {
14156
+ type: String,
14157
+ default: ''
14158
+ },
14159
+ xtId: {
14160
+ type: String,
14161
+ default: ''
14162
+ }
14163
+ },
14164
+ data() {
14165
+ return {
14166
+ popover: false,
14167
+ input: '',
14168
+ errors: [],
14169
+ errorList: errorList,
14170
+ cacheKeyWord: '',
14171
+ // 由于外部需要快速清掉 keyword 但是存在重新发送请求的情况,因此需要一个混存记录
14172
+ messageData: [],
14173
+ chatId: '',
14174
+ // 对话id
14175
+ chatMajorId: '',
14176
+ finish: false
14177
+ };
14178
+ },
14179
+ computed: {
14180
+ canSubmit() {
14181
+ return this.errors.length === 0 && this.input === "";
14182
+ }
14183
+ },
14184
+ watch: {
14185
+ keyWord: {
14186
+ handler() {
14187
+ if (this.keyWord) {
14188
+ this.cacheKeyWord = this.keyWord;
14189
+ this.postMessage();
14190
+ }
14191
+ },
14192
+ immediate: true
14193
+ }
14194
+ },
14195
+ methods: {
14196
+ cancelPopover() {
14197
+ this.popover = false;
14198
+ },
14199
+ openPopover() {
14200
+ this.popover = true;
14201
+ },
14202
+ scrollToBottom() {
14203
+ this.$refs.chatContainer.scrollTop = this.$refs.chatContainer.scrollHeight;
14204
+ },
14205
+ async postMessage(list, commonKey, parentMsgId) {
14206
+ let reanswerParams = {};
14207
+ this.finish = false;
14208
+ if (list) {
14209
+ list.sending = true;
14210
+ reanswerParams = {
14211
+ reStatus: 1,
14212
+ parentMsgId: list.parentMsgId,
14213
+ msgId: list.msgId,
14214
+ content: this.messageData[list.index - 1].message
14215
+ };
14216
+ this.messageData[list.index].message = '';
14217
+ this.messageData[list.index].cacheMessage = '';
14218
+ this.makeAutoMessage();
14219
+ }
14220
+ const params = {
14221
+ messageList: [{
14222
+ content: this.keyWord || this.cacheKeyWord,
14223
+ resId: this.resId,
14224
+ chatId: this.chatId || undefined,
14225
+ commonKey: commonKey || false,
14226
+ parentMsgId: parentMsgId || undefined,
14227
+ xtId: this.analyExercise.busId,
14228
+ ...reanswerParams
14229
+ }]
14230
+ };
14231
+ // list 存在说明是重新生成
14232
+ if (!list && !commonKey) {
14233
+ const userWord = this.keyWord || this.cacheKeyWord;
14234
+ this.messageData.push({
14235
+ type: 'user',
14236
+ message: userWord.replace(/\n/g, '<br>')
14237
+ });
14238
+ setTimeout(() => {
14239
+ this.messageData.push({
14240
+ type: 'robot',
14241
+ message: '',
14242
+ cacheMessage: '',
14243
+ zan: false,
14244
+ cai: false,
14245
+ stop: false,
14246
+ finish: false,
14247
+ sending: true,
14248
+ links: [],
14249
+ connectUrl: [],
14250
+ reAnswerCount: 0
14251
+ });
14252
+ this.makeAutoMessage();
14253
+ });
14254
+ }
14255
+ await sendMessageEventSource(params, signal, res => {
14256
+ this.makeMessageLine(res, list);
14257
+ });
14258
+ },
14259
+ makeAutoMessage() {
14260
+ const cacheMessage = [];
14261
+ for (let i = 0; i < this.messageData.length; i++) {
14262
+ const current = this.messageData[i];
14263
+ cacheMessage.push({
14264
+ role: current.type === 'robot' ? 'assistant' : 'user',
14265
+ content: current.message || '正在思考中。'
14266
+ });
14267
+ }
14268
+ this.makeAutoQuestioning(cacheMessage);
14269
+ },
14270
+ makeMessageLine(res, list) {
14271
+ const {
14272
+ content,
14273
+ status,
14274
+ chatId,
14275
+ msgId,
14276
+ parentMsgId,
14277
+ reference,
14278
+ commonKey,
14279
+ connectUrl
14280
+ } = JSON.parse(res.data);
14281
+ let index = list ? list.index : this.messageData.length - 1;
14282
+ const currentList = this.messageData[index];
14283
+ let allIdWithStart = true;
14284
+ // 结束标识
14285
+ if (status === 2 || status === 1) {
14286
+ if (commonKey) {
14287
+ currentList.sending = true;
14288
+ this.postMessage(list, commonKey, parentMsgId);
14289
+ return;
14290
+ }
14291
+ currentList.finish = true;
14292
+ if (reference) {
14293
+ currentList.links = JSON.parse(reference);
14294
+ currentList.links.map(item => {
14295
+ if (!item.title.startsWith(this.chatMajorId)) {
14296
+ allIdWithStart = false;
14297
+ }
14298
+ });
14299
+ }
14300
+ if (connectUrl) {
14301
+ currentList.connectUrl = JSON.parse(connectUrl);
14302
+ }
14303
+ currentList.allIdWithStart = allIdWithStart;
14304
+ this.cacheKeyWord = '';
14305
+ this.finish = true;
14306
+ this.$emit('on-message-finish', chatId);
14307
+ return;
14308
+ }
14309
+ currentList.cacheMessage += content;
14310
+ currentList.message = marked.parse(currentList.cacheMessage);
14311
+ currentList.msgId = msgId;
14312
+ currentList.parentMsgId = parentMsgId;
14313
+ currentList.chatId = chatId;
14314
+ setTimeout(() => {
14315
+ if (!list) this.scrollToBottom();
14316
+ }, 100);
14317
+ // 防止出现调用基础模型前导致停止回答id错误
14318
+ setTimeout(() => currentList.sending = false, 500);
14319
+ },
14320
+ async makeAutoQuestioning(messages) {
14321
+ // 首次不触发
14322
+ if (messages.length <= 2) return;
14323
+ const autoRes = await getAutoQuestioning(this.chatMajorId, messages);
14324
+ const {
14325
+ message: {
14326
+ content: {
14327
+ followUps
14328
+ }
14329
+ }
14330
+ } = autoRes;
14331
+ this.messageData[this.messageData.length - 1].followUps = followUps.length > 3 ? followUps.splice(0, 3) : followUps;
14332
+ },
14333
+ onStopChat(list) {
14334
+ this.$emit('on-message-finish', list.chatId);
14335
+ },
14336
+ selectModule(message) {
14337
+ this.cacheKeyWord = message;
14338
+ this.postMessage();
14339
+ },
14340
+ async clearChat() {
14341
+ if (this.messageData.length < 1) {
14342
+ this.$message.warning('当前对话为最新对话');
14343
+ return;
14344
+ }
14345
+ await chartClear(this.chatId);
14346
+ this.messageData = [];
11780
14347
  this.$message.success('对话清除成功!');
11781
14348
  },
11782
14349
  reanswer(list, index) {
@@ -11784,28 +14351,39 @@ const signal = controller.signal;
11784
14351
  list.stop = false;
11785
14352
  list.finish = false;
11786
14353
  list.links = [];
14354
+ list.connectUrl = [];
11787
14355
  this.postMessage(list);
11788
14356
  this.$emit('on-reanser');
11789
14357
  },
11790
14358
  errorChatInit(list, chatId) {
11791
- const {
11792
- chatMajorId
11793
- } = list[0];
11794
- this.chatMajorId = chatMajorId.toString();
11795
14359
  if (list && list[0].contents) {
14360
+ const {
14361
+ chatMajorId
14362
+ } = list[0];
14363
+ this.chatMajorId = chatMajorId && chatMajorId.toString();
11796
14364
  const cacheArray = [];
11797
14365
  list[0].contents.reverse().map(list => {
14366
+ let allIdWithStart = true;
14367
+ if (this.chatMajorId && list.references) {
14368
+ list.references.map(item => {
14369
+ if (!item.title.startsWith(this.chatMajorId)) {
14370
+ allIdWithStart = false;
14371
+ }
14372
+ });
14373
+ }
11798
14374
  const obj = {
11799
14375
  type: list.role === 'assistant' ? 'robot' : 'user',
11800
- message: list.content.replace(/\n/g, '<br>'),
14376
+ message: list.role === 'assistant' ? marked.parse(list.content) : list.content.replace(/\n/g, '<br>'),
11801
14377
  zan: list.type === 1,
11802
14378
  cai: list.type === 2,
11803
14379
  stop: list.status === 1,
11804
14380
  finish: true,
11805
14381
  links: list.references || [],
14382
+ connectUrl: list.connectUrls || [],
11806
14383
  reAnswerCount: 0,
11807
14384
  msgId: list.contentId,
11808
- parentMsgId: list.parentMsgId
14385
+ parentMsgId: list.parentMsgId,
14386
+ allIdWithStart
11809
14387
  };
11810
14388
  cacheArray.push(obj);
11811
14389
  });
@@ -11819,10 +14397,10 @@ const signal = controller.signal;
11819
14397
  });
11820
14398
  ;// CONCATENATED MODULE: ./components/demo/src/chat.vue?vue&type=script&lang=js
11821
14399
  /* harmony default export */ var src_chatvue_type_script_lang_js = (chatvue_type_script_lang_js);
11822
- ;// CONCATENATED MODULE: ./node_modules/mini-css-extract-plugin/dist/loader.js??clonedRuleSet-22.use[0]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-22.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-22.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-22.use[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat.vue?vue&type=style&index=0&id=8e426b78&prod&lang=scss&scoped=true
14400
+ ;// CONCATENATED MODULE: ./node_modules/mini-css-extract-plugin/dist/loader.js??clonedRuleSet-22.use[0]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-22.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-22.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-22.use[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/chat.vue?vue&type=style&index=0&id=d21026be&prod&lang=scss&scoped=true
11823
14401
  // extracted by mini-css-extract-plugin
11824
14402
 
11825
- ;// CONCATENATED MODULE: ./components/demo/src/chat.vue?vue&type=style&index=0&id=8e426b78&prod&lang=scss&scoped=true
14403
+ ;// CONCATENATED MODULE: ./components/demo/src/chat.vue?vue&type=style&index=0&id=d21026be&prod&lang=scss&scoped=true
11826
14404
 
11827
14405
  ;// CONCATENATED MODULE: ./components/demo/src/chat.vue
11828
14406
 
@@ -11835,11 +14413,11 @@ const signal = controller.signal;
11835
14413
 
11836
14414
  var chat_component = normalizeComponent(
11837
14415
  src_chatvue_type_script_lang_js,
11838
- chatvue_type_template_id_8e426b78_scoped_true_render,
11839
- chatvue_type_template_id_8e426b78_scoped_true_staticRenderFns,
14416
+ chatvue_type_template_id_d21026be_scoped_true_render,
14417
+ chatvue_type_template_id_d21026be_scoped_true_staticRenderFns,
11840
14418
  false,
11841
14419
  null,
11842
- "8e426b78",
14420
+ "d21026be",
11843
14421
  null
11844
14422
 
11845
14423
  )
@@ -11982,13 +14560,29 @@ var api = init(defaultConverter, {
11982
14560
  return this.analyExercise.busId;
11983
14561
  }
11984
14562
  },
14563
+ watch: {
14564
+ visible() {
14565
+ if (this.visible) {
14566
+ checkCourseIdIsExist(this.resId).then(res => {
14567
+ if (res.flag === true) {
14568
+ this.courseFlag = true;
14569
+ } else {
14570
+ this.courseFlag = false;
14571
+ this.message = res.message;
14572
+ }
14573
+ });
14574
+ }
14575
+ }
14576
+ },
11985
14577
  data() {
11986
14578
  return {
11987
14579
  aiMessage: '',
11988
14580
  // 页面显示值
11989
14581
  aiMessageKeyWord: '',
11990
14582
  // 传入组件值
11991
- stop: false
14583
+ stop: false,
14584
+ courseFlag: false,
14585
+ message: ''
11992
14586
  };
11993
14587
  },
11994
14588
  mounted() {
@@ -12048,10 +14642,10 @@ var api = init(defaultConverter, {
12048
14642
  });
12049
14643
  ;// CONCATENATED MODULE: ./components/demo/src/main.vue?vue&type=script&lang=js
12050
14644
  /* harmony default export */ var src_mainvue_type_script_lang_js = (mainvue_type_script_lang_js);
12051
- ;// CONCATENATED MODULE: ./node_modules/mini-css-extract-plugin/dist/loader.js??clonedRuleSet-22.use[0]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-22.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-22.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-22.use[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/main.vue?vue&type=style&index=0&id=63ef79ac&prod&lang=scss&scoped=true
14645
+ ;// CONCATENATED MODULE: ./node_modules/mini-css-extract-plugin/dist/loader.js??clonedRuleSet-22.use[0]!./node_modules/css-loader/dist/cjs.js??clonedRuleSet-22.use[1]!./node_modules/@vue/vue-loader-v15/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-22.use[2]!./node_modules/sass-loader/dist/cjs.js??clonedRuleSet-22.use[3]!./node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./components/demo/src/main.vue?vue&type=style&index=0&id=3f590f5c&prod&lang=scss&scoped=true
12052
14646
  // extracted by mini-css-extract-plugin
12053
14647
 
12054
- ;// CONCATENATED MODULE: ./components/demo/src/main.vue?vue&type=style&index=0&id=63ef79ac&prod&lang=scss&scoped=true
14648
+ ;// CONCATENATED MODULE: ./components/demo/src/main.vue?vue&type=style&index=0&id=3f590f5c&prod&lang=scss&scoped=true
12055
14649
 
12056
14650
  ;// CONCATENATED MODULE: ./components/demo/src/main.vue
12057
14651
 
@@ -12068,7 +14662,7 @@ var main_component = normalizeComponent(
12068
14662
  staticRenderFns,
12069
14663
  false,
12070
14664
  null,
12071
- "63ef79ac",
14665
+ "3f590f5c",
12072
14666
  null
12073
14667
 
12074
14668
  )