This version of the module is deprecated: Use moonbitlang/docx2html instead
Native MoonBit DOCX to HTML/Markdown converter ported from Mammoth
moon add bobzhang/docx2html///|
test "convert document model to html" {
let doc = @docx2html.document([
@docx2html.paragraph([@docx2html.text("Hello.")]),
])
let result = @docx2html.convert_document_to_html(doc)
inspect(result.value, content="<p>Hello.</p>")
}///|
test "custom image conversion" {
let image = @docx2html.Image::{
content_type: "image/png",
alt_text: Some("chart"),
data: b"abc",
}
let doc = @docx2html.document([@docx2html.paragraph([Image(image)])])
let convert_image = @docx2html.img_element(fn(_image) {
{ "src": "/assets/chart.png" }
})
let result = @docx2html.convert_document_to_html(doc, convert_image~)
inspect(
result.value,
content="<p><img alt=\"chart\" src=\"/assets/chart.png\" /></p>",
)
}pub(all) struct Comment {
comment_id : String
body : Array[DocumentElement]
author_name : String
author_initials : String
} derive(Eq, Debug)fn ConversionResult::map(self : ConversionResult, f : (String) -> String raise?) -> ConversionResult raise?pub(all) struct ConvertOptions {
style_map : Array[StyleMapping]
ignore_empty_paragraphs : Bool
id_prefix : String
pretty_print : Bool
output_format : String
} derive(Eq, Debug)pub(all) enum DocumentElement {
Document(Array[DocumentElement], Array[Note], Array[Comment])
Paragraph(Array[DocumentElement], ParagraphProperties)
Run(Array[DocumentElement], RunProperties)
Text(String)
Tab
Checkbox(Bool)
Hyperlink(Array[DocumentElement], String?, String?, String?)
NoteReference(String, String)
CommentReference(String)
Image(Image)
Table(Array[DocumentElement], TableProperties)
TableRow(Array[DocumentElement], Bool)
TableCell(Array[DocumentElement], Int, Int)
Break(BreakType)
BookmarkStart(String)
} derive(Eq, Debug)pub(all) enum DocumentMatcher {
ParagraphMatcher(String?, StyleNameMatcher?, Numbering?)
RunMatcher(String?, StyleNameMatcher?)
RunPropertyMatcher(String)
HighlightMatcher(String?)
TableMatcher(String?, StyleNameMatcher?)
BreakMatcher(BreakType)
CommentReferenceMatcher
} derive(Eq, Debug)pub(all) struct Note {
note_type : String
note_id : String
body : Array[DocumentElement]
} derive(Eq, Debug)pub(all) struct RunProperties {
style_id : String?
style_name : String?
is_bold : Bool
is_underline : Bool
is_italic : Bool
is_strikethrough : Bool
is_all_caps : Bool
is_small_caps : Bool
vertical_alignment : VerticalAlignment
font : String?
font_size : Int?
highlight : String?
} derive(Eq, Debug)pub(all) struct StyleMapping {
from : DocumentMatcher
to : Array[HtmlPathElement]
} derive(Eq, Debug)fn convert_document_to_html(document : DocumentElement, style_map? : Array[String], include_default_style_map? : Bool, ignore_empty_paragraphs? : Bool, id_prefix? : String, pretty_print? : Bool, convert_image? : (Image) -> ImageConversion, transform_document? : (DocumentElement) -> DocumentElement) -> ConversionResultfn convert_document_to_markdown(document : DocumentElement, style_map? : Array[String], include_default_style_map? : Bool, convert_image? : (Image) -> ImageConversion, transform_document? : (DocumentElement) -> DocumentElement) -> ConversionResultfn convert_to_html(docx : BytesView, style_map? : Array[String], include_default_style_map? : Bool, include_embedded_style_map? : Bool, ignore_empty_paragraphs? : Bool, id_prefix? : String, pretty_print? : Bool, convert_image? : (Image) -> ImageConversion, transform_document? : (DocumentElement) -> DocumentElement) -> ConversionResult raise DocxErrorfn convert_to_markdown(docx : BytesView, style_map? : Array[String], include_default_style_map? : Bool, include_embedded_style_map? : Bool, convert_image? : (Image) -> ImageConversion, transform_document? : (DocumentElement) -> DocumentElement) -> ConversionResult raise DocxErrorfn document(children : Array[DocumentElement], notes? : Array[Note], comments? : Array[Comment]) -> DocumentElementfn document_descendants_where(element : DocumentElement, predicate : (DocumentElement) -> Bool) -> Array[DocumentElement]fn paragraph(children : Array[DocumentElement], properties? : ParagraphProperties) -> DocumentElementfn read_xml_string(source : String, namespace_map? : Map[String, String]) -> XmlElement raise DocxErrorfn transform_elements(element : DocumentElement, transform : (DocumentElement) -> DocumentElement) -> DocumentElementfn transform_paragraphs(transform : (DocumentElement) -> DocumentElement) -> ((DocumentElement) -> DocumentElement)fn transform_runs(transform : (DocumentElement) -> DocumentElement) -> ((DocumentElement) -> DocumentElement)fn xml_element(name : String, attributes? : Map[String, String], children? : Array[XmlNode]) -> XmlElementInstall
Download zipNative MoonBit DOCX to HTML/Markdown converter ported from Mammoth