Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractCodeBlocksWithComments ¶
ExtractCodeBlocksWithComments processes a markdown string to return only code blocks. Any non-code content preceding a code block is added as a comment within the respective code block. If there are non-code contents left at the end without a following code block, they are appended as comments to the last code block.
**Usage**: Call this function with a markdown string and a boolean `withQuotes`. If `withQuotes` is set to true, the output will include the enclosing ``` for each code block. Otherwise, only the inner content of the code block (and the preceding comments) is returned.
func ExtractQuotedBlocks ¶
ExtractQuotedBlocks extracts only the code blocks from a markdown string.
**Usage**: This function takes in a markdown string and a boolean `withQuotes`. If `withQuotes` is set to true, the output will include the enclosing ``` for each code block. Otherwise, only the inner content of the code block is returned.
**Inner Workings**: This function leverages the `ExtractAllBlocks` function to first get all blocks from the markdown content. It then filters out only the code blocks and processes them based on the `withQuotes` parameter to decide on the inclusion of the enclosing ``` marks.
Types ¶
type MarkdownBlock ¶
func ExtractAllBlocks ¶
func ExtractAllBlocks(input string) []MarkdownBlock
ExtractAllBlocks processes a given markdown string to split it into a series of blocks.
**Usage**: Call this function with a markdown string as the argument. It will return a slice of MarkdownBlock structs, each representing a block of content (either normal or code).
**Inner Workings**: The function employs a state machine approach to parse through the markdown content. It recognizes and separates out code blocks (enclosed with ```) and normal text blocks. For code blocks, it also identifies the optional language specifier.