kdenote/lib/denote_frontmatter.h

44 lines
1.2 KiB
C++

#ifndef KDENOTE_FRONTMATTER_H
#define KDENOTE_FRONTMATTER_H
#include <QString>
#include <QStringList>
namespace Denote {
/// Supported file types for frontmatter.
enum class FileType {
MdYaml, ///< Markdown with YAML frontmatter (---)
Org, ///< Org-mode (#+key: value)
Txt, ///< Plain text (title: value style)
Unknown
};
/// Parsed frontmatter from a denote note.
struct FrontMatter {
QString title;
QStringList tags;
QString identifier;
QString signature;
};
/// Detect the file type from extension.
FileType fileTypeFromExtension(const QString &ext);
/// Returns true if the extension supports frontmatter.
bool supportsFrontMatter(const QString &ext);
/// Parse frontmatter from file content.
/// Returns a default-constructed FrontMatter if none found.
FrontMatter parseFrontMatter(const QByteArray &content, FileType type);
/// Generate frontmatter content for a new file.
QByteArray marshalFrontMatter(const FrontMatter &fm, FileType type);
/// Extract the body (content after frontmatter) from file content.
QString extractBody(const QByteArray &content, FileType type);
} // namespace Denote
#endif // KDENOTE_FRONTMATTER_H