diff --git a/org/block.go b/org/block.go index e1480c3..6f8a98f 100644 --- a/org/block.go +++ b/org/block.go @@ -118,6 +118,17 @@ func trimIndentUpTo(max int) func(string) string { } } +func (b Block) ParameterMap() map[string]string { + if len(b.Parameters) == 0 { + return nil + } + m := map[string]string{":lang": b.Parameters[0]} + for i := 1; i+1 < len(b.Parameters); i += 2 { + m[b.Parameters[i]] = b.Parameters[i+1] + } + return m +} + func (n Example) String() string { return orgWriter.WriteNodesAsString(n) } func (n Block) String() string { return orgWriter.WriteNodesAsString(n) } func (n Result) String() string { return orgWriter.WriteNodesAsString(n) } diff --git a/org/html_writer.go b/org/html_writer.go index cf07f72..8d35805 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -110,9 +110,13 @@ func (w *HTMLWriter) WriteComment(Comment) {} func (w *HTMLWriter) WritePropertyDrawer(PropertyDrawer) {} func (w *HTMLWriter) WriteBlock(b Block) { - content := w.blockContent(b.Name, b.Children) + content, params := w.blockContent(b.Name, b.Children), b.ParameterMap() + switch b.Name { case "SRC": + if params[":exports"] == "results" || params[":exports"] == "none" { + break + } lang := "text" if len(b.Parameters) >= 1 { lang = strings.ToLower(b.Parameters[0]) @@ -135,7 +139,7 @@ func (w *HTMLWriter) WriteBlock(b Block) { w.WriteString(content + "\n") } - if b.Result != nil { + if b.Result != nil && params[":exports"] != "code" && params[":exports"] != "none" { WriteNodes(w, b.Result) } } diff --git a/org/testdata/blocks.html b/org/testdata/blocks.html index 1e801cf..642dc6d 100644 --- a/org/testdata/blocks.html +++ b/org/testdata/blocks.html @@ -37,6 +37,9 @@ echo a source block with results a source block with results
+a source block that only exports results
+
+
 an example block with
 multiple lines including
 
diff --git a/org/testdata/blocks.org b/org/testdata/blocks.org
index 7667c23..b880eea 100644
--- a/org/testdata/blocks.org
+++ b/org/testdata/blocks.org
@@ -24,6 +24,20 @@ echo a source block with results
 #+RESULTS:
 : a source block with results
 
+#+BEGIN_SRC bash :exports none
+echo a source block with results that is not exported
+#+END_SRC
+
+#+RESULTS:
+: a source block with results that is not exported
+
+#+BEGIN_SRC bash :exports results
+echo a source block that only exports results
+#+END_SRC
+
+#+RESULTS:
+: a source block that only exports results
+
 #+BEGIN_EXAMPLE foo bar baz
 an example block with
 multiple lines including
diff --git a/org/testdata/blocks.pretty_org b/org/testdata/blocks.pretty_org
index ce4d5b9..8359623 100644
--- a/org/testdata/blocks.pretty_org
+++ b/org/testdata/blocks.pretty_org
@@ -24,6 +24,20 @@ echo a source block with results
 #+RESULTS:
 : a source block with results
 
+#+BEGIN_SRC bash :exports none
+echo a source block with results that is not exported
+#+END_SRC
+
+#+RESULTS:
+: a source block with results that is not exported
+
+#+BEGIN_SRC bash :exports results
+echo a source block that only exports results
+#+END_SRC
+
+#+RESULTS:
+: a source block that only exports results
+
 #+BEGIN_EXAMPLE foo bar baz
 an example block with
 multiple lines including