Module markdown

markdown
Version:
0.1.1
Dependencies from vmod:
0
Imports:
1
Imported by:
1
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

Imported by

Overview

Markdown module for V. For now, it uses the md4c library for parsing markdown files to HTML and soon it will be rewritten from scratch to pure V.

Usage

module main
import markdown

fn main() {
    text := '## Markdown Rocks!'
    output := markdown.to_html(text)
    println(output) // <h1>Markdown Rocks!</h1>
}

Installation

Install and use markdown module via VPM:

v install markdown

Or via vpkg:

vpkg get https://github.com/vlang/markdown --global

Or through Git:

git clone https://github.com/vlang/markdown.git ~/.vmodules/markdown

Contributors

Aliases

This section is empty.

Constants

This section is empty.

Sum types

This section is empty.

Functions

#fn new

fn new(parser_flags u32, enter_block_cb fn (MD_BLOCKTYPE, voidptr, voidptr) int, leave_block_cb fn (MD_BLOCKTYPE, voidptr, voidptr) int, enter_span_cb fn (MD_SPANTYPE, voidptr, voidptr) int, leave_span_cb fn (MD_SPANTYPE, voidptr, voidptr) int, text_cb fn (MD_TEXTTYPE, &char, u32, voidptr) int, debug_cb fn (&char, voidptr)) C.MD_PARSER

#fn render

fn render(src string, mut renderer &Renderer) !

render parses and renders a given markdown string based on the renderer.

#fn to_html

fn to_html(input string) string

#fn to_plain

fn to_plain(input string) string

Structs

#struct C.MD_PARSER

typedef
pub struct C.MD_PARSER {
pub:
	abi_version u32
	flags       u32
	enter_block BlockFn
	leave_block BlockFn
	enter_span  SpanFn
	leave_span  SpanFn
	text        TextFn
	debug_log   DebugFn
}

#struct C.MD_ATTRIBUTE

typedef
pub struct C.MD_ATTRIBUTE {
pub:
	text           &char
	size           u32
	substr_types   MD_TEXTTYPE
	substr_offsets u32
}

#struct C.MD_BLOCK_UL_DETAIL

typedef
pub struct C.MD_BLOCK_UL_DETAIL {
pub:
	is_tight int
	mark     u8
}

#struct C.MD_BLOCK_OL_DETAIL

typedef
pub struct C.MD_BLOCK_OL_DETAIL {
pub:
	start          u32
	is_tight       int
	mark_delimiter u8
}

#struct C.MD_BLOCK_LI_DETAIL

typedef
pub struct C.MD_BLOCK_LI_DETAIL {
pub:
	is_task          int
	task_mark        u8
	task_mark_offset u32
}

#struct C.MD_BLOCK_H_DETAIL

typedef
pub struct C.MD_BLOCK_H_DETAIL {
pub:
	level u32
}

#struct C.MD_BLOCK_CODE_DETAIL

typedef
pub struct C.MD_BLOCK_CODE_DETAIL {
pub:
	info       C.MD_ATTRIBUTE
	lang       C.MD_ATTRIBUTE
	fence_char u8
}

#struct C.MD_BLOCK_TD_DETAIL

typedef
pub struct C.MD_BLOCK_TD_DETAIL {
pub:
	align MD_ALIGN
}

#struct C.MD_SPAN_A_DETAIL

typedef
pub struct C.MD_SPAN_A_DETAIL {
pub:
	href  C.MD_ATTRIBUTE
	title C.MD_ATTRIBUTE
}

#struct C.MD_SPAN_IMG_DETAIL

typedef
pub struct C.MD_SPAN_IMG_DETAIL {
pub:
	src   C.MD_ATTRIBUTE
	title C.MD_ATTRIBUTE
}

Interfaces

#interface Renderer

pub interface Renderer {
mut:
	enter_block(typ MD_BLOCKTYPE, detail voidptr) ?
	leave_block(typ MD_BLOCKTYPE, detail voidptr) ?
	enter_span(typ MD_SPANTYPE, detail voidptr) ?
	leave_span(typ MD_SPANTYPE, detail voidptr) ?
	text(typ MD_TEXTTYPE, content string) ?
	debug_log(msg string)
}

Renderer represents an entity that accepts incoming data and renders the content.

Enums

#enum MD_BLOCKTYPE

pub enum MD_BLOCKTYPE {
	md_block_doc = 0
	md_block_quote
	md_block_ul
	md_block_ol
	md_block_li
	md_block_hr
	md_block_h
	md_block_code
	md_block_html
	md_block_p
	md_block_table
	md_block_thead
	md_block_tbody
	md_block_tr
	md_block_th
	md_block_td
}

#enum MD_TEXTTYPE

pub enum MD_TEXTTYPE {
	md_text_normal = 0
	md_text_null_char
	md_text_br
	md_text_softbr
	md_text_entity
	md_text_code
	md_text_html
	md_text_latexmath
}

#enum MD_SPANTYPE

pub enum MD_SPANTYPE {
	md_span_em
	md_span_strong
	md_span_a
	md_span_img
	md_span_code
	md_span_del
	md_span_latexmath
	md_span_latexmath_display
	md_span_wikilink
	md_span_u
}

#enum MD_ALIGN

pub enum MD_ALIGN {
	md_align_default = 0
	md_align_left
	md_align_center
	md_align_right
}