יחידה:מקרא

מתוך חב"דטקסט, מאגר טקסטים חב"דים חופשיים
גרסה מ־11:34, 30 בנובמבר 2026 מאת שיע בוט (שיחה | תרומות) (יחידת תצוגת מקרא למהדורות כתיב, ניקוד וטעמים)
(הבדל) → הגרסה הקודמת | הגרסה האחרונה (הבדל) | הגרסה הבאה ← (הבדל)
קפיצה לניווט קפיצה לחיפוש

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:מקרא/תיעוד

local p = {}

local function chapterData(frame)
    return mw.loadData('Module:מקרא/' .. frame.args[1])
end

local function displayText(text, edition, fullName, largeInitial)
    if not fullName then
        if edition == 'כתיב' then
            text = text:gsub('אלהים', 'אלוקים')
        else
            text = text:gsub('אֱלֹה', 'אֱלֹק')
        end
    end

    if largeInitial then
        local first = edition == 'כתיב' and 'ב' or 'בְּ'
        if text:sub(1, #first) == first then
            text = '<big>' .. first .. '</big>' .. text:sub(#first + 1)
        end
    end
    return text
end

function p.verse(frame)
    local data = chapterData(frame)
    local verseNumber, edition = frame.args[2], frame.args[3]
    for _, record in ipairs(data.verses) do
        if record.number == verseNumber then
            local text = assert(record[edition], 'מהדורת מקרא לא מוכרת')
            return displayText(text, edition, frame.args[4] == 'מקור', record.largeInitial)
        end
    end
    error('פסוק לא נמצא בפרק')
end

local headings = {
    {'כתיב', 'כתיב (אותיות בלבד)'},
    {'ניקוד', 'מנוקד'},
    {'שורות', 'מנוקד בשורות'},
    {'טעמים', 'עם טעמי המקרא'},
}

function p.chapter(frame)
    local data = chapterData(frame)
    local view = frame.args[2]
    local edition = view == 'שורות' and 'ניקוד' or view
    local style = [[font-family: SBL Hebrew, Ezra SIL, Noto Serif Hebrew, serif; font-size:1.35em; line-height:1.8]]
    local lines = {
        '[[' .. data.book .. '|ספר ' .. data.book .. ']] • פרק ' .. data.number .. ' • [[' .. data.nextChapter .. '|הפרק הבא]]',
        '',
    }

    local navigation = {}
    for _, item in ipairs(headings) do
        local destination, label = unpack(item)
        navigation[#navigation + 1] = destination == view and label or
            '[[' .. data.chapter .. '/' .. destination .. '|' .. label .. ']]'
    end
    lines[#lines + 1] = table.concat(navigation, ' • ')
    lines[#lines + 1] = ''
    lines[#lines + 1] = '<div class="ct-mikra-editions" lang="hbo" style="' .. style .. '">'

    for index, record in ipairs(data.verses) do
        local number = record.number
        local text = assert(record[edition], 'מהדורת מקרא לא מוכרת')
        local alias = displayText(text, edition, false, record.largeInitial)
        local source = displayText(text, edition, true, record.largeInitial)
        local label = data.number .. '_' .. number
        local target = '[[:קטגוריה:' .. data.chapter .. ' ' .. number .. '|' .. number .. ']]'
        local verse = '<span id="' .. label .. '"></span><span id="' .. number .. '"></span>'
        if edition == 'טעמים' and record.aliyah then
            verse = verse .. '<small>[' .. record.aliyah .. ']</small> '
        end
        verse = verse .. '<small>' .. target .. '</small> '
        if alias ~= source then
            verse = verse .. '<span class="ct-mikra-alias">' .. alias ..
                '</span><span class="ct-mikra-source" style="display:none">' .. source .. '</span>'
        else
            verse = verse .. source
        end
        lines[#lines + 1] = verse
        if data.verses[index + 1] ~= nil and (view == 'שורות' or record.paragraphEnd) then
            lines[#lines + 1] = ''
        end
    end
    lines[#lines + 1] = '</div>'
    return table.concat(lines, '\n')
end

return p