From d31a96a3c036472fdaff3262a795dc993de04e95 Mon Sep 17 00:00:00 2001
From: Donald Hunter
Date: Wed, 22 May 2024 19:39:21 +0100
Subject: [PATCH 1/4] Include file name in parse error message
Signed-off-by: Donald Hunter
---
org/document.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/org/document.go b/org/document.go
index 7357fda..8dba04f 100644
--- a/org/document.go
+++ b/org/document.go
@@ -241,7 +241,7 @@ func (d *Document) parseOne(i int, stop stopFn) (consumed int, node Node) {
if consumed != 0 {
return consumed, node
}
- d.Log.Printf("Could not parse token %#v: Falling back to treating it as plain text.", d.tokens[i])
+ d.Log.Printf("Could not parse token %#v in file %s: Falling back to treating it as plain text.", d.tokens[i], d.Path)
m := plainTextRegexp.FindStringSubmatch(d.tokens[i].matches[0])
d.tokens[i] = token{"text", len(m[1]), m[2], m}
return d.parseOne(i, stop)
From 5f599b9e668bcfc5fac3591c6fdaa9aed733b3b2 Mon Sep 17 00:00:00 2001
From: Donald Hunter
Date: Wed, 22 May 2024 19:38:38 +0100
Subject: [PATCH 2/4] Honour org :noweb strip-export parameter when writing
HTML
Signed-off-by: Donald Hunter
---
org/html_writer.go | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/org/html_writer.go b/org/html_writer.go
index a12d4bf..ca9ffb2 100644
--- a/org/html_writer.go
+++ b/org/html_writer.go
@@ -152,6 +152,10 @@ func (w *HTMLWriter) WriteBlock(b Block) {
if params[":exports"] == "results" || params[":exports"] == "none" {
break
}
+ if params[":noweb"] == "strip-export" {
+ stripNoweb := regexp.MustCompile(`<<[^>]+>>`)
+ content = stripNoweb.ReplaceAllString(content, "")
+ }
lang := "text"
if len(b.Parameters) >= 1 {
lang = strings.ToLower(b.Parameters[0])
From c7595323bcc430d0855517c1c08fe2304c5c9be5 Mon Sep 17 00:00:00 2001
From: Donald Hunter
Date: Tue, 28 May 2024 23:08:58 +0100
Subject: [PATCH 3/4] Add test for :noweb strip-export to blocks.org
Signed-off-by: Donald Hunter
---
org/testdata/blocks.html | 7 +++++++
org/testdata/blocks.org | 4 ++++
org/testdata/blocks.pretty_org | 4 ++++
3 files changed, 15 insertions(+)
diff --git a/org/testdata/blocks.html b/org/testdata/blocks.html
index e55c978..3febfdd 100644
--- a/org/testdata/blocks.html
+++ b/org/testdata/blocks.html
@@ -195,3 +195,10 @@ Snow covers Emacs
+
diff --git a/org/testdata/blocks.org b/org/testdata/blocks.org
index d9ff6e5..ad0cbfa 100644
--- a/org/testdata/blocks.org
+++ b/org/testdata/blocks.org
@@ -176,3 +176,7 @@ this unindented line is outside of the list item
---AlexSchroeder
#+END_VERSE
+
+#+BEGIN_SRC raku :results output :noweb strip-export :exports both
+<>describe ;
+#+END_SRC
diff --git a/org/testdata/blocks.pretty_org b/org/testdata/blocks.pretty_org
index 4ae5b0c..e0719ae 100644
--- a/org/testdata/blocks.pretty_org
+++ b/org/testdata/blocks.pretty_org
@@ -176,3 +176,7 @@ this unindented line is outside of the list item
---AlexSchroeder
#+END_VERSE
+
+#+BEGIN_SRC raku :results output :noweb strip-export :exports both
+<>describe ;
+#+END_SRC
From 83bde78a852f1f83cbbd9c2cdcbd17c626dcb5f4 Mon Sep 17 00:00:00 2001
From: Donald Hunter
Date: Tue, 28 May 2024 23:10:02 +0100
Subject: [PATCH 4/4] Add diff to error report when tests fail
Signed-off-by: Donald Hunter
---
org/org_writer_test.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/org/org_writer_test.go b/org/org_writer_test.go
index 539ef8c..14f5834 100644
--- a/org/org_writer_test.go
+++ b/org/org_writer_test.go
@@ -45,7 +45,7 @@ func testWriter(t *testing.T, newWriter func() Writer, ext string) {
if err != nil {
t.Fatalf("%s\n got error: %s", path, err)
} else if actual != expected {
- t.Fatalf("%s:\n%s'", path, "")
+ t.Fatalf("%s:\n%s'", path, diff(actual, expected))
}
})
}