Tangle :comments noweb with :noweb-ref blocks !148
merged
merged by cmc on 2026-10-07 23:32 UTC
· krz/orgstar:noweb-ref-comments into main
Conversation
Commits 1
Files changed 3
3 files changed, +21 −4
Layout: unified · split
Sources/OrgCore/Compute/Babel.swift
+6 −2
@@ -481,12 +481,16 @@ public enum Babel {
481 ? try expandNoweb ( other , params : otherParams , model : model , text : text , tangling : tangling , depth : depth + 1 , links : links )
481 ? try expandNoweb ( other , params : otherParams , model : model , text : text , tangling : tangling , depth : depth + 1 , links : links )
482 : normalizedBody ( other )
482 : normalizedBody ( other )
483 guard commenting , let links else { return b }
483 guard commenting , let links else { return b }
484 guard other . name != nil else { throw Failure . message ( " :comments noweb with :noweb-ref blocks isn't supported yet; nothing was tangled. " ) }
485 // ` c - w r a p ` : c o m m e n t e d i n t h i s b l o c k ' s l a n g u a g e , t r i m m e d .
484 // ` c - w r a p ` : c o m m e n t e d i n t h i s b l o c k ' s l a n g u a g e , t r i m m e d .
486 func wrap ( _ s : String ) throws -> String {
485 func wrap ( _ s : String ) throws -> String {
487 try Tangle . commentRegion ( s , language : block . language ? ? " " ) . trimmingCharacters ( in : . whitespacesAndNewlines )
486 try Tangle . commentRegion ( s , language : block . language ? ? " " ) . trimmingCharacters ( in : . whitespacesAndNewlines )
488 }
487 }
489 let ( begin , end ) = try links ( other , otherParams )
488 var ( begin , end ) = try links ( other . name = = nil ? block : other , other . name = = nil ? params : otherParams )
489 // A ` : n o w e b - r e f ` b l o c k w i t h o u t a n a m e : t h e l i n k i s t h e i n c l u d i n g b l o c k ' s , t h e n a m e e m p t y .
490 if other . name = = nil {
491 if let split = begin . range ( of : " ][ " ) { begin = begin [ . . < split . lowerBound ] + " ][]] " }
492 end = " ends here "
493 }
490 return try wrap ( begin ) + " \n " + b + " \n " + ( try wrap ( end ) ) + " \n "
494 return try wrap ( begin ) + " \n " + b + " \n " + ( try wrap ( end ) ) + " \n "
491 }
495 }
492 func inCommentedHeading ( _ b : SrcBlockInfo ) -> Bool {
496 func inCommentedHeading ( _ b : SrcBlockInfo ) -> Bool {
Sources/OrgCore/Compute/Tangle.swift
+5 −2
@@ -315,8 +315,11 @@ public enum Tangle {
315 guard let syntax = commentSyntax [ language ] else {
315 guard let syntax = commentSyntax [ language ] else {
316 throw Babel . Failure . message ( " :comments needs the comment syntax of \( language . isEmpty ? " the block's language " : language ) , which isn't known yet; nothing was tangled. " )
316 throw Babel . Failure . message ( " :comments needs the comment syntax of \( language . isEmpty ? " the block's language " : language ) , which isn't known yet; nothing was tangled. " )
317 }
317 }
318 return text . components ( separatedBy : " \n " ) . map { line in
318 // T h e c o m m e n t s t a r t s a t t h e l i n e s ' l e a s t i n d e n t a t i o n , a s ` c o m m e n t - r e g i o n ` p u t s i t .
319 line . contains ( where : { ! $0 . isWhitespace } ) ? syntax . start + line + syntax . end : line
319 let lines = text . components ( separatedBy : " \n " )
320 let indent = lines . filter { $0 . contains ( where : { ! $0 . isWhitespace } ) } . map { $0 . prefix { $0 = = " " || $0 = = " \t " } . count } . min ( ) ? ? 0
321 return lines . map { line in
322 line . contains ( where : { ! $0 . isWhitespace } ) ? String ( line . prefix ( indent ) ) + syntax . start + line . dropFirst ( indent ) + syntax . end : line
320 } . joined ( separator : " \n " )
323 } . joined ( separator : " \n " )
321 }
324 }
322
325
Tests/OrgCoreTests/TangleTests.swift
+10
@@ -143,6 +143,16 @@ struct TangleTests {
143 # + begin_src conf : tangle out . conf : comments noweb : noweb yes
143 # + begin_src conf : tangle out . conf : comments noweb : noweb yes
144 a = << named - py > >
144 a = << named - py > >
145 # + end_src
145 # + end_src
146 # + begin_src sh : noweb - ref setup
147 echo one
148 # + end_src
149 # + begin_src sh : noweb - ref setup
150 echo two
151 # + end_src
152 # + begin_src sh : tangle refs . sh : noweb yes : comments noweb
153 << setup > >
154 echo main
155 # + end_src
146 # + begin_src lua : tangle out . lua
156 # + begin_src lua : tangle out . lua
147 x = 1
157 x = 1
148 # + end_src
158 # + end_src
Checks
No checks reported
Revisions
1. 625afdf7c0 2026-10-07 23:32 UTC
Source and target
krz/orgstar:noweb-ref-comments into main
merged at 625afdf7c0 · base a4008c4a7f · branch deleted