-
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.
Merge pull request #757 from friendsofagape/ft/tsvObsNotes_support
Ft/tsv obs notes support
- Loading branch information
Showing
4 changed files
with
77 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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
// filter current chapter data from whole TSV JSON and generate array of notes of md content | ||
// based on reference of tsv | ||
import * as logger from '../../../../logger'; | ||
|
||
export default async function ObsTsvToChapterLevelMd(tsvJSON, chapter) { | ||
return new Promise((resolve) => { | ||
logger.debug('in ObsTsvToChapterLevel.js : in promise'); | ||
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) { | ||
logger.debug('in ObsTsvToChapterLevel.js : finished tsv md array resolved'); | ||
resolve(chapterTsvData); | ||
} | ||
}); | ||
} |
23 changes: 23 additions & 0 deletions
23
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,23 @@ | ||
// convert TSV to line by line json | ||
import * as logger from '../../../../logger'; | ||
|
||
export default async function tsvJSON(tsv) { | ||
const lines = tsv.split('\n'); | ||
logger.debug('in TsvToJson.js : in convert function'); | ||
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); | ||
} | ||
logger.debug('in TsvToJson.js : in convert function , Finished'); | ||
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