OPML Reference
OPML (Outline Processor Markup Language) is a format for exchanging outline-structured information, commonly used for sharing feed subscription lists.
| Versions | 1.0, 2.0 |
|---|
Functions
parseOpml()
Parses OPML content and returns a typed OPML object.
import { parseOpml } from 'feedsmith'
const opml = parseOpml(xmlContent, {
extraOutlineAttributes: ['customIcon', 'updateInterval']
})
// Returns: object with all fields optional and dates as strings
// Limit number of outlines parsed
const opml = parseOpml(xmlContent, { maxItems: 5 })
// Combine both options
const opml = parseOpml(xmlContent, {
maxItems: 5,
extraOutlineAttributes: ['customIcon', 'updateInterval']
})Parameters
| Parameter | Type | Description |
|---|---|---|
content | string | The OPML XML content to parse |
options | object | Optional parsing settings |
Options
| Option | Type | Default | Description |
|---|---|---|---|
maxItems | number | - | Limit the number of outlines parsed. Use 0 to skip outlines entirely, useful when only OPML metadata is needed |
extraOutlineAttributes | string[] | - | Custom attributes to extract from outline elements (case-insensitive), see examples |
Returns
object - Parsed OPML with all fields optional and dates as strings
generateOpml()
Generates OPML XML from OPML data.
import { generateOpml } from 'feedsmith'
const xml = generateOpml(opmlData, {
lenient: true,
stylesheets: [{ type: 'text/xsl', href: '/opml.xsl' }],
extraOutlineAttributes: ['customIcon', 'updateInterval']
})Parameters
| Parameter | Type | Description |
|---|---|---|
data | object | OPML data to generate |
options | object | Optional generation settings |
Options
| Option | Type | Default | Description |
|---|---|---|---|
lenient | boolean | false | Enable lenient mode for relaxed validation, see Lenient Mode |
stylesheets | Stylesheet[] | - | Add stylesheets for visual formatting, see Feed Styling |
extraOutlineAttributes | string[] | - | Custom attributes to include in outline elements. Only specified attributes are included in generated XML, see examples |
Returns
string - Generated OPML XML
Types
All OPML types are available under the Opml namespace:
import type { Opml } from 'feedsmith/types'
// Access any type from the definitions below
type Document = Opml.Document<Date>
type Head = Opml.Head<Date>
type Body = Opml.Body<Date>
type Outline = Opml.Outline<Date>
// … see type definitions below for all available typesSee the TypeScript guide for usage examples.
Type Definitions
INFO
TDate represents date fields in the type definitions. When parsing, dates are returned as strings in their original format (see Parsing › Handling Dates for more details). When generating, dates should be provided as JavaScript Date objects.
export namespace Opml {
export type Outline<
TDate extends DateLike,
A extends ReadonlyArray<string> = ReadonlyArray<string>,
> = {
text: string
type?: string
isComment?: boolean
isBreakpoint?: boolean
created?: TDate
category?: string
description?: string
xmlUrl?: string
htmlUrl?: string
language?: string
title?: string
version?: string
url?: string
outlines?: Array<Outline<TDate, A>>
} & ExtraFields<A>
export type Head<TDate extends DateLike> = {
title?: string
dateCreated?: TDate
dateModified?: TDate
ownerName?: string
ownerEmail?: string
ownerId?: string
docs?: string
expansionState?: Array<number>
vertScrollState?: number
windowTop?: number
windowLeft?: number
windowBottom?: number
windowRight?: number
}
export type Body<
TDate extends DateLike,
A extends ReadonlyArray<string> = ReadonlyArray<string>,
> = {
outlines?: Array<Outline<TDate, A>>
}
export type Document<
TDate extends DateLike,
A extends ReadonlyArray<string> = ReadonlyArray<string>,
> = {
head?: Head<TDate>
body?: Body<TDate, A>
}
}INFO
The Outline type includes an index signature [key: string]: unknown which allows storing any custom attributes alongside the standard OPML properties.