Surrounded By

Use to extract code snippet surrounded by a marker Use to keep marker lines # example-import-block import market # example-import-block def main(): # example: book trade id = market.book_trade('symbol', market.CURRENT_PRICE, 100) # example-end # example-cancel-trade market.cancel_trade(id) # example-cancel-trade if __name__ == "__main__": main() :include-file: python-examples.py { title: "extracted example with surroundedBy", surroundedBy: "# example-cancel-trade"} market.cancel_trade(id) block-A-start: event-one-handler: ... block-A-end block-B-start ... block-B-end :include-file: custom.dsl { title: "keep marker lines", surroundedBy: "block-A", surroundedByKeep: true } block-A-start: event-one-handler: ... block-A-end

Multiple Surrounded By

Pass a list to to extract multiple blocks Use to select separator(s) between blocks Note: can be either single value or a list. Plugin will use a different separator for each block. Use to have an empty line as a separator. :include-file: python-examples.py { title: "extracted example", surroundedBy: ["# example-import-block", "# example-cancel-trade"]} import market market.cancel_trade(id) :include-file: python-examples.py { title: "extracted example", surroundedBy: ["# example-import-block", "# example-cancel-trade"], surroundedBySeparator: ["..."] } import market ... market.cancel_trade(id) null

Surrounded By Scope

Use to extract text using scopes like , , etc: {} [] class MyClass { void action() { if (condition) { importantExample(); } if (anotherCondition) { anotherImportantExample(); } } } :include-file: MyClass.java {surroundedByScope: {start: "if (condition)", scope: "{}"}} if (condition) { importantExample(); }

Surrounded By Multi-chars scope

Pass comma separated multi char region definition to to handle scopes defined with keywords: module ModelZero : sig type t end module ModelA : sig type t val calc: t -> int module Nested : sig type t end end module ModelC : sig type t end :include-file: ocaml/model.mli {surroundedByScope: {start: "module ModelA", scope: "sig,end"}} module ModelA : sig type t val calc: t -> int module Nested : sig type t end end

Replace

Use to replace content of the resulting snippet Pass a list of lists to for multiple replaces :include-file: python-examples.py { surroundedBy: "# example-cancel-trade", replace: ['id', '"trade_id"'] } market.cancel_trade("trade_id") :include-file: python-examples.py { surroundedBy: "# example-cancel-trade", replace: [['id', '"trade_id"'], ["market", "api"]]} api.cancel_trade("trade_id")

Replace Regexp Groups

Use regexp capture groups to create derived content $1 hello1 world2 another3 line4 :include-file: replace-all-group.txt {replace: ["(\\w+)(\\d+)", "$2-$1"]} 1-hello 2-world 3-another 4-line

Start/End Line

Use , to extract specific content by using marker lines. Note: Lines match doesn't have to be exact, is used. By default and are included in the rendered result. Use to remove markers. To exclude start or end line only use and # example-import-block import market # example-import-block def main(): # example: book trade id = market.book_trade('symbol', market.CURRENT_PRICE, 100) # example-end # example-cancel-trade market.cancel_trade(id) # example-cancel-trade if __name__ == "__main__": main() :include-file: python-examples.py {startLine: "example: book trade", endLine: "example-end"} # example: book trade id = market.book_trade('symbol', market.CURRENT_PRICE, 100) # example-end contains :include-file: python-examples.py { startLine: "example: book trade", endLine: "example-end", excludeStartEnd: true } id = market.book_trade('symbol', market.CURRENT_PRICE, 100)

Start/End Multiple Lines

Pass multiple values to and to specify more precisely a block of code to extract. As example, let's extract a second block from the code snippets below without adding extra markers: if we use , we can't guarantee what block will it pick, and it will depend on functions order. To hit the exact one use multiple start lines. Znai will attempt to find a combination of start lines with the smallest distance between them: Note: Use and to limit lines from the bottom. removes all the lines between specified start lines, including the lines. removes all the lines between specified end lines, including the lines. startLine endLine match type weather_season = | Spring | Summer | Autumn | Winter let weight_season season = match season with | Spring -> 4 | Summer -> 5 | Autumn -> 3 | Winter -> -1 let describe_season season = (** human readable season description *) match season with | Spring -> "It's springtime! Flowers are blooming." | Summer -> "It's summertime! Enjoy the warm weather." | Autumn -> "It's autumn! Leaves are changing colors." | Winter -> "It's winter! Time to bundle up and enjoy the snow." startLine: "match season" :include-file: ocaml/seasons.ml {startLine: ["let describe_season", "match season"], startLineKeepLast: true} match season with | Spring -> "It's springtime! Flowers are blooming." | Summer -> "It's summertime! Enjoy the warm weather." | Autumn -> "It's autumn! Leaves are changing colors." | Winter -> "It's winter! Time to bundle up and enjoy the snow." endLine endLineKeepFirst excludeStart excludeEnd

Include Contains

Use to include only lines containing specified text(s). :include-file: python-examples.py { include: "import " } or :include-file: python-examples.py { include: ["import "] } import market

Exclude Contains

Use to exclude lines containing specified text(s). :include-file: python-examples.py { exclude: "# example" } or :include-file: python-examples.py { exclude: ["# example"] } import market def main(): id = market.book_trade('symbol', market.CURRENT_PRICE, 100) market.cancel_trade(id) if __name__ == "__main__": main()

Include Regexp

Use to include only lines matching regexp(s). :include-file: python-examples.py { includeRegexp: "market.*_trade" } or :include-file: python-examples.py { includeRegexp: ["market.*_trade"] } id = market.book_trade('symbol', market.CURRENT_PRICE, 100) market.cancel_trade(id)

Exclude Regexp

Use to exclude lines matching regexp(s). :include-file: python-examples.py { excludeRegexp: ["if .* ==", "\\s+main", "# example", "^\\s*$"] } import market id = market.book_trade('symbol', market.CURRENT_PRICE, 100) market.cancel_trade(id)