From 1b3c7b4127c2125bfa0a780d4e65703f29ab0ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20H=C3=A9rail?= Date: Wed, 25 Jan 2023 13:08:08 +0100 Subject: [PATCH] fix: Properly handle macro when extracting Metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a macro is set in the header, only the first line will be read and then discarded. This makes sure we keep the macro in and stop processing metadata when we hit a macro. Co-authored-by: Manuel RĂ¼ger --- README.md | 3 +++ pkg/mark/meta.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e70b76..f288534 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,9 @@ be replaced with specified template: --> ``` +**NOTE**: Make sure to define your macros after your metadata (Title/Space), +mark will stop processing metadata if it hits a Macro. + Capture groups can be defined in the macro's which can be later referenced in the `` using `${}` syntax, where `` is number of a capture group in regexp (`${0}` is used for entire regexp match), diff --git a/pkg/mark/meta.go b/pkg/mark/meta.go index 2f1a301..416182b 100644 --- a/pkg/mark/meta.go +++ b/pkg/mark/meta.go @@ -34,8 +34,9 @@ type Meta struct { } var ( - reHeaderPatternV1 = regexp.MustCompile(`\[\]:\s*#\s*\(([^:]+):\s*(.*)\)`) - reHeaderPatternV2 = regexp.MustCompile(``) + reHeaderPatternV1 = regexp.MustCompile(`\[\]:\s*#\s*\(([^:]+):\s*(.*)\)`) + reHeaderPatternV2 = regexp.MustCompile(``) + reHeaderPatternMacro = regexp.MustCompile(`