Table of Contents

Method CanRead

Namespace
DocWright.Formats.Markdown
Assembly
DocWright.Formats.Markdown.dll

CanRead(Stream)

Sniffs whether a stream looks like Markdown, restoring its position before returning.

public bool CanRead(Stream stream)

Parameters

stream Stream

The seekable stream to sniff.

Returns

bool

true when the stream carries a Markdown-only construct.

Remarks

Markdown has no signature, and every plain-text file is valid Markdown — so a sniff that accepted anything decodable would claim every stream no other reader recognized, and a corrupt DOCX would silently become a document full of mojibake instead of an error. The probe therefore requires a positive signal: an ATX heading, a fenced code block, a setext underline, a thematic break, a list marker or a link reference definition at the start of a line within the first four kilobytes.

The consequence is stated rather than hidden: a Markdown file that is nothing but prose is not auto-detected. It loads by extension or by passing FormatDetection.Markdown, and reading it as plain text would in any case have produced the same document.

Exceptions

ArgumentNullException

stream is null.

ArgumentException

The stream is not seekable.