Skip to main content

Overview

Separates page body content from trailing footnotes using a marker string. Shamela pages often contain both main content and footnotes separated by a specific marker.

Signature

splitPageBodyFromFooter(
  content: string,
  footnoteMarker?: string
): readonly [string, string]

Parameters

content
string
required
Combined body and footnote text
footnoteMarker
string
Marker indicating the start of footnotes. Defaults to FOOTNOTE_MARKER constant from the library.

Returns

[body, footnote]
[string, string]
A tuple containing:

Behavior

  • If the marker is not found, returns the entire content as body with an empty footnote string
  • The marker itself is excluded from both the body and footnote sections
  • Returns a readonly tuple for type safety

Example

import { splitPageBodyFromFooter } from 'shamela';

const pageContent = `
متن الكتاب وهو النص الأساسي
الذي يحتوي على المحتوى الرئيسي

[FOOTNOTE_MARKER]

[١] هذه هي الحاشية الأولى
[٢] وهذه الحاشية الثانية
`;

const [body, footnotes] = splitPageBodyFromFooter(pageContent);

console.log('Body:', body);
// => "متن الكتاب وهو النص الأساسي\nالذي يحتوي على المحتوى الرئيسي"

console.log('Footnotes:', footnotes);
// => "[١] هذه هي الحاشية الأولى\n[٢] وهذه الحاشية الثانية"

Processing Pipeline

Typical usage in a content processing pipeline:
import {
  mapPageCharacterContent,
  splitPageBodyFromFooter,
  removeTagsExceptSpan,
} from 'shamela';

// 1. Normalize content
let content = mapPageCharacterContent(rawContent);

// 2. Remove unwanted tags
content = removeTagsExceptSpan(content);

// 3. Split body from footnotes
const [body, footnotes] = splitPageBodyFromFooter(content);

// 4. Process each part separately
processBody(body);
processFootnotes(footnotes);