MCPcopy
hub / github.com/ocsjs/ocsjs / workOrExamQuestionTitleTransform

Function workOrExamQuestionTitleTransform

packages/scripts/src/projects/cx.ts:764–794  ·  view source on GitHub ↗
(titles: (HTMLElement | undefined)[])

Source from the content-addressed store, hash-verified

762
763 // 处理作业和考试题目的方法
764 const workOrExamQuestionTitleTransform = (titles: (HTMLElement | undefined)[]) => {
765 // 是否为多个小题的题目
766 const is_multiple_question = titles.length > 1;
767 const optimizationTitle = titles
768 .map((el, i) => {
769 if (el) {
770 const titleCloneEl = el.cloneNode(true) as HTMLElement;
771 const childNodes = titleCloneEl.childNodes;
772 // 一般多小题题目只有第一个 title 存在题型文本
773 if (i === 0) {
774 // 删除序号
775 childNodes[0]?.remove();
776 // 删除题型
777 childNodes[0]?.remove();
778 }
779 // 显示图片链接在题目中
780 return optimizationElementWithImage(titleCloneEl, true).innerText;
781 }
782 return '';
783 })
784 .join('\n');
785
786 return removeRedundantWords(
787 StringUtils.of(optimizationTitle)
788 .nowrap(is_multiple_question ? '\n' : ' ')
789 .nospace()
790 .toString()
791 .trim(),
792 redundanceWordsText.split('\n')
793 );
794 };
795
796 // 这里跟章节测试的连线题不一样,章节测试是新版连线题
797 /** 新建答题器 */

Callers 1

workOrExamFunction · 0.85

Calls 6

removeRedundantWordsFunction · 0.90
toStringMethod · 0.80
nospaceMethod · 0.80
nowrapMethod · 0.80
ofMethod · 0.80

Tested by

no test coverage detected