-
-
Notifications
You must be signed in to change notification settings - Fork 278
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 #1984 from Sefaria/bug/sc-28448/new-editor-inconsi…
…stency-verse-numbers Bug/sc 28448/new editor inconsistency verse numbers
- Loading branch information
Showing
4 changed files
with
167 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Sefaria from "../static/js/sefaria/sefaria"; | ||
|
||
export async function getSegmentObjs(refs) { | ||
/* | ||
Given an array of ref-strings (could also be ranged refs), | ||
turn each ref to segment object and return an array of all segments | ||
*/ | ||
const segments = []; | ||
|
||
for (const ref of refs) { | ||
const text = await Sefaria.getText(ref, { stripItags: 1 }); | ||
const newSegments = Sefaria.makeSegments(text, false); | ||
segments.push(...newSegments); | ||
} | ||
return segments; | ||
} | ||
export async function getNormalRef(ref) { | ||
/* | ||
Given a ref-string, get he and en normal ref-string | ||
*/ | ||
const refObj = await Sefaria.getRef(ref); | ||
return {en: refObj.ref, he: refObj.heRef} | ||
} | ||
function placedSegmentMapper(lang, segmented, includeNumbers, s) { | ||
/* | ||
Map each segment object to a formatted text string | ||
*/ | ||
if (!s[lang]) {return ""} | ||
|
||
let numStr = ""; | ||
if (includeNumbers) { | ||
const num = (lang=="he") ? Sefaria.hebrew.encodeHebrewNumeral(s.number) : s.number; | ||
numStr = "<small>(" + num + ")</small> "; | ||
} | ||
let str = "<span class='segment'>" + numStr + s[lang] + "</span> "; | ||
if (segmented) { | ||
str = "<p>" + str + "</p>"; | ||
} | ||
str = str.replace(/(<br\/>)+/g, ' ') | ||
return str; | ||
} | ||
export const segmentsToSourceText = (segments, lan) => { | ||
/* | ||
Turn array of segment objects into one chunk of formatted text | ||
*/ | ||
const segmented = shouldBeSegmented(segments[0].ref); | ||
const includeNumbers = shouldIncludeSegmentNums(segments[0].ref); | ||
return(segments.map(placedSegmentMapper.bind(this, lan, segmented, includeNumbers)) | ||
.filter(Boolean) | ||
.join("")); | ||
} | ||
function shouldIncludeSegmentNums(ref){ | ||
/* | ||
Decide if segment of this ref should have segment numbers when turned into text chunk | ||
*/ | ||
const indexTitle = Sefaria.refIndexTitle(ref); | ||
const categories = Sefaria.refCategories(ref); | ||
if (categories.includes("Talmud")) {return false} | ||
if (indexTitle === "Pesach Haggadah") {return false} | ||
if (categories === 1) {return false} | ||
return true; | ||
} | ||
function shouldBeSegmented(ref){ | ||
/* | ||
Decide if segment of this ref should be followed by new line when turned into text chunk | ||
*/ | ||
const categories = Sefaria.refCategories(ref); | ||
return !(categories[0] in {"Tanakh": 1, "Talmud": 1}); | ||
} |
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
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
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