Closed anqi-j closed 2 years ago
Hi, thank you for your feedback and effort to code your suggestion! Maybe just split your suggestions into multiple issues next time, so it is easier to reply/follow up on each one. Also please use code blocks for code so it is easier to read 😄
The array variable headings may start from 0, instead of 1, like Python. Whenever there is headings[verseNumber/beginVerse/endVerse], you might want to -1 for the indexing.
We can define bookChapter - majorSeparator - beginVerse - minorSeparator - endVerse. It would be great to pass down the separators in the input to the output, such as ":".
If there is only 1 verse quoted, we may want "Gen1,1" instead of "Gen1,1-1".
I don't see the necessity to append invisible links like [[Gen1#2|]] at the end, because Obsidian does not have backlink tracking for the headings (only the whole file), as I know of. If you see the value of keeping it, could you make it a toggle setting?
Implemented in version 1.1.0 (verse offset can be changed in settings)
Hi, Kuchejak! Sorry to bother you again.
I found a few places available for perfection. I tried to modify the code to relieve your workload. However, I don't know how to use typescript well yet. I attached the main.js code as below. I am sorry for my inability to do a pull request.
Example:
Input
Gen1:1
Output
[[Gen1#2|Gen1,1-1]] but actually Verse 2! [[Gen1#2|]]
Potential improvements
Attempts to fix
link-regexes.ts
add parentheses to retrieve the major and minor separators
var oneVerseRegEx = new RegExp(/([a-zA-Z0-9\s.ěščřžýáíé]+)([,#.:;])(\d+)$/); var multipleVersesRegEx = new RegExp( /([a-zA-Z0-9\s.ěščřžýáíé]+)([,#.:;])(\d+)\s([-.=])\s(\d+)$/ );
convert-link.ts > convertLinkToQuote
catch up the major and minor separators
let majorSeparator; let minorSeparator;
case oneVerseRegEx.test(userInput): { const [_, matchedChapter, matchedMajorSeparator, matchedVerse] = userInput.match(oneVerseRegEx); bookAndChapter = matchedChapter; majorSeparator = matchedMajorSeparator; beginVerse = Number(matchedVerse); endVerse = Number(matchedVerse); break; } case multipleVersesRegEx.test(userInput): { const [ _, matchedChapter, matchedMajorSeparator, matchedBeginVerse, matchedMinorSeparator, matchedEndVerse, ] = userInput.match(multipleVersesRegEx); bookAndChapter = matchedChapter; majorSeparator = matchedMajorSeparator; beginVerse = Number(matchedBeginVerse); minorSeparator = matchedMinorSeparator; endVerse = Number(matchedEndVerse); break; }
if (tFile) { return yield createLinkOutput( ... majorSeparator, minorSeparator, ... );
convert-link.ts > getVerseText
get the correct range of verses
const headingLine = headings[verseNumber - 1].position.start.line;
convert-link.ts > createLinkOutput
Delete or toggle the invisible links
for (let i = beginVerse; i <= endVerse; i++) { res +=
[[${fileName}#${headings[i].heading}|]]
; }Achieve desired formats
... let res = settings.prefix; if (beginVerse == endVerse) { res +=
[[${fileName}#${ headings[beginVerse - 1].heading }|${fileName}${majorSeparator}${beginVerse}]]
; } else { if (settings.linkEndVerse) { res +=[[${fileName}#${ headings[beginVerse - 1].heading }|${fileName}${majorSeparator}${beginVerse}]]
; res +=[[${fileName}#${ headings[endVerse - 1].heading }|${minorSeparator}${endVerse}]]
; } else { res +=[[${fileName}#${ headings[beginVerse - 1].heading }|${fileName}${majorSeparator}${beginVerse}${minorSeparator}${endVerse}]]
; } } ...What this achieves is consistent with the input-output pairs below:
A tentative test
One verse
Gen1,1 [[Gen1#1|Gen1,1]] In the beginning God created the heavens and the earth. Gen1:1 [[Gen1#1|Gen1:1]] In the beginning God created the heavens and the earth.
Multiple verses + With a link to the last verse
Gen1,1-3
[[Gen1#1|Gen1,1]][[Gen1#3|-3]] In the beginning God created the heavens and the earth. Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters. And God said, "Let there be light," and there was light.
Gen1:1=3
[[Gen1#1|Gen1:1]][[Gen1#3|=3]] In the beginning God created the heavens and the earth. Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters. And God said, "Let there be light," and there was light.
Multiple verses + Without a link to the last verse
Gen1,1-3
[[Gen1#1|Gen1,1-3]] In the beginning God created the heavens and the earth. Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters. And God said, "Let there be light," and there was light.
Gen1:1=3
[[Gen1#1|Gen1:1=3]] In the beginning God created the heavens and the earth. Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters. And God said, "Let there be light," and there was light.
Thank you!