Skip to content

Commit

Permalink
解决文件末尾多余空行的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleBing committed Apr 22, 2024
1 parent daf0e8f commit 7ae04d1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v1.26 `2024-04-22`
- 去除生成 yamlString 时末尾多余的空行,改用 `Array.join(EOL)`

## v1.25 `2024-01-27`
- 筛选单字编码错误的、纠正单字错误的。
- 可用于生成其它版本的五笔码表。
Expand Down
29 changes: 17 additions & 12 deletions js/Dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,20 +378,25 @@ class Dict {
toYamlString(){
let yamlBody = ''
if (this.isGroupMode){
this.wordsOrigin.forEach(group => {
let tempGroupString = ''
tempGroupString = tempGroupString + `## ${group.groupName}${EOL}` // + groupName
group.dict.forEach(item =>{
tempGroupString = tempGroupString + item.toYamlString() + EOL
})
yamlBody = yamlBody + tempGroupString + EOL // 每组的末尾加个空行
})
// 为了避免最后多出的空格,改用 join
let tempGroupString =
this.wordsOrigin
.map(group => {
let tempGroupString = ''
tempGroupString = tempGroupString + `## ${group.groupName}${EOL}` // + groupName
let groupWordsYamlStringArray = group.dict.map(item => item.toYamlString())
return tempGroupString + groupWordsYamlStringArray.join(EOL)
})
.join(EOL + EOL)
yamlBody = yamlBody + tempGroupString // 每组的末尾加个空行
return this.header + EOL + yamlBody
} else {
let yamlBody = ''
this.wordsOrigin.forEach(item =>{
yamlBody = yamlBody + item.toYamlString() + EOL
})
let yamlBody =
this.wordsOrigin
.map(item => {
return item.toString()
})
.join(EOL)
return this.header + EOL + yamlBody
}
}
Expand Down
11 changes: 5 additions & 6 deletions js/DictOther.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,18 @@ class DictOther {
}



// 删除词条
deleteWords(wordIdSet){
this.wordsOrigin = this.wordsOrigin.filter(item => !wordIdSet.has(item.id))
}

// 转为 String
toYamlString(){
let fileContentString = ''
this.wordsOrigin.forEach(item =>{
fileContentString = fileContentString + item.toYamlString() + EOL
})
return fileContentString
return this.wordsOrigin
.map(item => {
item.toYamlString()
})
.join(EOL)
}

toExportString(seperator, dictFormat){
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "wubi-dict-editor",
"version": "1.2.5",
"version": "1.2.6",
"private": true,
"author": {
"name": "KyleBing",
"email": "[email protected]"
},
"date": "2024-01-27",
"date": "2024-04-22",
"dateInit": "2021-07-24",
"description": "五笔码表管理工具",
"main": "main.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
"config": {
"forge": {
"packagerConfig": {
"appVersion": "1.2.5",
"appVersion": "1.2.6",
"name": "五笔码表助手",
"appCopyright": "[email protected]",
"icon": "./assets/img/appIcon/appicon",
Expand Down

0 comments on commit 7ae04d1

Please sign in to comment.