zoukankan      html  css  js  c++  java
  • 根据固定格式进行数据拆分

    eg
    <b>加粗文字</b>文字文字<br/>(换行)文字文字##1##(问题序号)文字文字


    //通过ID,获取试题 function getQuestionById(list, id) { let data = {}; for(let n = 0 ;n<list.length;n++){ if (list[n].number == parseInt(id)) { data = list[n]; break; } } return data; } //分析文章试题 function parseParagraphs(content, paragraphQuestionList) { var paragraphs = { fragments: [] }; //标题 var html = content.replace(/<b>(.*?)</b>/, ""); if (RegExp.$1) { paragraphs.fragments.push({ type: 'title', content: RegExp.$1 }); } var sections = html.replace(/ /g, '').split(/<br/>/); for (var i = 0; i < sections.length; i++) { var ms = sections[i].match(/##d+##/g); var qs = sections[i].split(/##d+##/); for (var n = 0; n < qs.length; n++) { //段落片段 if (qs[n] != '') { paragraphs.fragments.push({ type: 'paragraph', content: qs[n] }); } if (n < qs.length - 1) { ms[n].match(/##(d+)##/) paragraphs.fragments.push({ type: 'question', id: RegExp.$1, content: getQuestionById(paragraphQuestionList, RegExp.$1) }); } } //段落片段 paragraphs.fragments.push({ type: 'br' }); } // let num = paragraphs.fragments.length -1; // paragraphs.fragments.forEach((item,index) => { // if (item.type == 'br' && index < num){ // let key = paragraphs.fragments[index + 1].type; // if (key =='paragraph'){ // paragraphs.fragments[index + 1].type ='paragraphIndent' // } // } // }) return paragraphs; } export default parseParagraphs

      

  • 相关阅读:
    装饰器结合cookie
    day12(输出重定向)
    day13(软件包管理)
    day11(acl权限/特殊属性/su与sudo)
    day10(权限)
    day09(用户管理)
    day08(打包压缩zip和tar)
    day07 文件管理(上传与下载/字符处理命令sort/uniq/cut与tr/wc)
    day06(find命令 name/size/type)
    day05(文件的修改vi和vim/移动文件mv/删除文件rm)
  • 原文地址:https://www.cnblogs.com/linsx/p/9761150.html
Copyright © 2011-2022 走看看