---
title: Markdown and Code Blocks Parsing
description: This document explains the API and usage of the Markdown and Code parsing features in the application.

doc_version: 1
last_updated: 2026-07-02
---


# Markdown and Code Parsing

The Glazed package offers a comprehensive suite of functions designed to extract code blocks from markdown files. This
functionality is particularly useful for post-processing code generated by Low-Level Virtual Machines (LLVMs). By
parsing markdown files and isolating code blocks, Glazed allows for more granular control over code execution, testing,
and debugging. This feature enhances the efficiency of working with LLVM-generated code, streamlining the process and
making it more manageable.

This document explains the API and usage of the Markdown and Code parsing features in the application.

## GenerateComment

The `GenerateComment` function converts a given string into a comment based on the specified programming language.

**Usage**:

Call this function with a string and a language to get the string formatted as a comment in that language.

**Example**:

```go
comment := GenerateComment("This is a comment.", GoLang)
```

**Output**:

```go
// This is a comment.
```

## MarkdownCodeBlockToLanguage

The `MarkdownCodeBlockToLanguage` function translates a markdown code block language specifier to its corresponding Language type.

**Usage**:

Use this function to identify the language of a code block in markdown.

**Example**:

```go
lang := MarkdownCodeBlockToLanguage("go")
```

**Output**:

```go
Go
```

## ExtractAllBlocks

The `ExtractAllBlocks` function 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).

**Example**:

Using the markdown string:

```
# Title

This is a markdown document.

```go
fmt.Println("Hello, world!")
.```

This is a comment.

.```python
print("Hello, world!")
.```
```

**Output**:

```
Normal  # Title

This is a markdown document.

Code go fmt.Println("Hello, world!")
Normal  
This is a comment.

Code python print("Hello, world!")
```

## ExtractQuotedBlocks

The `ExtractQuotedBlocks` function 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.

**Example**:

Using the same markdown string...

**Output**:

```
.```go
fmt.Println("Hello, world!")
.```
.```python
print("Hello, world!")
.```
```

## ExtractCodeBlocksWithComments

The `ExtractCodeBlocksWithComments` function 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.

**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.

**Example**:

Using the markdown same markdown string...

**Output**:

```
.```go
// # Title
// 
// This is a markdown document.
// 
fmt.Println("Hello, world!")
.```
.```python
# 
# This is a comment.
# 
print("Hello, world!")
.```
```