From 802dda7ff42c4bc7d1a8a3a3c6be22c4890f1111 Mon Sep 17 00:00:00 2001 From: sbarex Date: Wed, 23 Feb 2022 08:37:55 +0100 Subject: [PATCH] Allows you to use `...` to end the `yaml` header block. --- CHANGELOG.md | 5 +++++ QLMarkdown.xcodeproj/project.pbxproj | 16 ++++++++-------- QLMarkdown/Settings.swift | 8 +++++++- QLMarkdown/test1.md | 4 ++-- README.md | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10971b7..a1feb7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog + +### 1.0.14 (39) +Bugfix: +- Allows you to use `...` to end the `yaml` header block. + ### 1.0.13 (38) Bugfix: - Fixed the Sparkle integration bug. **If you have installed version 1.0.11 or 1.0.12 you may need to [re-download the updated app from the web](https://github.com/sbarex/QLMarkdown/releases/download/1.0.13/QLMarkdown.zip).** diff --git a/QLMarkdown.xcodeproj/project.pbxproj b/QLMarkdown.xcodeproj/project.pbxproj index 233c024..015e5e5 100644 --- a/QLMarkdown.xcodeproj/project.pbxproj +++ b/QLMarkdown.xcodeproj/project.pbxproj @@ -1433,7 +1433,7 @@ CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements; CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 38; + CURRENT_PROJECT_VERSION = 39; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = NO; HEADER_SEARCH_PATHS = ( @@ -1453,7 +1453,7 @@ "$(BUILT_PRODUCTS_DIR)/libpcre2/lib", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.0.13; + MARKETING_VERSION = 1.0.14; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown.QLExtension; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1470,7 +1470,7 @@ CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements; CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 38; + CURRENT_PROJECT_VERSION = 39; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = NO; HEADER_SEARCH_PATHS = ( @@ -1490,7 +1490,7 @@ "$(BUILT_PRODUCTS_DIR)/libpcre2/lib", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.0.13; + MARKETING_VERSION = 1.0.14; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown.QLExtension; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1684,7 +1684,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 38; + CURRENT_PROJECT_VERSION = 39; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = NO; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -1706,7 +1706,7 @@ "$(BUILT_PRODUCTS_DIR)/libpcre2/lib", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.0.13; + MARKETING_VERSION = 1.0.14; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1727,7 +1727,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 38; + CURRENT_PROJECT_VERSION = 39; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = NO; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -1749,7 +1749,7 @@ "$(BUILT_PRODUCTS_DIR)/libpcre2/lib", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.0.13; + MARKETING_VERSION = 1.0.14; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/QLMarkdown/Settings.swift b/QLMarkdown/Settings.swift index 031df75..976a2bc 100644 --- a/QLMarkdown/Settings.swift +++ b/QLMarkdown/Settings.swift @@ -640,7 +640,13 @@ class Settings { var header = "" if self.yamlExtension && (self.yamlExtensionAll || filename.lowercased().hasSuffix("rmd")) && md_text.hasPrefix("---") { - let pattern = "(?s)((?<=---\n).*?(?>\n---\n))" + /* + (?s): Turn on "dot matches newline" for the remainder of the regular expression. For “single line mode” makes the dot match all characters, including line breaks. + (?<=---\n): Positive lookbehind. Matches at a position if the pattern inside the lookbehind can be matched ending at that position. Find expression .* where expression `---\n` precedes. + (?>\n(?:---|\.\.\.): + (?:---|\.\.\.): not capturing group + */ + let pattern = "(?s)((?<=---\n).*?(?>\n(?:---|\\.\\.\\.)\n))" if let range = md_text.range(of: pattern, options: .regularExpression) { let yaml = String(md_text[range.lowerBound ..< md_text.index(range.upperBound, offsetBy: -4)]) var isHTML = false diff --git a/QLMarkdown/test1.md b/QLMarkdown/test1.md index 9893d4d..bf3b85c 100644 --- a/QLMarkdown/test1.md +++ b/QLMarkdown/test1.md @@ -6,9 +6,9 @@ Abstract: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusm output: pdf_document: default html_notebook: default ---- +... -The previous block placed at the top of the document and contained between the markers `---` is displayed as the file header when the `YAML` extension is enabled. With the `table` extension on, it is displayed as a table otherwise as a block of code. +The previous block placed at the top of the document, starting with `---` and ending with `---` or `...` is displayed as the file header when the `YAML` extension is enabled. With the `table` extension on, it is displayed as a table otherwise as a block of code. # TOC diff --git a/README.md b/README.md index aba5f48..f8a5738 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ If no language is defined and the guessing fail (or is not enabled), the code is In the [Advanced options panel](#advanced-options), you can enable the extension to handle a `yaml` header at the beginning of a file. You can choose to enable the extensions to all `.md` files or only for `.rmd` files. -The header is recognized only if the file start with `---`. +The header is recognized only if the file start with `---`. The yaml block must be closed with `---` or with `...`. When the `table` extension is enabled, the header is rendered as a table, otherwise as a block of code. Nested tables are supported.