hoedown.monkey2 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. Namespace hoedown
  2. #Import "hoedown/src/document.h"
  3. #Import "hoedown/src/html.h"
  4. #Import "hoedown/src/autolink.c"
  5. #Import "hoedown/src/buffer.c"
  6. #Import "hoedown/src/document.c"
  7. #Import "hoedown/src/escape.c"
  8. #Import "hoedown/src/html_blocks.c"
  9. #Import "hoedown/src/html_smartypants.c"
  10. #Import "hoedown/src/html.c"
  11. #Import "hoedown/src/stack.c"
  12. #Import "hoedown/src/version.c"
  13. Extern
  14. 'buffer
  15. Struct hoedown_buffer
  16. End
  17. Function hoedown_buffer_new:hoedown_buffer Ptr( unit:Int )
  18. Function hoedown_buffer_reset( buf:hoedown_buffer Ptr )
  19. Function hoedown_buffer_free( buf:hoedown_buffer Ptr )
  20. Function hoedown_buffer_put( buf:hoedown_buffer Ptr,data:UByte Ptr,size:Int )
  21. Function hoedown_buffer_cstr:Void Ptr( buf:hoedown_buffer Ptr )
  22. 'renderer
  23. Struct hoedown_renderer
  24. End
  25. Enum hoedown_html_flags
  26. End
  27. Const HOEDOWN_HTML_NONE:hoedown_html_flags="(hoedown_html_flags)0"
  28. Const HOEDOWN_HTML_SKIP_HTML:hoedown_html_flags
  29. Const HOEDOWN_HTML_ESCAPE:hoedown_html_flags
  30. Const HOEDOWN_HTML_HARD_WRAP:hoedown_html_flags
  31. Const HOEDOWN_HTML_USE_XHTML:hoedown_html_flags
  32. Function hoedown_html_renderer_new:hoedown_renderer Ptr( render_flags:hoedown_html_flags,nesting_level:Int )
  33. Function hoedown_html_toc_renderer_new:hoedown_renderer Ptr( nesting_level:Int )
  34. Function hoedown_html_renderer_free( renderer:hoedown_renderer Ptr )
  35. 'document
  36. Struct hoedown_document
  37. End
  38. Enum hoedown_extensions
  39. End
  40. Const HOEDOWN_EXT_NONE:hoedown_extensions="(hoedown_extensions)0"
  41. Const HOEDOWN_EXT_TABLES:hoedown_extensions
  42. Const HOEDOWN_EXT_FENCED_CODE:hoedown_extensions
  43. Const HOEDOWN_EXT_FOOTNOTES:hoedown_extensions
  44. Const HOEDOWN_EXT_AUTOLINK:hoedown_extensions
  45. Const HOEDOWN_EXT_STRIKETHROUGH:hoedown_extensions
  46. Const HOEDOWN_EXT_UNDERLINE:hoedown_extensions
  47. Const HOEDOWN_EXT_HIGHLIGHT:hoedown_extensions
  48. Const HOEDOWN_EXT_QUOTE:hoedown_extensions
  49. Const HOEDOWN_EXT_SUPERSCRIPT:hoedown_extensions
  50. Const HOEDOWN_EXT_MATH:hoedown_extensions
  51. Const HOEDOWN_EXT_NO_INTRA_EMPHASIS:hoedown_extensions
  52. Const HOEDOWN_EXT_SPACE_HEADERS:hoedown_extensions
  53. Const HOEDOWN_EXT_MATH_EXPLICIT:hoedown_extensions
  54. Const HOEDOWN_EXT_DISABLE_INDENTED_CODE:hoedown_extensions
  55. #rem
  56. Enum hoedown_extensions
  57. HOEDOWN_EXT_TABLES
  58. HOEDOWN_EXT_FENCED_CODE
  59. HOEDOWN_EXT_FOOTNOTES
  60. HOEDOWN_EXT_AUTOLINK
  61. HOEDOWN_EXT_STRIKETHROUGH
  62. HOEDOWN_EXT_UNDERLINE
  63. HOEDOWN_EXT_HIGHLIGHT
  64. HOEDOWN_EXT_QUOTE
  65. HOEDOWN_EXT_SUPERSCRIPT
  66. HOEDOWN_EXT_MATH
  67. HOEDOWN_EXT_NO_INTRA_EMPHASIS
  68. HOEDOWN_EXT_SPACE_HEADERS
  69. HOEDOWN_EXT_MATH_EXPLICIT
  70. HOEDOWN_EXT_DISABLE_INDENTED_CODE
  71. End
  72. #end
  73. Function hoedown_document_new:hoedown_document Ptr( renderer:hoedown_renderer Ptr,extensions:hoedown_extensions,max_nesting:Int )
  74. Function hoedown_document_render( doc:hoedown_document Ptr,ob:hoedown_buffer Ptr,data:CString,size:Int )
  75. Function hoedown_document_render_inline( doc:hoedown_document Ptr,ob:hoedown_buffer Ptr,data:CString,size:Int )
  76. Function hoedown_document_free( doc:hoedown_document Ptr )
  77. Public
  78. Function MarkdownToHtml:String( markdown:String,toc:Bool=False )
  79. Local ob:=hoedown_buffer_new( 4096 )
  80. Local r:hoedown_renderer Ptr
  81. If toc
  82. r=hoedown_html_toc_renderer_new( 10 )
  83. Else
  84. r=hoedown_html_renderer_new( HOEDOWN_HTML_NONE,10 )
  85. Endif
  86. Local doc:=hoedown_document_new( r,HOEDOWN_EXT_TABLES|HOEDOWN_EXT_FENCED_CODE,10 )
  87. hoedown_document_render( doc,ob,markdown,markdown.Utf8Length )
  88. Local html:=String.FromCString( hoedown_buffer_cstr( ob ) )
  89. hoedown_document_free( doc )
  90. hoedown_html_renderer_free( r )
  91. hoedown_buffer_free( ob )
  92. Return html
  93. End