diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-01-10 12:45:33 -0700 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-02-02 20:14:28 -0700 |
commit | bffddc6a993c4b6b64922e8d327bdf32e0d4975a (patch) | |
tree | 37187f42d569be9a9eaf7b1235782972ca4e84b6 /src/gui/text/qtextmarkdownimporter_p.h | |
parent | 216af5d7f9675a408e22167b097f221beeeb88db (diff) |
Extract and re-write "front matter" in markdown documents
It's increasingly common for YAML to be used as metadata in front of
markdown documents. md4c does not handle this, so we need to remove
it ahead of time, lest md4c misinterpret it as heading text or so.
The --- fences are expected to be consistent regardless of the format of
what's between them, and the yaml (or whatever) parser does not need to
see them. So we remove them while reading, and QTextMarkdownWriter
writes them around the front matter if there is any.
If your application needs to parse this "front matter", just call
qtd->metaInformation(QTextDocument::FrontMatter).toUtf8() and feed that
to some parser that you've linked in, such as yaml-cpp.
Since YAML is used with GitHub Docs, we consider this feature to be part
of the GitHub dialect:
https://docs.github.com/en/contributing/writing-for-github-docs/using-yaml-frontmatter
[ChangeLog][QtGui][Text] Markdown "front matter" (usually YAML) is now
extracted during parsing (GitHub dialect) and can be retrieved from
QTextDocument::metaInformation(FrontMatter). QTextMarkdownWriter also
writes front matter (if any) to the output.
Fixes: QTBUG-120722
Change-Id: I220ddcd2b94c99453853643516ca7a36bb2bcd6f
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/gui/text/qtextmarkdownimporter_p.h')
-rw-r--r-- | src/gui/text/qtextmarkdownimporter_p.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/gui/text/qtextmarkdownimporter_p.h b/src/gui/text/qtextmarkdownimporter_p.h index 89e0ab4ad1..8b8f4ec9bb 100644 --- a/src/gui/text/qtextmarkdownimporter_p.h +++ b/src/gui/text/qtextmarkdownimporter_p.h @@ -46,6 +46,7 @@ public: FeaturePermissiveWWWAutoLinks = 0x0400, FeatureTasklists = 0x0800, FeatureUnderline = 0x4000, + FeatureFrontMatter = 0x100000, // Qt feature, not yet in MD4C // composite flags FeaturePermissiveAutoLinks = FeaturePermissiveMailAutoLinks | FeaturePermissiveURLAutoLinks | FeaturePermissiveWWWAutoLinks, |