doctavious / snippext

Snippext extracts snippets from source files and merges them into your documentation.
MIT License
0 stars 0 forks source link

Allow Users to Select Which Lines are Rendered For a Snippet #11

Closed seancarroll closed 1 year ago

seancarroll commented 1 year ago

Add snippet configuration to allow users to specify which lines of a snippet are rendered. Users should be able to specify a list of lines which include individual lines "1" as well as a range of lines "5-7". An example of what that would look like in a target file would be

<!-- snippet::start main[selected_lines=["1", "5-7"]] -->
<!-- snippet::end -->
seancarroll commented 1 year ago

We recently made a change so that we could support attribute values other than string however [] will likely cause issues with our regex to extract attributes. Even if that wasn't an issue we would have to make additional changes to appropriately convert array into a serde_json::Value::Array and our currently logic isn't very good. To improve our logic it might make sense us for attributes to be JSON e.g.

{"omit_source_links": true, "selected_lines": ["1", "5-7"]}

While this would be a larger change I think it would improve the overall attribute code related to rendering

We may also want to support a string format e.g. "1,5-7" which we could appropriately parse which would look like the following (assuming we went the JSON attribute configuration route)

{"omit_source_links": true, "selected_lines": "1,5-7"}