summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocument.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2024-01-10 12:45:33 -0700
committerShawn Rutledge <shawn.rutledge@qt.io>2024-02-02 20:14:28 -0700
commitbffddc6a993c4b6b64922e8d327bdf32e0d4975a (patch)
tree37187f42d569be9a9eaf7b1235782972ca4e84b6 /src/gui/text/qtextdocument.cpp
parent216af5d7f9675a408e22167b097f221beeeb88db (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/qtextdocument.cpp')
-rw-r--r--src/gui/text/qtextdocument.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index df00c809d1..38279b3064 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -1159,6 +1159,8 @@ QString QTextDocument::metaInformation(MetaInformation info) const
return d->url;
case CssMedia:
return d->cssMedia;
+ case FrontMatter:
+ return d->frontMatter;
}
return QString();
}
@@ -1182,6 +1184,9 @@ void QTextDocument::setMetaInformation(MetaInformation info, const QString &stri
case CssMedia:
d->cssMedia = string;
break;
+ case FrontMatter:
+ d->frontMatter = string;
+ break;
}
}
@@ -1327,6 +1332,10 @@ void QTextDocument::setHtml(const QString &html)
\value CssMedia This value is used to select the corresponding '@media'
rule, if any, from a specified CSS stylesheet when setHtml()
is called. This enum value has been introduced in Qt 6.3.
+ \value FrontMatter This value is used to select header material, if any was
+ extracted during parsing of the source file (currently
+ only from Markdown format). This enum value has been
+ introduced in Qt 6.8.
\sa metaInformation(), setMetaInformation(), setHtml()
*/