@@ -13,6 +13,7 @@ The `tangle` module currently provides a single command:
1313- `:Neorg tangle current-file` - performs all possible tangling operations on the current file
1414
1515### Usage Tutorial
16+
1617By default, *zero* code blocks are tangled. You must provide where you'd like to tangle each code
1718block manually (global configuration will be discussed later). To do so, add a `#tangle
1819<output-file>` tag above the code block you'd wish to export, where <output-file> is relative to the
@@ -26,6 +27,10 @@ print("Hello World!")
2627```
2728The above snippet will *only* tangle that single code block to the desired output file: `init.lua`.
2829
30+ > [!WARNING]
31+ > Due to a bug in the norg treesitter parser, `#tangle ./init.lua` or `#tangle folder/init.lua` will not work
32+ > As a result, we recommend specifying files destinations in metadata
33+
2934#### Global Tangling for Single Files
3035Apart from tangling a single or a set of code blocks, you can declare a global output file in the document's metadata:
3136```norg
@@ -51,6 +56,17 @@ tangle: [
5156The above snippet tells the Neorg tangling engine to tangle all `lua` code blocks to `./init.lua` and all `haskell` code blocks to `./output.hs`.
5257As always if any of the code blocks have a `#tangle` tag then that takes precedence.
5358
59+ If you want to be more verbose, or you're tangling to a file without an extension (perhaps you're
60+ writing a shell script that has a shebang) you can also do this:
61+ ```norg
62+ @document.meta
63+ tangle: {
64+ lua: ./init.lua
65+ python: ./output
66+ }
67+ @end
68+ ```
69+
5470#### Ignoring Code Blocks
5571Sometimes when tangling you may want to omit some code blocks. For this you may use the `#tangle.none` tag:
5672```norg
@@ -166,17 +182,21 @@ local lib, modules, utils, log = neorg.lib, neorg.modules, neorg.utils, neorg.lo
166182
167183local module = modules .create (" core.tangle" )
168184local Path = require (" pathlib" )
185+ --- @type core.dirman.utils
186+ local dirman_utils
169187
170188module .setup = function ()
171189 return {
172190 requires = {
173191 " core.integrations.treesitter" ,
192+ " core.dirman.utils" ,
174193 " core.neorgcmd" ,
175194 },
176195 }
177196end
178197
179198module .load = function ()
199+ dirman_utils = module .required [" core.dirman.utils" ]
180200 modules .await (" core.neorgcmd" , function (neorgcmd )
181201 neorgcmd .add_commands_from_table ({
182202 tangle = {
@@ -348,7 +368,7 @@ module.public = {
348368 local path_lib_path = Path .new (file_to_tangle_to )
349369 if path_lib_path :is_relative () then
350370 local buf_path = Path .new (buf_name )
351- file_to_tangle_to = tostring (buf_path : parent (): child ( file_to_tangle_to ):resolve ())
371+ file_to_tangle_to = tostring (dirman_utils . expand_pathlib ( file_to_tangle_to , true , buf_path ):resolve ())
352372 end
353373
354374 local delimiter_content
@@ -477,14 +497,7 @@ module.on_event = function(event)
477497 local tangled_count = 0
478498
479499 for file , content in pairs (tangles ) do
480- -- resolve upward relative path like `../../`
481- local relative_file , upward_count = string.gsub (file , " %.%.[\\ /]" , " " )
482- if upward_count > 0 then
483- local base_dir = vim .fn .expand (" %:p" .. string.rep (" :h" , upward_count + 1 )) --[[ @as string]]
484- file = vim .fs .joinpath (base_dir , relative_file )
485- end
486-
487- vim .loop .fs_open (vim .fn .expand (file ) --[[ @as string]] , " w" , 438 , function (err , fd )
500+ vim .loop .fs_open (file , " w" , 438 , function (err , fd )
488501 assert (not err and fd , lib .lazy_string_concat (" Failed to open file '" , file , " ' for tangling: " , err ))
489502
490503 local write_content = table.concat (content , " \n " )
0 commit comments