Skip to content

Commit

Permalink
Allows you to use ... to end the yaml header block.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarex committed Feb 23, 2022
1 parent 1f5ee72 commit 802dda7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).**
Expand Down
16 changes: 8 additions & 8 deletions QLMarkdown.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = "";
Expand All @@ -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 = (
Expand All @@ -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 = "";
Expand Down Expand Up @@ -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)";
Expand All @@ -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 = "";
Expand All @@ -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)";
Expand All @@ -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 = "";
Expand Down
8 changes: 7 additions & 1 deletion QLMarkdown/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions QLMarkdown/test1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 802dda7

Please sign in to comment.