Skip to main content

Overview

Shamela can be used in browsers with automatic CDN-hosted WASM files, or you can use the lightweight content-only export for processing pre-downloaded data.

Full API (with sql.js)

For full database functionality in the browser, the library automatically uses a CDN-hosted WASM file:
The full API includes sql.js (~900KB WASM). For content processing only, use the lightweight shamela/content export instead.

Custom CDN

You can specify a different CDN or self-hosted WASM file:

Content-Only Export (Lightweight)

If you only need content processing utilities without database functionality, use the shamela/content export:

Available Exports from shamela/content

  • parseContentRobust - Parse HTML into structured lines preserving title spans
  • mapPageCharacterContent - Normalize Arabic text with mapping rules
  • splitPageBodyFromFooter - Separate body from footnotes
  • removeArabicNumericPageMarkers - Remove page markers
  • removeTagsExceptSpan - Strip HTML except spans
  • htmlToMarkdown - Convert Shamela HTML to Markdown (title spans → ## headers)
  • normalizeHtml - Normalize hadeeth tags to standard spans
  • normalizeLineEndings - Normalize line endings to Unix-style (\n)
  • stripHtmlTags - Strip all HTML tags from content
  • normalizeTitleSpans - Handle consecutive title spans (merge, split, or hierarchy)
  • moveContentAfterLineBreakIntoSpan - Move pre-title text into the span
  • convertContentToMarkdown - Full pipeline: normalize spans → move pre-title text → convert to Markdown

Available Exports from shamela/transform

  • denormalizeBooks - Resolve relationships in MasterData to return rich book objects

Use Cases for Content-Only Export

Client-Side React/Next.js Components

Processing Pre-Downloaded Data

Bundled Environments

Avoid including sql.js in your bundle:

Content Processing Examples

Parse HTML Content

Normalize Arabic Content

Split Body and Footnotes

Convert to Markdown

Normalize Consecutive Titles

Full Markdown Pipeline

Custom Character Mapping Rules

Extend default mapping rules for custom processing:

TypeScript Support

Content utilities include full type definitions:

Browser Fetch Configuration

For older browsers or custom fetch implementations:

Bundle Size Comparison

Use shamela/content for client-side processing to keep your bundle size small.

CORS Considerations

When using the full API in browsers, ensure the Shamela API endpoints have appropriate CORS headers configured.

Best Practices

Use content-only exports for client-side components to avoid bundling sql.js.
Never expose API keys in client-side code. Proxy requests through your backend if needed.
CDN-hosted WASM is loaded automatically in browsers, but you can specify a custom URL if needed.

Next Steps

Content Processing

Deep dive into content processing utilities

Next.js Usage

Using content exports in Next.js client components