c-md/srcs/transpile/fence.c.md
2026-01-12 16:22:13 +01:00

84 lines
1.4 KiB
Markdown

# fence.c
Handles opening and closing of fenced code blocks in the transpilation process.
---
## Includes
```c
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "internal/transpile_internal.h"
#include "utils.h"
```
---
## Function Descriptions
### `handle_fence_open`
Handles the opening of a fenced code block.
#### Parameters
- `s`: Pointer to the current transpilation state.
- `line`: Pointer to the current line being processed.
#### Return Value
Returns `0` on success, `1` on error.
#### Implementation
```c
int8_t
handle_fence_open(t_state *s, char *line)
{
char *block_ext;
block_ext = extract_fence_ext(line);
if (NULL == block_ext)
return (0);
if (0 != strcmp(block_ext, s->ext))
{
free(block_ext);
return (0);
}
free(block_ext);
if (0 == s->first_block)
{
if (0 > fprintf(s->out, "\n"))
return (1);
s->dst_line++;
}
s->first_block = 0;
s->in_block = 1;
s->block_src_start = s->src_line + 1;
s->block_dst_start = s->dst_line + 1;
return (0);
}
```
### `handle_fence_close`
Handles the closing of a fenced code block.
#### Parameters
- `s`: Pointer to the current transpilation state.
#### Implementation
```c
int8_t
handle_fence_close(t_state *s)
{
uint32_t src_end;
uint32_t dst_end;
s->in_block = 0;
src_end = s->src_line - 1;
dst_end = s->dst_line;
if (s->block_src_start <= src_end)
{
map_add(s->map, s->block_src_start, src_end,
s->block_dst_start, dst_end);
}
return (0);
}
```