Commit 3bb6fee240
Verified · cmc
Layout: unified · split
Sources/OrgCore/Compute/Babel.swift +4 −1
| @@ -1846,6 +1846,8 @@ public enum Babel { | |||
| 1846 | beg = buffer.point | 1846 | beg = buffer.point |
| 1847 | } | 1847 | } |
| 1848 | var tabulated = false | 1848 | var tabulated = false |
| 1849 | // A list made from a string is examplified, as a string result is. | ||
| 1850 | var listed = false | ||
| 1849 | switch value { | 1851 | switch value { |
| 1850 | case .none: | 1852 | case .none: |
| 1851 | break | 1853 | break |
| @@ -1854,6 +1856,7 @@ public enum Babel { | |||
| 1854 | let items = s.split(separator: "\n", omittingEmptySubsequences: true) | 1856 | let items = s.split(separator: "\n", omittingEmptySubsequences: true) |
| 1855 | buffer.insert(items.map { "- " + $0 }.joined(separator: "\n") + "\n") | 1857 | buffer.insert(items.map { "- " + $0 }.joined(separator: "\n") + "\n") |
| 1856 | case .table(let rows) where params.contains("list"): | 1858 | case .table(let rows) where params.contains("list"): |
| 1859 | listed = true | ||
| 1857 | let items = rows.count == 1 ? (rows[0] ?? []) : rows.compactMap { $0?.joined(separator: " ") } | 1860 | let items = rows.count == 1 ? (rows[0] ?? []) : rows.compactMap { $0?.joined(separator: " ") } |
| 1858 | buffer.insert(items.map { "- " + $0 }.joined(separator: "\n") + "\n") | 1861 | buffer.insert(items.map { "- " + $0 }.joined(separator: "\n") + "\n") |
| 1859 | case .table(let rows): | 1862 | case .table(let rows): |
| @@ -1895,7 +1898,7 @@ public enum Babel { | |||
| 1895 | // As inserted. | 1898 | // As inserted. |
| 1896 | } else if params.contains("drawer") { | 1899 | } else if params.contains("drawer") { |
| 1897 | wrap(":results:", ":end:", escape: false) | 1900 | wrap(":results:", ":end:", escape: false) |
| 1898 | } else if !tabulated, !params.contains("list") { | 1901 | } else if !tabulated, !(params.contains("list") && listed) { |
| 1899 | examplify(buffer, beg, end.position) | 1902 | examplify(buffer, beg, end.position) |
| 1900 | } | 1903 | } |
| 1901 | if indent > 0, !(tabulated && params.contains("append")) { | 1904 | if indent > 0, !(tabulated && params.contains("append")) { |
Tests/OrgCoreTests/BabelTests.swift +1
| @@ -108,6 +108,7 @@ struct BabelTests { | |||
| 108 | "#+begin_src sh :results raw\necho '*bold*'\n#+end_src\n", | 108 | "#+begin_src sh :results raw\necho '*bold*'\n#+end_src\n", |
| 109 | "#+begin_src sh :results drawer\necho in a drawer\n#+end_src\n", | 109 | "#+begin_src sh :results drawer\necho in a drawer\n#+end_src\n", |
| 110 | "#+begin_src sh :results list\nprintf 'a\\nb\\n'\n#+end_src\n", | 110 | "#+begin_src sh :results list\nprintf 'a\\nb\\n'\n#+end_src\n", |
| 111 | "#+begin_src sh :results output list\nprintf 'a\\nb\\n'\n#+end_src\n", | ||
| 111 | "#+begin_src sh :results silent\necho quiet\n#+end_src\n", | 112 | "#+begin_src sh :results silent\necho quiet\n#+end_src\n", |
| 112 | "#+begin_src sh :results output code\necho 'x=1'\n#+end_src\n", | 113 | "#+begin_src sh :results output code\necho 'x=1'\n#+end_src\n", |
| 113 | "#+begin_src sh :wrap example\necho wrapped\n#+end_src\n", | 114 | "#+begin_src sh :wrap example\necho wrapped\n#+end_src\n", |