You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: allow format control of output
- Introduce {code} output token
- Introduce output_formats alternative to formats as mechanism for
specifying complete output format
* test: update tests to account for code token
* docs: update README to include code
* fix: let empty table merge
* format
* feat: switch from code to copied_text name
* docs: add example for precedence:
* test: added test for more config validation cases
* lint & format
* feat: add mapping descriptions
Added automatically-derived desc to the keymaps
* fix: validate {copied_text} usage in formats vs output_formats
- output_formats must contain {copied_text} to include the copied code
- formats cannot contain {copied_text} (auto-prepended, would cause
duplication)
---------
Co-authored-by: Evgeny Zhdanov <evdev34@gmail.com>
In case it fails to find the format for a mapping, it will fail during config load time with an error message. Check your config if that happens, whether everything specified in mappings is also present in formats.
245
246
247
+
### Full Output Control with `output_formats`
248
+
249
+
For complete control over the output structure, use `output_formats` instead of `formats`. The `output_formats` option allows you to place the code content anywhere in your output using the `{copied_text}` variable.
250
+
251
+
```lua
252
+
require('copy_with_context').setup({
253
+
mappings= {
254
+
relative='<leader>cy',
255
+
markdown='<leader>cm',
256
+
},
257
+
output_formats= {
258
+
default="{copied_text}\n\n# {filepath}:{line}", -- Code first, then context
259
+
markdown="```lua\n{copied_text}\n```\n\n*{filepath}:{line}*", -- Wrap in markdown code block
260
+
},
261
+
})
262
+
```
263
+
264
+
**Key differences:**
265
+
-`formats`: The copied text is automatically prepended with a newline. Format string only controls the context line.
266
+
-`output_formats`: You control the entire output. Typically includes `{copied_text}` token, but it's optional (omit it if you only want to copy metadata without the copied content).
267
+
268
+
When both `formats` and `output_formats` define the same format name, `output_formats` takes precedence.
269
+
270
+
Example with mixed configuration:
271
+
```lua
272
+
require('copy_with_context').setup({
273
+
mappings= {
274
+
relative='<leader>cy',
275
+
markdown='<leader>cm',
276
+
verbose='<leader>cl',
277
+
},
278
+
formats= {
279
+
default='# {filepath}:{line}', -- {copied_text} is auto-prepended
280
+
verbose='(from {filepath}:{line})', -- will be ignored because the format of the same name in output_formats takes precedence
281
+
},
282
+
output_formats= {
283
+
markdown="```{copied_text}```\n\n{remote_url}", -- {copied_text} token must be specified or it will not be included
284
+
verbose='This glorious example:\n\n```{copied_text}```\n\n(from {filepath}:{line})', -- This is the format used because output_formats take precedence over formats of the same name
285
+
},
286
+
})
287
+
```
288
+
246
289
### Repository URL Support
247
290
248
291
When you use `{remote_url}` in a format string, the plugin automatically generates permalink URLs for your code snippets. This feature works with:
0 commit comments