diff --git a/Flucy.html b/Flucy.html index a22220b..4cd97cc 100644 --- a/Flucy.html +++ b/Flucy.html @@ -14,9 +14,7 @@ -
- -
+
diff --git a/README.md b/README.md index c999d3e..a37eda3 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,18 @@ - [x] 增加JSON校验错误提示 - [x] 增加控制台版本报告 -- [ ] 增加控制台`issue`提交路径信息 -- [ ] 增加`markdown`格式支持,可能要定制语法,防止`
`标签
+- [x] 增加控制台`issue`提交路径信息
+- [x] 增加`markdown`格式支持,可能要定制语法,防止`
`标签
 - [ ] 增加json文件直接导入功能
 - [ ] 增加json文件直接导出功能,生成前再校验一次
-- [ ] 增加页面重置功能,避免刷新,重置前提示用户
-- [ ] 增加tests翻译功能
-- [ ] 调整页面按钮文案,避免和新功能混淆
+- [x] 增加页面重置功能,避免刷新,重置前提示用户
+- [x] 增加tests翻译功能
+- [x] 调整页面按钮文案,避免和新功能混淆
 - [ ] 增加翻译提示功能,及语言转换选项
-- [ ] 增加description语言分支选择功能,多语言版本
\ No newline at end of file
+- [ ] 增加description语言分支选择功能,多语言版本
+
+## 已知bug - 覆盖测试下
+
+1. basic-bonfires.json / basic-ziplines.json / front-end-development-certificate.json / gear-up-for-success.json / data-visualization-certificate.json / api-projects.json / back-end-development-certificate.json /里导出或导入错误,它的discription里面还有数组,我把它扁平化了
+2. front-end-development-certificate.json / chromedevtools.json /  bigonotation.json / computer-basics.json / dom.json / jslingo.json没用断言,用的别的,上面的有些也是这个原因
+3. basic-js.json 中后几个断言中没有message字段
\ No newline at end of file
diff --git a/index.css b/index.css
index 2a280ad..ccf0015 100644
--- a/index.css
+++ b/index.css
@@ -24,4 +24,10 @@ body, section, div {
 }
 .container div textarea {
     width: 100%;
+}
+.mainText {
+    color: black;
+}
+.testsText {
+    color: blue;
 }
\ No newline at end of file
diff --git a/index.js b/index.js
index a2b3d54..ce0dc3d 100644
--- a/index.js
+++ b/index.js
@@ -4,8 +4,47 @@ var str ='';
 var obj = {
     challenges: []
 };
-console.log("Flucy~v0.1.3");
+
+String.prototype.markdown2Html = function markdown2Html() {
+    var parten = {
+        strong: {
+            exp: /(?:\*\*)(.+?)(?:\*\*)/gi,
+            html: [" ", " "]
+        },
+        code: {
+            exp: /(?:\`)(.+?)(?:\`)/gi,
+            html: [" ", " "]
+        }
+    }
+    var result = this.toString();
+    for (currentParten in parten) {
+        if (parten.hasOwnProperty(currentParten)) {
+            result = result.replace(parten[currentParten].exp, function () {
+                console.log(arguments);
+                return parten[currentParten].html[0] + arguments[1] + parten[currentParten].html[1];
+            })
+        }
+    }
+    return result
+}
+console.log("Flucy~ v0.1.5 @KevinHu-1024");
+console.log("bug反馈地址:https://github.com/KevinHu-1024/Flucy/issues");
+console.log("本工具来自FreeCodeCamp中文社区翻译组:https://github.com/huluoyang/freecodecamp.cn/wiki");
+console.log("FreeCodeCamp中文社区:https://freecodecamp.cn");
 function a() {
+    if (translate.innerHTML != '') {
+        var con = confirm("导入时会重置右侧内容!");
+        if (!con) {
+            return
+        }
+    }
+    source.disabled = 'disabled';
+    translate.innerHTML = '';
+    json = null;
+    str ='';
+    obj = {
+        challenges: []
+    };
     try {
         json = JSON.parse(source.value);
     } catch (error) {
@@ -13,41 +52,81 @@ function a() {
         console.log(error);
         return
     }
+    var main = document.createElement('h3');
+    main.innerHTML = json.name;
+    main.style = "color:red;";
+    translate.appendChild(main);
+    var link = document.createElement('a');
+    link.innerHTML = title;
+    link.href = "https://github.com/KevinHu-1024/Flucy/releases/";
+    link.style = "text-align:right;font-size:12px;color:grey;text-decoration:none;";
+    translate.appendChild(link);
+    var frg = document.createDocumentFragment();
     for(var i = 0; i < json.challenges.length; i++) {
         var cur = json.challenges[i];
-        str += "

" + (i+1) + "." + cur.title +"

" + var ti = document.createElement('h4'); + ti.style = "color:green;text-decoration:underline"; + ti.innerHTML = (i+1) + "." + cur.title; + frg.appendChild(ti); obj.challenges.push({ - dis:[] + dis:[], + tes:[] }) for (var j = 0; j < cur.description.length; j ++) { - str += ""; + var tex = document.createElement('textarea'); + tex.value = cur.description[j]; + tex.className = "mainText"; + tex.rows = 5; + frg.appendChild(tex); + tex = null; obj.challenges[i].dis.push(cur.description[j]); } + for (var n = 0; n < cur.tests.length; n++) { + var tesTex = document.createElement('textarea'); + // console.log(n, cur.tests[n]); + tesTex.value = /(?:\'message\:)(.+)(?:\'\))/gi.exec(cur.tests[n])[1]; + tesTex.className = "testsText"; + tesTex.rows = 5; + frg.appendChild(tesTex); + tesTex = null; + obj.challenges[i].tes.push(cur.tests[n]); + } } console.log(json); console.log(obj); - translate.innerHTML = "

" + json.name +"

" + "" + title + "" + str; + translate.appendChild(frg); } function b() { - var collection = translate.getElementsByTagName("textarea"); + if (source.value != '') { + var con = confirm("导出时会重置左侧内容!"); + if (!con) { + return + } + } + source.value = ''; + var mainTextCollection = translate.getElementsByClassName("mainText"); + var testsTextCollection = translate.getElementsByClassName("testsText"); var i = 0; - // console.log(collection); + var h = 0; for (var m = 0; m < obj.challenges.length; m++) { var tar = obj.challenges[m]; for (var j = 0; j < tar.dis.length; j++) { - tar.dis[j] = collection[i].value.replace(/(\)(\s\s)/gi, '$1  ').replace(/(\)(\s\s)/gi, '$1  '); + tar.dis[j] = mainTextCollection[i].value.markdown2Html(); i ++; } + for (var n = 0; n < tar.tes.length; n++) { + tar.tes[n] = testsTextCollection[h].value.markdown2Html() + "');"; + h ++; + } } console.log(obj); for (var k = 0; k < obj.challenges.length; k++) { json.challenges[k].description = obj.challenges[k].dis; + for (var t = 0; t < obj.challenges[k].tes.length; t++) { + obj.challenges[k].tes[t] = /^(assert)(.+)(?:'message:)/gi.exec(json.challenges[k].tests[t])[0] + obj.challenges[k].tes[t]; + json.challenges[k].tests[t] = obj.challenges[k].tes[t]; + } } console.log(json); - source.value = JSON.stringify(json, null, 2); -} -// 提取tests中某项的message: -// /(?:\'message\:)(.+)(?:\))/gi.exec("assert((function(){var testCar = new Car(3,1,2); return testCar.wheels === 3 && testCar.seats === 1 && testCar.engines === 2;})(), 'message: Calling new Car(3,1,2) should produce an object with a wheels property of 3, a seats property of 1, and an engines property of 2.');")[1] -//转义 -//" return valorAnterior - valorActual;".replace(/(\)(\s\s)/gi, '$1  ') -//"
return valorAnterior - valorActual;
".replace(/(\)(\s\s)/gi, '$1  ') \ No newline at end of file + source.value = JSON.stringify(json, null, 2) + "\n"; +} \ No newline at end of file