summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextmarkdownwriter.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QTextMarkdownWriter: escape all backslashesShawn Rutledge2024-03-261-9/+4
| | | | | | | | | | | | | | | | | | A literal backslash needs to be doubled so that the parser doesn't treat it as escaping the following character when the markdown is read back. In ca4774131b9b8ee40b4d7f5c1ba296af4700207f we tried to limit it to backslashes that were not already escaped. In case someone really needs a longer series of backslashes, it's more correct to escape them all; but this comes with the risk that if they do not get un-escaped by the markdown parser in some scenario, repeated round-trip saving and loading could multiply them excessively. So we also add a lot of tests to try to verify that this is safe. Task-number: QTBUG-96051 Fixes: QTBUG-122083 Pick-to: 6.7 Change-Id: I64f610d24e99f67ebdc30d5ab5c6cf3985aec5ec Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Add categorized log message in QTextMarkdownWriter::writeFrontMatter()Shawn Rutledge2024-03-051-2/+4
| | | | | | | | | | There is logging in QTextMarkdownImporter::import(); in case something goes wrong, it's useful to compare the size during reading and writing. Amends bffddc6a993c4b6b64922e8d327bdf32e0d4975a Task-number: QTBUG-120722 Change-Id: I5f60305ca84d48f91bbb18e9c10ea4010005b356 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QTextMarkdownWriter: escape special characters (line or word prefix)Shawn Rutledge2024-03-041-3/+51
| | | | | | | | | | | | | | | | | | Try to avoid writing anything that the parser would misinterpret. Escape pre-existing backslashes, but not those that are already escaped. Optimize maybeEscapeFirstChar() slightly and apply it to every line of output (except in code blocks), not only to new lines created by word-wrapping. Since it would be hard to do this without using regular expressions, the markdown writer feature now depends on the regex feature. Fixes: QTBUG-96051 Fixes: QTBUG-122083 Pick-to: 6.7 Change-Id: I8d95366501fd31441829081c668f11a3a3a23fe2 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* tst_QTextMarkdownWriter: test both ways of setting font characteristicsShawn Rutledge2024-02-141-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have explicit QFont properties, and QTextFormat::setProperty(). Setting FontFixedPitch doesn't necessarily affect the view (QTextEdit or Qt Quick Text/TextEdit); and setting the font to the one we get from QFontDatabase::systemFont(QFontDatabase::FixedFont) is also unreliable, because the "monospace" fallback might actually be proportional. QTextMarkdownWriter checks for both to decide whether to use backticks; so markdown writing works if an editor UI makes the format monospace both ways to be safe. But in the opposite case that the main font is actually a monospace font, it's always been broken. The rest of the QTextCharFormat properties are generally working, to the extent that they are applicable to Markdown. But we lacked explicit test coverage: so far we were just reading Markdown or HTML and writing Markdown to test the writer. Also amend an old comment about writing underlines: writing was always possible, and since f5c7799f59ba53c634906b11e2135190093bf87b reading is supported too. So the underline support is symmetric (except that we don't heed the QTextDocument::MarkdownFeatures argument to the writer ctor: we probably should do that some day). Pick-to: 6.7 Task-number: QTBUG-54623 Task-number: QTBUG-75648 Task-number: QTBUG-75649 Task-number: QTBUG-79900 Task-number: QTBUG-99676 Task-number: QTBUG-103484 Change-Id: Iacb4ed0ea59030570702d4eadfdadfad872065c6 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QTextMarkdownWriter: Don't word-wrap headingsShawn Rutledge2024-02-131-1/+3
| | | | | | | | | If it wraps, the text on the next line is no longer part of the heading. Fixes: QTBUG-106526 Change-Id: I8015c948d875c6944422ef3439e3128af5b2a2e2 Pick-to: 6.5 6.6 6.7 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QTextMarkdownWriter: Avoid omitting or misplacing ending indicatorsShawn Rutledge2024-02-131-2/+21
| | | | | | | | | | | | | | | | | | | | | If we need to word-wrap a paragraph after a long formatted span, write any ending markers before the newline (amends 280d679c556ab8ead4748a627d7cd4c1950027fb ). Break before a fragment if the whole thing is past the column limit; in that case, write out any ending format markers before the newline. And now we have test coverage: prepend characters one-at-a-time to a line that already has a two-word formatted span at the end, and watch it successively break after the span, in the middle, and then before, while never putting a newline before the ending markers or failing to write them. Fixes: QTBUG-116927 Change-Id: I140e10d19a491cb599bf7ecf8514af866b5383f3 Pick-to: 6.5 6.6 6.7 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QTextMarkdownWriter: Handle lists in blockquotes correctlyShawn Rutledge2024-02-131-17/+51
| | | | | | | | | | | | | | But we do not yet handle a blockquote in a list item. Presumably that's less common anyway. We now also continue block-quote prefixes onto blank lines within a block quote, which looks more normal. Pick-to: 6.7 Task-number: QTBUG-104997 Change-Id: I2b5642cf3a0c81a94444a33f026a02ad53e7e6bb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Extract and re-write "front matter" in markdown documentsShawn Rutledge2024-02-021-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Add QTextListFormat::start: html and markdown ordered list index offsetNicolas Werner2023-03-221-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | This is useful for a lot of applications that render text coming from sources which already support arbitrarily numbered lists (like chat applications for example). Application-side workarounds usually have significant overhead; and this feature has been requested multiple times. It should be possible to both read and write HTML with the <ol start="x"> attribute, and read and write Markdown with arbitrary numbers for the first item in a list. [ChangeLog][QtGui] QTextList now supports specifying a start index using the new QTextList::{setStart, start} functions. The HTML start attribute on ordered lists in rich text documents is now parsed and used when rendering a text list. Non-negative indices in markdown lists are now also parsed and written properly. This allows starting a list with a different number than 1. Fixes: QTBUG-30407 Fixes: QTBUG-65384 Task-number: QTBUG-107562 Change-Id: Ib35b9378d9134ffedaa2d92f728b0984793aa7c1 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QtGui: Disambiguate static variables in markdown codeFriedemann Kleint2023-01-311-61/+64
| | | | | | | | | | | It causes clashes in CMake Unity (Jumbo) builds. Pick-to: 6.5 Task-number: QTBUG-109394 Initial-patch-by: Amir Masoud Abdol <amir.abdol@qt.io> Change-Id: I7d8c7a15dd8d3b7198b5ac1924a0f2bcf4415e06 Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-21/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. <classes> are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Avoid crash in QTextMarkdownWriter::writeBlock()Shawn Rutledge2022-09-101-2/+2
| | | | | | | | | | The inner loop would go out of bounds whenever it tried to find the end of a run of spaces in a fragment that contained only spaces. Fixes: QTBUG-104999 Change-Id: I5dda03b31194fff12f6052c458a0eb85d0be5c2b Pick-to: 6.2 6.3 6.4 6.4.0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Emit autolinks in QTextMarkdownWriterShawn Rutledge2022-06-241-6/+12
| | | | | | | | | | | | | | | | | | | When a markdown document contains a "naked" URL, or an angle-bracketed <URL>, md4c recognizes it, and we set the AnchorHref charfmt property. There's no need to expand it into the [text](url) form if the text is the same as the url, there is no tooltip, and the url is valid. QTextMarkdownWriter now writes a CommonMark "autolink" in that case: https://spec.commonmark.org/0.30/#autolinks [ChangeLog][QtGui][Text] QTextMarkdownWriter now writes an autolink whenever a hyperlink has no custom text and no tooltip, including when the document was parsed from Markdown containing a naked URL. Pick-to: 6.4 Fixes: QTBUG-94713 Change-Id: I432db8499c62e1e0b1e913bfd8ef2147e3c2bb2a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Avoid ending Markdown fenced code blocks with gratuitous blank linesShawn Rutledge2022-05-201-2/+2
| | | | | | | | | | | | This caused unnecessary empty <pre> blocks when converting markdown to HTML, made code blocks too large using QSyntaxHighlighter to highlight the whole block, and caused assymmetry when rewriting markdown. Pick-to: 6.3 Fixes: QTBUG-101031 Change-Id: I08016577ccb92edb4afae31d7df3259cb011d5c8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Convert <pre> to Markdown ``` and vice-versa with nonBreakableLinesShawn Rutledge2022-05-191-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The HTML parser calls QTextBlockFormat::setNonBreakableLines(true) when it sees a <pre> tag; so for symmetry, the markdown reader now does the same when it sees a fenced code block, and the markdown writer honors the nonBreakableLines property by writing a fenced code block. This preserves the meaning better when reading HTML and writing markdown or vice-versa, without modifying HTML reading or writing code. Added a test tst_QTextMarkdownImporter::fencedCodeBlocks() which unfortunately also highlights a known bug in the markdown reader: each fenced code block ends with an extra empty block. That can be fixed separately. tst_QTextMarkdownWriter::fromHtml(preformats with embedded backticks) that we re-enabled in 1abaf9d5d6ea9c6554362e851903ddd214a6f659 was not a very useful test: ``` with a space and some words but no newline is not a fence: it's just like a `monospace` span. We have had trouble with those in CI because of missing monospace fonts, or inconsistency when a supposedly mono font's QFontInfo::fixedPitch() returns false. So just test proper <pre>/fence conversion for now. Pick-to: 6.3 Fixes: QTBUG-100515 Fixes: QTBUG-100981 Task-number: QTBUG-101031 Change-Id: I88f0ede0810d8a9480b30eb0cd780e1af67cc5f2 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtGui: replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-04-281-1/+1
| | | | | | Task-number: QTBUG-98434 Change-Id: I98c27030c783f968cbf38dc966ce486dc366b302 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QtGui: use _L1 for for creating Latin-1 string literalsSona Kurazyan2022-04-281-6/+8
| | | | | | Task-number: QTBUG-98434 Change-Id: Idcb71c1d27125333a53b6bdd3e1af0d4c66617fa Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QtGui: stop using QLatin1Char constructor for creating char literalsSona Kurazyan2022-04-131-18/+18
| | | | | | | | | Required for porting away from QLatin1Char/QLatin1String in scope of QTBUG-98434. Change-Id: I308d86cefcbfd126929b68f9a853d420840c965f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Use QTextCharFormat::fontFixedPitch to remember Markdown backtick spansShawn Rutledge2022-01-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | If the editing app (like qtbase/examples/widgets/richtext/textedit) has controls only for setting a specific font, and someone uses it to write markdown "from scratch", then we need to detect that they chose Courier or some other fixed-pitch font, and write the backticks, because Markdown has no syntax for selecting a specific font family. If the user loads markdown into such an application, the font is set to QFontDatabase::systemFont(QFontDatabase::FixedFont). Round-trip editing was already working, as long as such a font exists. QTextCharFormat::setFont() calls setFontFixedPitch(font.fixedPitch()), but for the chosen "mono" font, font.fixedPitch() can be false. For semantic completeness and separation of concerns, we now set fontFixedPitch explicitly if a `backtick` span is encountered. As a followup to f1e60de66540b198d696253ab5148de4fcbff319 this should get its autotest passing reliably. Fixes: QTBUG-99676 Pick-to: 6.3 6.2 5.15 Change-Id: I4987a1f0f819f82ec64546bdc3ef53e7d29933de Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Markdown writer: indent fence consistent with code blockShawn Rutledge2021-10-141-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | - Under a list item, we've been indenting code blocks: ``` int main() ... ``` - But it's also ok *not* to indent (and github handles that better): ``` int main() ... ``` - There was a bug that when the code is not indented, the fence would be indented anyway: ``` int main() ... ``` and that was not OK, neither for md4c nor for github. Now with this change, either way is rewritable: you can read markdown into QTextDocument, make small edits and write it back out again, with the indentation being preserved (the code block is either part of the list item, thus indented, or else it's outside the list completely). Pick-to: 6.2 Task-number: QTBUG-92445 Change-Id: I5f51899e28ba9f09b88a71e640d9283416cce171 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Use QList instead of QVector in gui implementationJarek Kobus2020-07-071-2/+2
| | | | | | | Task-number: QTBUG-84469 Change-Id: I366e845249203d80d640355a7780ac2f91a762f1 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtGui: fix deprecated QChar conversionsMarc Mutz2020-05-111-1/+1
| | | | | | | | | Conversions from non-char-types to QChar are going to be deprecated. Use QChar::fromUcs2(), fromUcs4(), QLatin1Char(), or convert the constructor argument to char16_t. Change-Id: Ib45ebd5560aa3a2bc460037ab09773607485c6e2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Markdown writer: omit space after opening code block fenceShawn Rutledge2020-04-201-1/+1
| | | | | | | | | | | The CommonMark spec shows that it's not necessary to have a space between the code fence and the language string: https://spec.commonmark.org/0.29/#example-112 This also avoids a needless trailing space after a code fence that does not include a language string. Change-Id: I2addd38a196045a7442150760b73269bfe4ffb22 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Markdown writer: don't wrap code block, and detect its endShawn Rutledge2020-04-201-7/+10
| | | | | | | | | | | | The end of a code block nested in a list item is now detected; and if the text of the list item continues after the code block, it continues to be indented. Code blocks should never be word-wrapped. Fixes: QTBUG-80603 Change-Id: I4427f8b1d4807d819616f5cb971e2d006170d9be Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Markdown importer: properly set hyperlinksGiuseppe D'Angelo2020-02-031-1/+75
| | | | | | | | The "title" in markdown is the tooltip, not the name attribute of a link. Also, tell the char format that it's an anchor. Change-Id: I2978848ec6705fe16376d6fe17f31007cce4b801 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QTextMarkdownWriter: preserve empty listsv5.14.0-beta3Shawn Rutledge2019-11-051-1/+2
| | | | | | | | | | You can save a "skeletal" document with list items to fill in later, the same as you can do in HTML or ODF format. Reading them back via QTextDocument::fromMarkdown() isn't always perfect though. Fixes: QTBUG-79217 Change-Id: Iacdb3e6792250ebdead05f314c9e3d00546eeb9f Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Make QTextBlockFormat::MarkerType an enum classShawn Rutledge2019-10-101-2/+2
| | | | | | | This came up during API review. Change-Id: I9198e1eb96db0c21e46a226a032919bb62d3ca66 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Fix build without features.itemmodelTasuku Suzuki2019-07-061-0/+5
| | | | | | Change-Id: I1235bed395a47438bc18571e2331a3432e274dec Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QTextMarkdownWriter: write fenced code blocks with language declarationShawn Rutledge2019-06-041-8/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MD4C now makes it possible to detect indented and fenced code blocks: https://github.com/mity/md4c/issues/81 Fenced code blocks have the advantages of being easier to write by hand, and having an "info string" following the opening fence, which is commonly used to declare the language. Also, the HTML parser now recognizes tags of the form <pre class="language-foo"> which is one convention for declaring the programming language (as opposed to human language, for which the lang attribute would be used): https://stackoverflow.com/questions/5134242/semantics-standards-and-using-the-lang-attribute-for-source-code-in-markup So it's possible to read HTML and write markdown without losing this information. It's also possible to read markdown with any type of code block: fenced with ``` or ~~~, or indented, and rewrite it the same way. Change-Id: I33c2bf7d7b66c8f3ba5bdd41ab32572f09349c47 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
* Markdown and HTML: support image alt text and titleShawn Rutledge2019-06-011-1/+9
| | | | | | | | | | | | | | | | | | | | | It's a required CommonMark feature: https://spec.commonmark.org/0.29/#images and alt text is also required in HTML: https://www.w3.org/wiki/Html/Elements/img#Requirements_for_providing_text_to_act_as_an_alternative_for_images Now we are able to read these attributes from either html or markdown and rewrite either an html or markdown document that preserves them. This patch does not add viewing or editing support in QTextEdit etc. Change-Id: I51307389f8f9fc00809808390e583a83111a7b33 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
* QTextMarkdownWriter: fix some bad cases with word wrapShawn Rutledge2019-05-241-3/+18
| | | | | | | | | | | | | | If any non-breakable content (such as a link) already went past 80 columns, or if a word ended on column 80, it didn't wrap the rest of the paragraph following. Change-Id: I27dc0474f18892c34ee2514ea6d5070dae29424f Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
* Markdown: blockquotes, code blocks, and generalized nestingShawn Rutledge2019-05-081-21/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Can now detect nested quotes and code blocks inside quotes, and can rewrite the markdown too. QTextHtmlParser sets hard-coded left and right margins, so we need to do the same to be able to read HTML and write markdown, or vice-versa, and to ensure that all views (QTextEdit, QTextBrowser, QML Text etc.) will render it with margins. But now we add a semantic memory too: BlockQuoteLevel is similar to HeadingLevel, which was added in 310daae53926628f80c08e4415b94b90ad525c8f to preserve H1..H6 heading levels, because detecting it via font size didn't make sense in QTextMarkdownWriter. Likewise detecting quote level by its margins didn't make sense; markdown supports nesting quotes; and indenting nested quotes via 40 pixels may be a bit too much, so we should consider it subject to change (and perhaps be able to change it via CSS later on). Since we're adding BlockQuoteLevel and depending on it in QTextMarkdownWriter, it's necessary to set it in QTextHtmlParser to enable HTML->markdown conversion. (But so far, nested blockquotes in HTML are not supported.) Quotes (and nested quotes) can contain indented code blocks, but it seems the reverse is not true (according to https://spec.commonmark.org/0.29/#example-201 ) Quotes can contain fenced code blocks. Quotes can contain lists. Nested lists can be interrupted with nested code blocks and nested quotes. So far the writer assumes all code blocks are the indented type. It will be necessary to add another attribute to remember whether the code block is indented or fenced (assuming that's necessary). Fenced code blocks would work better for writing inside block quotes and list items because the fence is less ambiguous than the indent. Postponing cursor->insertBlock() as long as possible helps with nesting. cursor->insertBlock() needs to be done "just in time" before inserting text that will go in the block. The block and char formats aren't necessarily known until that time. When a nested block (such as a nested quote) ends, the context reverts to the previous block format, which then needs to be re-determined and set before we insert text into the outer block; but if no text will be inserted, no new block is necessary. But we can't use QTextBlockFormat itself as storage, because for some reason bullets become very "sticky" and it becomes impossible to have plain continuation paragraphs inside list items: they all get bullets. Somehow QTextBlockFormat remembers, if we copy it. But we can create a new one each time and it's OK. Change-Id: Icd0529eb90d2b6a3cb57f0104bf78a7be81ede52 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
* Change QTextMarkdownWriter to pass by const pointer and QAIMShawn Rutledge2019-05-081-13/+13
| | | | | | | | | - QObjects are always passed by pointer not by reference, by convention - writeTable() takes QAIM rather than QATM to make testing via QStandardItemModel possible in the future Change-Id: I5bc6b8cd9709da4fb5d57d98fa22e0cb34360944 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
* Markdown: deal with horizontal rules (thematic breaks)Shawn Rutledge2019-05-081-0/+3
| | | | | Change-Id: I14d4bcfe1a6c3bd87d1328f0abb81b2138545e4e Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
* Markdown: fix several issues with lists and continuationsShawn Rutledge2019-05-081-18/+89
| | | | | | | | | | | | | | | | | | | | Importer fixes: - the first list item after a heading doesn't keep the heading font - the first text fragment after a bullet is the bullet text, not a separate paragraph - detect continuation lines and append to the list item text - detect continuation paragraphs and indent them properly - indent nested list items properly - add a test for QTextMarkdownImporter Writer fixes: - after bullet items, continuation lines and paragraphs are indented - indentation of continuations isn't affected by checkboxes - add extra newlines between list items in "loose" lists - avoid writing triple newlines - enhance the test for QTextMarkdownWriter Change-Id: Ib1dda514832f6dc0cdad177aa9a423a7038ac8c6 Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
* Prefix QTextStream operators with Qt::Lars Knoll2019-05-031-3/+3
| | | | | Change-Id: I128769cb78abb8168f0bf29cef8c693073793ced Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Add QTextMarkdownWriter::writeTable(QAbstractTableModel)Shawn Rutledge2019-05-021-0/+31
| | | | | | | | | | This provides the ability to write live data from a table to Markdown, which can be useful to load it into a text document or a wiki. But so far QTextMarkdownWriter is still a private class, intended to be used experimentally from QtQuick and perhaps later exposed in other ways. Change-Id: I0de4673987e4172178604e49b5a024a05d4486ba Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Add QTextMarkdownWriter, QTextEdit::markdown property etc.Shawn Rutledge2019-05-011-0/+363
A QTextDocument can now be written out in Markdown format. - Add the QTextMarkdownWriter as a private class for now - Add QTextDocument::toMarkdown() - QTextDocumentWriter uses QTextMarkdownWriter if setFormat("markdown") is called or if the file suffix is .md or .mkd - Add QTextEdit::toMarkdown() and the markdown property [ChangeLog][QtGui][Text] Markdown (CommonMark or GitHub dialect) is now a supported format for reading into and writing from QTextDocument. Change-Id: I663a77017fac7ae1b3f9a400f5cd357bb40750af Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>