-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
renderer/src/components/EditorPage/Reference/OBS/ObsTsvToChapterLevel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// filter current chapter data from whole TSV JSON and generate array of notes of md content | ||
// based on reference of tsv | ||
|
||
export default async function ObsTsvToChapterLevelMd(tsvJSON, chapter) { | ||
return new Promise((resolve) => { | ||
const filteredData = tsvJSON.filter((data) => data.Reference.split(':')[0].toString() === chapter.toString()); | ||
const chapterTsvData = []; | ||
const notesObj = {}; | ||
filteredData.forEach((tsvObj) => { | ||
let mdstring = ''; | ||
mdstring += `# ${ tsvObj.Quote }\n\n${ tsvObj.Note }\n`; | ||
if (tsvObj.Reference.split(':')[1] in notesObj) { | ||
notesObj[tsvObj.Reference.split(':')[1]].OccurrenceNote += mdstring; | ||
} else { | ||
notesObj[tsvObj.Reference.split(':')[1]] = { OccurrenceNote: mdstring }; | ||
} | ||
}); | ||
Object.values(notesObj).forEach((value) => { | ||
chapterTsvData.push(value); | ||
}); | ||
if (chapterTsvData?.length > 0) { | ||
resolve(chapterTsvData); | ||
} | ||
}); | ||
} |
20 changes: 20 additions & 0 deletions
20
renderer/src/components/EditorPage/Reference/OBS/TsvToJson.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default async function tsvJSON(tsv) { | ||
const lines = tsv.split('\n'); | ||
|
||
const result = []; | ||
|
||
const headers = lines[0].split('\t'); | ||
|
||
for (let i = 1; i < lines.length; i++) { | ||
const obj = {}; | ||
const currentline = lines[i].split('\t'); | ||
|
||
for (let j = 0; j < headers.length; j++) { | ||
obj[headers[j]] = currentline[j]; | ||
} | ||
|
||
result.push(obj); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters