Skip to content

Commit

Permalink
compile cleanly with latest V, also run v fmt -w .
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Nov 16, 2023
1 parent 61c47ea commit 4c67d01
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
33 changes: 18 additions & 15 deletions html_experimental.v
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ import datatypes { Stack }

pub type ParentType = MD_BLOCKTYPE | MD_SPANTYPE

// HtmlTransformer transforms converted HTML elements (limited
// to attribute and content for now) from markdown before incorporated
// into the final output.
//
// When implementing an HtmlTransformer, escaping the content is up
// to you. However, it is best to wrap the values you don't need with
// HtmlTransformer transforms converted HTML elements (limited
// to attribute and content for now) from markdown before incorporated
// into the final output.
//
// When implementing an HtmlTransformer, escaping the content is up
// to you. However, it is best to wrap the values you don't need with
// `markdown.default_html_transformer.transform_{attribute|content}`
pub interface HtmlTransformer {
transform_attribute(parent ParentType, name string, value string) string
Expand Down Expand Up @@ -69,15 +69,15 @@ pub fn (t AttrTransformerFn) transform_attribute(parent ParentType, name string,
}

pub fn (t AttrTransformerFn) transform_content(parent ParentType, text string) string {
return default_html_transformer.transform_content(parent, text)
return markdown.default_html_transformer.transform_content(parent, text)
}

pub fn (mut t AttrTransformerFn) config_set(key string, val string) {}

pub type ContentTransformerFn = fn (ParentType, string) string

pub fn (t ContentTransformerFn) transform_attribute(parent ParentType, name string, value string) string {
return default_html_transformer.transform_attribute(parent, name, value)
return markdown.default_html_transformer.transform_attribute(parent, name, value)
}

pub fn (t ContentTransformerFn) transform_content(parent ParentType, text string) string {
Expand Down Expand Up @@ -113,10 +113,10 @@ fn tos_attribute(attr &C.MD_ATTRIBUTE, mut wr strings.Builder) {

pub struct HtmlRenderer {
pub mut:
transformer HtmlTransformer = markdown.default_html_transformer
transformer HtmlTransformer = markdown.default_html_transformer
mut:
parent_stack Stack[ParentType]
content_writer strings.Builder = strings.new_builder(200)
content_writer strings.Builder = strings.new_builder(200)
writer strings.Builder = strings.new_builder(200)
image_nesting_level int
}
Expand All @@ -137,10 +137,10 @@ fn (mut ht HtmlRenderer) render_closing_attribute() {
ht.writer.write_byte(`"`)
}

[params]
@[params]
struct MdAttributeConfig {
prefix string
suffix string
prefix string
suffix string
setting_key string
}

Expand Down Expand Up @@ -173,7 +173,7 @@ fn (mut ht HtmlRenderer) render_attribute(key string, value string) {
} else {
value
}

ht.writer.write_string(transformed)
ht.render_closing_attribute()
}
Expand Down Expand Up @@ -257,7 +257,10 @@ fn (mut ht HtmlRenderer) enter_block(typ MD_BLOCKTYPE, detail voidptr) ? {
if typ == .md_block_code {
details := unsafe { &C.MD_BLOCK_CODE_DETAIL(detail) }
ht.writer.write_string('<code')
ht.render_md_attribute('class', details.lang, prefix: 'language-', setting_key: 'code_language')
ht.render_md_attribute('class', details.lang,
prefix: 'language-'
setting_key: 'code_language'
)
ht.writer.write_byte(`>`)
} else if typ == .md_block_li {
details := unsafe { &C.MD_BLOCK_LI_DETAIL(detail) }
Expand Down
28 changes: 14 additions & 14 deletions md4c.v
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* MD4C: Markdown parser for C
* MD4C: Markdown parser for C
* (http://github.com/mity/md4c)
*
* Copyright (c) 2016-2019 Martin Mitáš
Expand Down Expand Up @@ -40,7 +40,7 @@ type TextFn = fn (t MD_TEXTTYPE, tx &char, s u32, u voidptr) int
type DebugFn = fn (m &char, u voidptr)

pub enum MD_BLOCKTYPE {
md_block_doc = 0
md_block_doc = 0
md_block_quote
md_block_ul
md_block_ol
Expand All @@ -59,7 +59,7 @@ pub enum MD_BLOCKTYPE {
}

pub enum MD_TEXTTYPE {
md_text_normal = 0
md_text_normal = 0
md_text_null_char
md_text_br
md_text_softbr
Expand Down Expand Up @@ -89,7 +89,7 @@ pub enum MD_ALIGN {
md_align_right
}

[typedef]
@[typedef]
pub struct C.MD_PARSER {
pub:
abi_version u32
Expand All @@ -102,7 +102,7 @@ pub:
debug_log DebugFn
}

[typedef]
@[typedef]
pub struct C.MD_ATTRIBUTE {
pub:
text &char
Expand All @@ -111,64 +111,64 @@ pub:
substr_offsets &u32
}

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

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

[typedef]
@[typedef]
pub struct C.MD_BLOCK_LI_DETAIL {
pub:
is_task bool
task_mark u8
task_mark_offset u32
}

[typedef]
@[typedef]
pub struct C.MD_BLOCK_H_DETAIL {
pub:
level u32
}

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

[typedef]
@[typedef]
pub struct C.MD_BLOCK_TD_DETAIL {
pub:
align MD_ALIGN
}

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

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

[typedef]
@[typedef]
pub struct C.MD_SPAN_WIKILINK_DETAIL {
pub:
target C.MD_ATTRIBUTE
Expand Down

0 comments on commit 4c67d01

Please sign in to comment.