markdown.bmx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. ' Copyright (c) 2023 Bruce A Henderson
  2. '
  3. ' Permission is hereby granted, free of charge, to any person obtaining a copy
  4. ' of this software and associated documentation files (the "Software"), to deal
  5. ' in the Software without restriction, including without limitation the rights
  6. ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. ' copies of the Software, and to permit persons to whom the Software is
  8. ' furnished to do so, subject to the following conditions:
  9. '
  10. ' The above copyright notice and this permission notice shall be included in
  11. ' all copies or substantial portions of the Software.
  12. '
  13. ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. ' THE SOFTWARE.
  20. '
  21. SuperStrict
  22. ModuleInfo "Version: 1.01"
  23. ModuleInfo "Author: Bruce A Henderson"
  24. ModuleInfo "License: MIT"
  25. ModuleInfo "md4c - Copyright (c) Martin Mitas - https://github.com/woollybah/MarkdownEdit_md4c"
  26. ModuleInfo "Copyright: 2023 Bruce A Henderson"
  27. ModuleInfo "History: 1.01"
  28. ModuleInfo "History: Added TMDHtmlCodeHighlighter for code highlighting."
  29. ModuleInfo "History: 1.00"
  30. ModuleInfo "History: Initial Release"
  31. Rem
  32. bbdoc: A markdown processor.
  33. about: Can either use a custom renderer, or generate HTML directly.
  34. End Rem
  35. Module Text.Markdown
  36. Import "common.bmx"
  37. Rem
  38. bbdoc: A renderer for markdown parser events.
  39. End Rem
  40. Interface IMDRenderer
  41. Method EnterBlock:Int(block:TMDBlock)
  42. Method LeaveBlock:Int(block:TMDBlock)
  43. Method EnterSpan:Int(span:TMDSpan)
  44. Method LeaveSpan:Int(span:TMDSpan)
  45. Method Text:Int(text:String, textType:EMDTextType)
  46. End Interface
  47. Rem
  48. bbdoc:
  49. End Rem
  50. Type TMDHtmlCodeHighlighter Abstract
  51. Private
  52. Field _codeblock:TStringBuilder
  53. Field _output:TStringBuilder
  54. Field _lang:String
  55. Field _info:String[]
  56. Method _EnterCodeBlock:Int(block:TMDBlockCode)
  57. _codeblock = New TStringBuilder
  58. Local lang:SMDAttribute = block.Lang()
  59. If lang.size > 0 Then
  60. _lang = String.FromUTF8Bytes(lang.text, lang.size)
  61. End If
  62. local info:SMDAttribute = block.Info()
  63. If info.size > 0 Then
  64. _info = info.SubsToStringArray()
  65. End If
  66. Return 0
  67. End Method
  68. Method _LeaveCodeBlock:Int(block:TMDBlockCode)
  69. Local processed:Int = Text(_lang, _info, _codeblock.ToString(), _output)
  70. If Not processed Then
  71. _output.Append("<pre><code")
  72. If _lang Then
  73. _output.Append(" class=~qlanguage-").Append(_lang).Append("~q")
  74. End If
  75. _output.Append(">")
  76. _output.Append(_codeblock.ToString()) ' TODO - escape
  77. _output.Append("</code></pre>")
  78. End If
  79. End Method
  80. Method _CodeBlockText:Int(txt:String, textType:EMDTextType)
  81. _codeblock.Append(txt)
  82. End Method
  83. Public
  84. Rem
  85. bbdoc: Provides the text for a code block.
  86. returns: #True if the code was processed, #False if the default code block rendering should be used.
  87. about: If the code is processed, the output should be appended to @output.
  88. End Rem
  89. Method Text:Int(lang:String, info:String[], text:String, output:TStringBuilder) Abstract
  90. End Type
  91. Rem
  92. bbdoc: Html table of contents options.
  93. End Rem
  94. Type TMDHtmlTocOptions
  95. Field depth:Int
  96. Field placeHolder:String
  97. End Type
  98. Rem
  99. bbdoc: A Markdown text processor.
  100. End Rem
  101. Type TMarkdown
  102. Rem
  103. bbdoc: Parses markdown @text, feeding parser events into the supplied @renderer.
  104. End Rem
  105. Function Parse:Int(renderer:IMDRenderer, text:String, flags:EMDFlags = EMDFlags.DIALECT_COMMONMARK)
  106. Return bmx_md_parse(renderer, text, flags)
  107. End Function
  108. Rem
  109. bbdoc: Parses markdown @text, appending HTML into @output.
  110. End Rem
  111. Function ParseToHtml:Int(text:String, output:TStringBuilder, parserFlags:EMDFlags = EMDFlags.DIALECT_COMMONMARK,..
  112. rendererFlags:EMDHtmlFlags = EMDHtmlFlags.NONE,
  113. tocOptions:TMDHtmlTocOptions = Null,
  114. codehilite:TMDHtmlCodeHighlighter = Null)
  115. Local depth:Int = 0
  116. Local ph:Byte Ptr
  117. If tocOptions Then
  118. depth = tocOptions.depth
  119. ph = tocOptions.placeHolder.ToUTF8String()
  120. End If
  121. if codehilite Then
  122. codehilite._output = output
  123. End If
  124. Local res:Int = bmx_md_html(text, output, parserFlags, rendererFlags, depth, ph, codehilite)
  125. MemFree(ph)
  126. Return res
  127. End Function
  128. Private
  129. Function _HtmlOutput(text:Byte Ptr, size:UInt, output:TStringBuilder) { nomangle }
  130. output.AppendUTF8Bytes(text, Int(size))
  131. End Function
  132. Function _EnterBlock:Int(parser:IMDRenderer, blockType:EMDBlockType, detail:Byte Ptr) { nomangle }
  133. Local block:TMDBlock = BlockAs(blockType, detail)
  134. Return parser.EnterBlock(block)
  135. End Function
  136. Function _LeaveBlock:Int(parser:IMDRenderer, blockType:EMDBlockType, detail:Byte Ptr) { nomangle }
  137. Local block:TMDBlock = BlockAs(blockType, detail)
  138. Return parser.LeaveBlock(block)
  139. End Function
  140. Function _EnterSpan:Int(parser:IMDRenderer, spanType:EMDSpanType, detail:Byte Ptr) { nomangle }
  141. Local span:TMDSpan = SpanAs(spanType, detail)
  142. Return parser.EnterSpan(span)
  143. End Function
  144. Function _LeaveSpan:Int(parser:IMDRenderer, spanType:EMDSpanType, detail:Byte Ptr) { nomangle }
  145. Local span:TMDSpan = SpanAs(spanType, detail)
  146. Return parser.LeaveSpan(span)
  147. End Function
  148. Function _Text:Int(parser:IMDRenderer, textType:EMDTextType, text:String) { nomangle }
  149. Return parser.Text(text, textType)
  150. End Function
  151. Function _EnterCodeBlock:Int(hilite:TMDHtmlCodeHighlighter, blockType:EMDBlockType, detail:Byte Ptr) { nomangle }
  152. Local block:TMDBlockCode = TMDBlockCode(BlockAs(blockType, detail))
  153. Return hilite._EnterCodeBlock(block)
  154. End Function
  155. Function _LeaveCodeBlock:Int(hilite:TMDHtmlCodeHighlighter, blockType:EMDBlockType, detail:Byte Ptr) { nomangle }
  156. Local block:TMDBlockCode = TMDBlockCode(BlockAs(blockType, detail))
  157. Return hilite._LeaveCodeBlock(block)
  158. End Function
  159. Function _CodeBlockText:Int(hilite:TMDHtmlCodeHighlighter, textType:EMDTextType, text:String) { nomangle }
  160. Return hilite._CodeBlockText(text, textType)
  161. End Function
  162. Function BlockAs:TMDBlock(blockType:EMDBlockType, detail:Byte Ptr)
  163. Select blockType
  164. Case EMDBlockType.BLOCK_DOC
  165. Return New TMDBlockDoc(detail)
  166. Case EMDBlockType.BLOCK_QUOTE
  167. Return New TMDBlockQuote(detail)
  168. Case EMDBlockType.BLOCK_UL
  169. Return New TMDBlockUL(detail)
  170. Case EMDBlockType.BLOCK_OL
  171. Return New TMDBlockOL(detail)
  172. Case EMDBlockType.BLOCK_LI
  173. Return New TMDBlockLI(detail)
  174. Case EMDBlockType.BLOCK_HR
  175. Return New TMDBlockHR(detail)
  176. Case EMDBlockType.BLOCK_H
  177. Return New TMDBlockH(detail)
  178. Case EMDBlockType.BLOCK_CODE
  179. Return New TMDBlockCode(detail)
  180. Case EMDBlockType.BLOCK_HTML
  181. Return New TMDBlockHtml(detail)
  182. Case EMDBlockType.BLOCK_P
  183. Return New TMDBlockP(detail)
  184. Case EMDBlockType.BLOCK_TABLE
  185. Return New TMDBlockTable(detail)
  186. Case EMDBlockType.BLOCK_THEAD
  187. Return New TMDBlockTHead(detail)
  188. Case EMDBlockType.BLOCK_TBODY
  189. Return New TMDBlockTBody(detail)
  190. Case EMDBlockType.BLOCK_TR
  191. Return New TMDBlockTR(detail)
  192. Case EMDBlockType.BLOCK_TH
  193. Return New TMDBlockTH(detail)
  194. Case EMDBlockType.BLOCK_TD
  195. Return New TMDBlockTD(detail)
  196. End Select
  197. End Function
  198. Function SpanAs:TMDSpan(spanType:EMDSpanType, detail:Byte Ptr)
  199. Select spanType
  200. Case EMDSpanType.SPAN_EM
  201. Return New TMDSpanEM(detail)
  202. Case EMDSpanType.SPAN_STRONG
  203. Return New TMDSpanStrong(detail)
  204. Case EMDSpanType.SPAN_A
  205. Return New TMDSpanA(detail)
  206. Case EMDSpanType.SPAN_IMG
  207. Return New TMDSpanImg(detail)
  208. Case EMDSpanType.SPAN_CODE
  209. Return New TMDSpanCode(detail)
  210. Case EMDSpanType.SPAN_DEL
  211. Return New TMDSpanDel(detail)
  212. Case EMDSpanType.SPAN_LATEXMATH
  213. Return New TMDSpanLatexMath(detail)
  214. Case EMDSpanType.SPAN_LATEXMATH_DISPLAY
  215. Return New TMDSpanLatexMathDisplay(detail)
  216. Case EMDSpanType.SPAN_WIKILINK
  217. Return New TMDSpanWikiLink(detail)
  218. Case EMDSpanType.SPAN_U
  219. Return New TMDSpanU(detail)
  220. End Select
  221. End Function
  222. End Type
  223. Rem
  224. bbdoc: A markdown block.
  225. about: A block represents a part of document hierarchy structure like a paragraph or list item.
  226. End Rem
  227. Type TMDBlock Abstract
  228. Field detail:Byte Ptr
  229. Method GetType:EMDBlockType() Abstract
  230. End Type
  231. Rem
  232. bbdoc: A markdown block document body
  233. End Rem
  234. Type TMDBlockDoc Extends TMDBlock
  235. Method New(detail:Byte Ptr)
  236. Self.detail = detail
  237. End Method
  238. Method GetType:EMDBlockType() Override
  239. Return EMDBlockType.BLOCK_DOC
  240. End Method
  241. End Type
  242. Rem
  243. bbdoc: A markdown block block quote
  244. End Rem
  245. Type TMDBlockQuote Extends TMDBlock
  246. Method New(detail:Byte Ptr)
  247. Self.detail = detail
  248. End Method
  249. Method GetType:EMDBlockType() Override
  250. Return EMDBlockType.BLOCK_QUOTE
  251. End Method
  252. End Type
  253. Rem
  254. bbdoc: A markdown block unordered list
  255. End Rem
  256. Type TMDBlockUL Extends TMDBlock
  257. Method New(detail:Byte Ptr)
  258. Self.detail = detail
  259. End Method
  260. Method GetType:EMDBlockType() Override
  261. Return EMDBlockType.BLOCK_UL
  262. End Method
  263. Rem
  264. bbdoc: Non-zero if tight list, zero if loose.
  265. End Rem
  266. Method IsTight:Int()
  267. Return bmx_md_blockul_istight(detail)
  268. End Method
  269. Rem
  270. bbdoc: Item bullet character in Markdown source of the list.
  271. about: e.g. `-`, `+`, `*`.
  272. End Rem
  273. Method Mark:Int()
  274. Return bmx_md_blockul_mark(detail)
  275. End Method
  276. End Type
  277. Rem
  278. bbdoc: A markdown block ordered list
  279. End Rem
  280. Type TMDBlockOL Extends TMDBlock
  281. Method New(detail:Byte Ptr)
  282. Self.detail = detail
  283. End Method
  284. Method GetType:EMDBlockType() Override
  285. Return EMDBlockType.BLOCK_OL
  286. End Method
  287. Rem
  288. bbdoc: Start index of the ordered list.
  289. End Rem
  290. Method Start:UInt()
  291. Return bmx_md_blockol_start(detail)
  292. End Method
  293. Rem
  294. bbdoc: Non-zero if tight list, zero if loose.
  295. End Rem
  296. Method IsTight:Int()
  297. Return bmx_md_blockol_istight(detail)
  298. End Method
  299. Rem
  300. bbdoc: Character delimiting the item marks in MarkDown source.
  301. about: e.g. `.` or `)`
  302. End Rem
  303. Method MarkDelimiter:Int()
  304. Return bmx_md_blockol_markdelimiter(detail)
  305. End Method
  306. End Type
  307. Rem
  308. bbdoc: A markdown block list item
  309. End Rem
  310. Type TMDBlockLI Extends TMDBlock
  311. Method New(detail:Byte Ptr)
  312. Self.detail = detail
  313. End Method
  314. Method GetType:EMDBlockType() Override
  315. Return EMDBlockType.BLOCK_LI
  316. End Method
  317. Rem
  318. bbdoc: Can be non-zero only with MD_FLAG_TASKLISTS
  319. End Rem
  320. Method IsTask:Int()
  321. Return bmx_md_blockli_istask(detail)
  322. End Method
  323. Rem
  324. bbdoc: If IsTask, then one of `x`, `X` or ` `, otherwise undefined.
  325. End Rem
  326. Method TaskMark:Int()
  327. Return bmx_md_blockli_taskmark(detail)
  328. End Method
  329. Rem
  330. bbdoc: If IsTask, then offset in the input of the char between `[` and `]`.
  331. End Rem
  332. Method TaskMarkOffset:UInt()
  333. Return bmx_md_blockli_taskmarkoffset(detail)
  334. End Method
  335. End Type
  336. Rem
  337. bbdoc: A markdown block thematic break.
  338. End Rem
  339. Type TMDBlockHR Extends TMDBlock
  340. Method New(detail:Byte Ptr)
  341. Self.detail = detail
  342. End Method
  343. Method GetType:EMDBlockType() Override
  344. Return EMDBlockType.BLOCK_HR
  345. End Method
  346. End Type
  347. Rem
  348. bbdoc: A markdown header block.
  349. End Rem
  350. Type TMDBlockH Extends TMDBlock
  351. Method New(detail:Byte Ptr)
  352. Self.detail = detail
  353. End Method
  354. Method GetType:EMDBlockType() Override
  355. Return EMDBlockType.BLOCK_H
  356. End Method
  357. Rem
  358. bbdoc: Header level (1 - 6)
  359. End Rem
  360. Method Level:UInt()
  361. Return bmx_md_blockh_level(detail)
  362. End Method
  363. Rem
  364. bbdoc: An identifier, eg `{#some-id}` or autogenerated from the heading text
  365. End Rem
  366. Method Identifier:SMDAttribute()
  367. Return bmx_md_blockh_identifier(detail)
  368. End Method
  369. End Type
  370. Rem
  371. bbdoc: A markdown code block.
  372. End Rem
  373. Type TMDBlockCode Extends TMDBlock
  374. Method New(detail:Byte Ptr)
  375. Self.detail = detail
  376. End Method
  377. Method GetType:EMDBlockType() Override
  378. Return EMDBlockType.BLOCK_CODE
  379. End Method
  380. Rem
  381. bbdoc:
  382. End Rem
  383. Method Info:SMDAttribute()
  384. Return bmx_md_blockcode_info(detail)
  385. End Method
  386. Rem
  387. bbdoc:
  388. End Rem
  389. Method Lang:SMDAttribute()
  390. Return bmx_md_blockcode_lang(detail)
  391. End Method
  392. Rem
  393. bbdoc:
  394. End Rem
  395. Method FenceChar:Int()
  396. Return bmx_md_blockcode_fencechar(detail)
  397. End Method
  398. End Type
  399. Rem
  400. bbdoc: A markdown HTML block.
  401. End Rem
  402. Type TMDBlockHtml Extends TMDBlock
  403. Method New(detail:Byte Ptr)
  404. Self.detail = detail
  405. End Method
  406. Method GetType:EMDBlockType() Override
  407. Return EMDBlockType.BLOCK_HTML
  408. End Method
  409. End Type
  410. Rem
  411. bbdoc: A markdown paragraph block.
  412. End Rem
  413. Type TMDBlockP Extends TMDBlock
  414. Method New(detail:Byte Ptr)
  415. Self.detail = detail
  416. End Method
  417. Method GetType:EMDBlockType() Override
  418. Return EMDBlockType.BLOCK_P
  419. End Method
  420. End Type
  421. Rem
  422. bbdoc: A markdown table block.
  423. End Rem
  424. Type TMDBlockTable Extends TMDBlock
  425. Method New(detail:Byte Ptr)
  426. Self.detail = detail
  427. End Method
  428. Method GetType:EMDBlockType() Override
  429. Return EMDBlockType.BLOCK_TABLE
  430. End Method
  431. Rem
  432. bbdoc: The number of columns in the table.
  433. End Rem
  434. Method ColCount:UInt()
  435. Return bmx_md_blocktable_colcount(detail)
  436. End Method
  437. Rem
  438. bbdoc: The number of header rows.
  439. about: Always returns 1.
  440. End Rem
  441. Method HeadRowCount:UInt()
  442. Return bmx_md_blocktable_headrowcount(detail)
  443. End Method
  444. Rem
  445. bbdoc: The number of body rows.
  446. End Rem
  447. Method BodyRowCount:UInt()
  448. Return bmx_md_blocktable_bodyrowcount(detail)
  449. End Method
  450. End Type
  451. Rem
  452. bbdoc: A markdown table head block.
  453. End Rem
  454. Type TMDBlockTHead Extends TMDBlock
  455. Method New(detail:Byte Ptr)
  456. Self.detail = detail
  457. End Method
  458. Method GetType:EMDBlockType() Override
  459. Return EMDBlockType.BLOCK_THEAD
  460. End Method
  461. End Type
  462. Rem
  463. bbdoc: A markdown table body block.
  464. End Rem
  465. Type TMDBlockTBody Extends TMDBlock
  466. Method New(detail:Byte Ptr)
  467. Self.detail = detail
  468. End Method
  469. Method GetType:EMDBlockType() Override
  470. Return EMDBlockType.BLOCK_TBODY
  471. End Method
  472. End Type
  473. Rem
  474. bbdoc: A markdown table row block.
  475. End Rem
  476. Type TMDBlockTR Extends TMDBlock
  477. Method New(detail:Byte Ptr)
  478. Self.detail = detail
  479. End Method
  480. Method GetType:EMDBlockType() Override
  481. Return EMDBlockType.BLOCK_TR
  482. End Method
  483. End Type
  484. Rem
  485. bbdoc: A markdown table header cell block
  486. End Rem
  487. Type TMDBlockTH Extends TMDBlock
  488. Method New(detail:Byte Ptr)
  489. Self.detail = detail
  490. End Method
  491. Method GetType:EMDBlockType() Override
  492. Return EMDBlockType.BLOCK_TH
  493. End Method
  494. Rem
  495. bbdoc: Alignment
  496. End Rem
  497. Method Align:EMDAlign()
  498. Return bmx_md_blocktd_align(detail)
  499. End Method
  500. End Type
  501. Rem
  502. bbdoc: A markdown table cell block
  503. End Rem
  504. Type TMDBlockTD Extends TMDBlock
  505. Method New(detail:Byte Ptr)
  506. Self.detail = detail
  507. End Method
  508. Method GetType:EMDBlockType() Override
  509. Return EMDBlockType.BLOCK_TD
  510. End Method
  511. Rem
  512. bbdoc: Alignment
  513. End Rem
  514. Method Align:EMDAlign()
  515. Return bmx_md_blocktd_align(detail)
  516. End Method
  517. End Type
  518. Rem
  519. bbdoc: A markdown span.
  520. End Rem
  521. Type TMDSpan Abstract
  522. Field detail:Byte Ptr
  523. Method GetType:EMDSpanType() Abstract
  524. End Type
  525. Rem
  526. bbdoc: A markdown emphasize span.
  527. End Rem
  528. Type TMDSpanEM Extends TMDSpan
  529. Method New(detail:Byte Ptr)
  530. Self.detail = detail
  531. End Method
  532. Method GetType:EMDSpanType() Override
  533. Return EMDSpanType.SPAN_EM
  534. End Method
  535. End Type
  536. Rem
  537. bbdoc: A markdown strong span.
  538. End Rem
  539. Type TMDSpanStrong Extends TMDSpan
  540. Method New(detail:Byte Ptr)
  541. Self.detail = detail
  542. End Method
  543. Method GetType:EMDSpanType() Override
  544. Return EMDSpanType.SPAN_STRONG
  545. End Method
  546. End Type
  547. Rem
  548. bbdoc: A markdown hyperlink span.
  549. End Rem
  550. Type TMDSpanA Extends TMDSpan
  551. Method New(detail:Byte Ptr)
  552. Self.detail = detail
  553. End Method
  554. Method GetType:EMDSpanType() Override
  555. Return EMDSpanType.SPAN_A
  556. End Method
  557. Method HRef:SMDAttribute()
  558. Return bmx_md_spana_href(detail)
  559. End Method
  560. Method Title:SMDAttribute()
  561. Return bmx_md_spana_title(detail)
  562. End Method
  563. End Type
  564. Rem
  565. bbdoc: A markdown image span.
  566. End Rem
  567. Type TMDSpanImg Extends TMDSpan
  568. Method New(detail:Byte Ptr)
  569. Self.detail = detail
  570. End Method
  571. Method GetType:EMDSpanType() Override
  572. Return EMDSpanType.SPAN_IMG
  573. End Method
  574. Method Src:SMDAttribute()
  575. Return bmx_md_spanimg_src(detail)
  576. End Method
  577. Method Title:SMDAttribute()
  578. Return bmx_md_spanimg_title(detail)
  579. End Method
  580. End Type
  581. Rem
  582. bbdoc: A markdown code span.
  583. End Rem
  584. Type TMDSpanCode Extends TMDSpan
  585. Method New(detail:Byte Ptr)
  586. Self.detail = detail
  587. End Method
  588. Method GetType:EMDSpanType() Override
  589. Return EMDSpanType.SPAN_CODE
  590. End Method
  591. End Type
  592. Rem
  593. bbdoc: A markdown strikethrough span.
  594. End Rem
  595. Type TMDSpanDel Extends TMDSpan
  596. Method New(detail:Byte Ptr)
  597. Self.detail = detail
  598. End Method
  599. Method GetType:EMDSpanType() Override
  600. Return EMDSpanType.SPAN_DEL
  601. End Method
  602. End Type
  603. Rem
  604. bbdoc: A markdown latex math span.
  605. End Rem
  606. Type TMDSpanLatexMath Extends TMDSpan
  607. Method New(detail:Byte Ptr)
  608. Self.detail = detail
  609. End Method
  610. Method GetType:EMDSpanType() Override
  611. Return EMDSpanType.SPAN_LATEXMATH
  612. End Method
  613. End Type
  614. Rem
  615. bbdoc: A markdown latex math display span.
  616. End Rem
  617. Type TMDSpanLatexMathDisplay Extends TMDSpan
  618. Method New(detail:Byte Ptr)
  619. Self.detail = detail
  620. End Method
  621. Method GetType:EMDSpanType() Override
  622. Return EMDSpanType.SPAN_LATEXMATH_DISPLAY
  623. End Method
  624. End Type
  625. Rem
  626. bbdoc: A markdown wikilink span.
  627. End Rem
  628. Type TMDSpanWikiLink Extends TMDSpan
  629. Method New(detail:Byte Ptr)
  630. Self.detail = detail
  631. End Method
  632. Method GetType:EMDSpanType() Override
  633. Return EMDSpanType.SPAN_WIKILINK
  634. End Method
  635. Method Target:SMDAttribute()
  636. Return bmx_md_spanwikilink_target(detail)
  637. End Method
  638. End Type
  639. Rem
  640. bbdoc: A markdown underline span.
  641. End Rem
  642. Type TMDSpanU Extends TMDSpan
  643. Method New(detail:Byte Ptr)
  644. Self.detail = detail
  645. End Method
  646. Method GetType:EMDSpanType() Override
  647. Return EMDSpanType.SPAN_U
  648. End Method
  649. End Type
  650. Rem
  651. bbdoc: A markdown attribute.
  652. End Rem
  653. Struct SMDAttribute
  654. Field text:Byte Ptr
  655. Field size:UInt
  656. Field substrTypes:EMDTextType Ptr
  657. Field substrOffsets:UInt Ptr
  658. Method SubsToStringArray:String[]()
  659. Return bmx_md_attribute_substostringarray(Self)
  660. End Method
  661. End Struct
  662. Private
  663. Extern
  664. Function bmx_md_parse:Int(parser:IMDRenderer, text:String, flags:EMDFlags)
  665. Function bmx_md_html:Int(text:String, output:TStringBuilder, parserFlags:EMDFlags, ..
  666. rendererFlags:EMDHtmlFlags, depth:Int, ph:Byte Ptr, ch:Object)
  667. Function bmx_md_blockul_istight:Int(detail:Byte Ptr)
  668. Function bmx_md_blockul_mark:Int(detail:Byte Ptr)
  669. Function bmx_md_blockol_start:UInt(detail:Byte Ptr)
  670. Function bmx_md_blockol_istight:Int(detail:Byte Ptr)
  671. Function bmx_md_blockol_markdelimiter:Int(detail:Byte Ptr)
  672. Function bmx_md_blockli_istask:Int(detail:Byte Ptr)
  673. Function bmx_md_blockli_taskmark:Int(detail:Byte Ptr)
  674. Function bmx_md_blockli_taskmarkoffset:UInt(detail:Byte Ptr)
  675. Function bmx_md_blockh_level:UInt(detail:Byte Ptr)
  676. Function bmx_md_blockh_identifier:SMDAttribute(detail:Byte Ptr)
  677. Function bmx_md_blockcode_info:SMDAttribute(detail:Byte Ptr)
  678. Function bmx_md_blockcode_lang:SMDAttribute(detail:Byte Ptr)
  679. Function bmx_md_blockcode_fencechar:Int(detail:Byte Ptr)
  680. Function bmx_md_blocktable_colcount:UInt(detail:Byte Ptr)
  681. Function bmx_md_blocktable_headrowcount:UInt(detail:Byte Ptr)
  682. Function bmx_md_blocktable_bodyrowcount:UInt(detail:Byte Ptr)
  683. Function bmx_md_blocktd_align:EMDAlign(detail:Byte Ptr)
  684. Function bmx_md_spana_href:SMDAttribute(detail:Byte Ptr)
  685. Function bmx_md_spana_title:SMDAttribute(detail:Byte Ptr)
  686. Function bmx_md_spanimg_src:SMDAttribute(detail:Byte Ptr)
  687. Function bmx_md_spanimg_title:SMDAttribute(detail:Byte Ptr)
  688. Function bmx_md_spanwikilink_target:SMDAttribute(detail:Byte Ptr)
  689. Function bmx_md_attribute_substostringarray:String[](attr:SMDAttribute Var)
  690. End Extern