|
@@ -15,6 +15,14 @@ namespace HTEXLib.Translator
|
|
|
{
|
|
|
public class HTML2ITEMV3Translator
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// 全角
|
|
|
+ /// </summary>
|
|
|
+ string[] aza = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
|
|
|
+ /// <summary>
|
|
|
+ /// 半角
|
|
|
+ /// </summary>
|
|
|
+ string[] azh = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
|
|
|
public const string Answer = "Answer";
|
|
|
public const string Analysis = "Analysis";
|
|
|
public const string Ended = "Ended";
|
|
@@ -137,6 +145,9 @@ namespace HTEXLib.Translator
|
|
|
html = Regex.Replace(html, classpattern, "");
|
|
|
string pattern = "<span([^>]{0,})>";
|
|
|
html = Regex.Replace(html, pattern, "");
|
|
|
+ string apattern = "<a([^>]{0,})></a>";
|
|
|
+ html = Regex.Replace(html, apattern, "");
|
|
|
+ //<a id="OP2_89937270DA164EFF8650A3FB645B678A" ></a>B<a id="OPTG2_89937270DA164EFF8650A3FB645B678A" ></a>
|
|
|
html = html.Replace(" close=\"\" separators=\" | \">", "");
|
|
|
html = html.Replace("\t", " ").Replace("<span>", "").Replace("</span>", "").Replace("dir=\"ltr\"", "");
|
|
|
HtmlDocument doc = new HtmlDocument();
|
|
@@ -205,6 +216,7 @@ namespace HTEXLib.Translator
|
|
|
{
|
|
|
emferror.AddRange(eferror);
|
|
|
}
|
|
|
+
|
|
|
int stIndex = conskey.Key[0]+1;
|
|
|
if (consInner.IsNotEmpty())
|
|
|
{
|
|
@@ -231,6 +243,19 @@ namespace HTEXLib.Translator
|
|
|
tagValue = Regex.Replace(tagValue, @"\s", "");
|
|
|
return tagValue;
|
|
|
}
|
|
|
+
|
|
|
+ private string BlankPointTag(string tagHtml)
|
|
|
+ {
|
|
|
+ //去掉标签中的Html
|
|
|
+ HtmlDocument doc = new HtmlDocument();
|
|
|
+ doc.LoadHtml(tagHtml);
|
|
|
+ var tagValue = doc.DocumentNode.InnerText.Replace("{", "").Replace("}", "")
|
|
|
+ .Replace("\n", " ").Replace("\t", " ").Replace("\r", " ")
|
|
|
+ .Replace(" ", " ").Replace(" ", " ").Replace(" ", " ");
|
|
|
+ // tagValue = Regex.Replace(tagValue, @"\d", "");
|
|
|
+ tagValue = Regex.Replace(tagValue, @"\s", " ");
|
|
|
+ return tagValue;
|
|
|
+ }
|
|
|
public (List<DOCX.Models.ItemInfo> ItemInfo, List<string> error) ConvertTest(string[] array, List<KeyValuePair<int[], List<ItemInfo>>> composeList) {
|
|
|
List<DOCX.Models.ItemInfo> tests = new List<DOCX.Models.ItemInfo>();
|
|
|
List<string> error = new List<string>();
|
|
@@ -242,6 +267,10 @@ namespace HTEXLib.Translator
|
|
|
string openTagVal = "";
|
|
|
bool openFlag = false;
|
|
|
string openTagLang = "";
|
|
|
+ if (array[0].Contains("EmfBase64ConvertError"))
|
|
|
+ {
|
|
|
+ error.Add(array[0]);
|
|
|
+ }
|
|
|
for (int index = 1; index < array.Length; index++) {
|
|
|
if (index % 2 == 1)
|
|
|
{
|
|
@@ -408,7 +437,8 @@ namespace HTEXLib.Translator
|
|
|
else {
|
|
|
//偶数序列为内容
|
|
|
content.Append(array[index]);
|
|
|
- if (array[index].Contains("EmfBase64ConvertError")) {
|
|
|
+ if (array[index].Contains("EmfBase64ConvertError"))
|
|
|
+ {
|
|
|
error.Add(array[index]);
|
|
|
}
|
|
|
}
|
|
@@ -421,6 +451,10 @@ namespace HTEXLib.Translator
|
|
|
return (tests,error);
|
|
|
}
|
|
|
public (List<CodeValue> options,string question) OptionProcess(string question) {
|
|
|
+ for (int idx = 0; idx < 26; idx++)
|
|
|
+ {
|
|
|
+ question = question.Replace(aza[idx], azh[idx]);
|
|
|
+ }
|
|
|
List<CodeValue> options = new List<CodeValue>();
|
|
|
string optsRgex = optionsKeys[0] + "\\s*(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?).*"; ;
|
|
|
string optsHtml = Regex.Match(question, optsRgex).Value;
|
|
@@ -448,13 +482,12 @@ namespace HTEXLib.Translator
|
|
|
return (options, question.Replace(optsHtml, ""));
|
|
|
}
|
|
|
else {
|
|
|
- return (null, question);
|
|
|
+ return (new List<CodeValue>(), question) ;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void DoOpenTag (string openTag,string openTagVal, bool openFlag, string openTagLang , StringBuilder content , DOCX.Models.ItemInfo test) {
|
|
|
if (test != null) {
|
|
|
-
|
|
|
switch (openTag) {
|
|
|
case Summary:
|
|
|
if (test.type.Equals("single") || test.type.Equals("multiple")|| test.type.Equals("judge")||test.type.Equals("sortmultiple"))
|
|
@@ -472,6 +505,10 @@ namespace HTEXLib.Translator
|
|
|
{
|
|
|
HashSet<string> ans = new HashSet<string>();
|
|
|
var anstr = BlankTag(content.ToString());
|
|
|
+ for (int idx = 0; idx < 26; idx++)
|
|
|
+ {
|
|
|
+ anstr = anstr.Replace(aza[idx], azh[idx]);
|
|
|
+ }
|
|
|
if (!test.type.Equals("judge"))
|
|
|
{
|
|
|
anstr.Select(s => s.ToString()).ToList().ForEach(x =>
|
|
@@ -518,7 +555,7 @@ namespace HTEXLib.Translator
|
|
|
break;
|
|
|
case Ended: break;
|
|
|
case Point:
|
|
|
- string Points =BlankTag(content.ToString());
|
|
|
+ string Points = BlankPointTag(content.ToString());
|
|
|
if (!string.IsNullOrWhiteSpace(Points))
|
|
|
{
|
|
|
string[] ps = Regex.Split(Points, "\\.|\\.|\\、|\\:|\\:|\\,|\\,|\\;|\\;");
|