Fresh IDE . Check-in [1bfb28c992]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Unification of MiniMagAsm and BBcode formatting features and used tags. The formatting is now more HTML5 compatible. Full featured unordered and ordered lists for MiniMagAsm implemented.
Timelines: family | ancestors | descendants | both | FreshLibDev
Files: files | file ages | folders
SHA1:1bfb28c992f8505775cf3071d47c12359c804834
User & Date: johnfound 2018-10-01 17:48:44
Context
2018-10-17
12:00
Work on the bbcode parser and adapting the MiniMag parser to the new interfaces. check-in: 058c531ade user: johnfound tags: FreshLibDev
2018-10-01
17:48
Unification of MiniMagAsm and BBcode formatting features and used tags. The formatting is now more HTML5 compatible. Full featured unordered and ordered lists for MiniMagAsm implemented. check-in: 1bfb28c992 user: johnfound tags: FreshLibDev
07:51
BBCode parser added to the library. check-in: 63144560e5 user: johnfound tags: FreshLibDev
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to freshlib/data/bbcode.asm.

3
4
5
6
7
8
9

10
11
12
13
14
15
16
...
108
109
110
111
112
113
114

115
116
117
118
119
120
121
122
iglobal
PHashTable tableBBtags, tpl_func,                      \
        'b',       tagStrong,                          \
        '*',       tagListItem,                        \
        'i',       tagEm,                              \
        'u',       tagUnderlined,                      \
        's',       tagDel,                             \

        'url',     tagURL,                             \
        'img',     tagImg,                             \
        'quote',   tagQuote,                           \
        'code',    tagCode,                            \
        'size',    tagSize,                            \
        'color',   tagColor,                           \
        'list',    tagUL,                              \
................................................................................

iglobal

tagStrong       onetag '<strong>',                              0,              '</strong>',    0
tagEm           onetag '<em>',                                  0,              '</em>',        0
tagUnderlined   onetag '<span class="underlined">',             0,              '</span>',      0
tagDel          onetag '<del>',                                 0,              '</del>',       0

tagCode         onetag '<code class="',                         '">',           '</code>',      fBlockTag or fEmptyAttr or fDisableTags
tagQuote        onetag '<blockquote><header>',                  '</header>',    '</blockquote>',fBlockTag or fEmptyAttr
tagUL           onetag '<ul>',                                  0,              '</ul>',        fBlockTag
tagOL           onetag '<ol type="',                            '">',           '</ol>',        fBlockTag or fEmptyAttr
tagListItem     onetag '<li>',                                  0,              0,              fBlockTag
tagTable        onetag '<table>',                               0,              '</table>',     fBlockTag
tagTR           onetag '<tr>',                                  0,              '</tr>',        fBlockTag
tagTH           onetag '<th>',                                  0,              '</th>',        fBlockTag







>







 







>
|







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
iglobal
PHashTable tableBBtags, tpl_func,                      \
        'b',       tagStrong,                          \
        '*',       tagListItem,                        \
        'i',       tagEm,                              \
        'u',       tagUnderlined,                      \
        's',       tagDel,                             \
        'c',       tagInlineCode,                      \
        'url',     tagURL,                             \
        'img',     tagImg,                             \
        'quote',   tagQuote,                           \
        'code',    tagCode,                            \
        'size',    tagSize,                            \
        'color',   tagColor,                           \
        'list',    tagUL,                              \
................................................................................

iglobal

tagStrong       onetag '<strong>',                              0,              '</strong>',    0
tagEm           onetag '<em>',                                  0,              '</em>',        0
tagUnderlined   onetag '<span class="underlined">',             0,              '</span>',      0
tagDel          onetag '<del>',                                 0,              '</del>',       0
tagInlineCode   onetag '<code>',                                0,              '</code>',      0
tagCode         onetag '<code class="block ',                   '">',           '</code>',      fBlockTag or fEmptyAttr or fDisableTags
tagQuote        onetag '<blockquote><header>',                  '</header>',    '</blockquote>',fBlockTag or fEmptyAttr
tagUL           onetag '<ul>',                                  0,              '</ul>',        fBlockTag
tagOL           onetag '<ol type="',                            '">',           '</ol>',        fBlockTag or fEmptyAttr
tagListItem     onetag '<li>',                                  0,              0,              fBlockTag
tagTable        onetag '<table>',                               0,              '</table>',     fBlockTag
tagTR           onetag '<tr>',                                  0,              '</tr>',        fBlockTag
tagTH           onetag '<th>',                                  0,              '</th>',        fBlockTag

Changes to freshlib/data/markdown.asm.

11
12
13
14
15
16
17
18


19
20
21
22
23
24
25
..
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
...
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606

607
608
609
610

611
612
613

614
615
616
617
618
619
620


621
622
623
624
625
626

627
628
629
630
631


632
633
634
635
636


637
638
639
640
641


642
643

644
645
646
647
648
649
650
...
668
669
670
671
672
673
674
675
676
677



678
679
680






681

682
683




684
685
686
687
688
689
690
...
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
....
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357

1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395















1396
1397
1398
1399
1400
1401
1402
....
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517

1518
1519
1520
1521
1522
1523
1524
1525































































1526
1527
1528
1529
1530
1531
1532
....
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
....
1601
1602
1603
1604
1605
1606
1607






1608
1609
1610
1611
1612
1613
1614


1615
1616
1617
1618
1619
1620
1621
1622
....
1623
1624
1625
1626
1627
1628
1629




















1630
1631
1632
1633
1634
1635
1636
....
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
....
1843
1844
1845
1846
1847
1848
1849

1850
1851
1852
1853
1854
1855
1856
....
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
fcloseImage             = 2
fcloseInlineImage       = 3
fcloseObject            = 4


fblkQuote       = 1
fblkTable       = 2




fstateHeader    = $01
fstatePara      = $02
fstateWhite     = $04
fstateBold      = $08
fstateUnderline = $20
fstateStrikeout = $40
................................................................................

fstateTextNow  = $200         ; don't use the second byte for any other flags.
fstateTextPrev = $100

fstateInlineSource    =  $10000
fstateBlockSource     =  $20000
fstateTable           = $100000
fstateSubChapter      = $200000


; Translates some markdown text to HTML
; Arguments:
;     .markdown - pointer or handler of the markdown text.
;     .procFixLink - [proc .ptrLink] procedure that process the link address and returns
;                    handle to the processed link address. if [.procFixLink]=NULL, the links
;                    are inserted as they are in the HTML.
;     .fBacklinks - flag, that defines whether to insert after the headers back links to the
;                   table of contents item.
;     .pResult - pointer to TMarkdownResults structure where the result strings are returned.

;
; Returns:
;   The procedure returns  4 string handles in the TMarkdownResults structure pointed by
;   .pResult argument.

proc TranslateMarkdown2, .markdown, .procFixLink, .fBacklinks, .pResult, .lParam

................................................................................
        lea     esi, [esi+1]

.td_ok:
        or      [.state], fstatePara
        jmp     .process_char

.not_td_open:
        mov     word [edi], '<p'
        lea     edi, [edi+2]
        or      [.state], fstatePara

; is it bullet list?

        cmp     al, '*'
        jne     .close_p_tag

        cmp     byte [esi], ' '
        jne     .close_p_tag

        mov     dword [edi], ' cla'
        mov     dword [edi+4], 'ss="'
        mov     dword [edi+8], 'uli"'
        lea     edi, [edi+12]


        inc     esi
        mov     al, [esi]
        inc     esi


.close_p_tag:
        mov     byte [edi], '>'

        lea     edi, [edi+1]
        jmp     .process_char

.process_inline_code:
        mov     ecx, fstateInlineSource
        mov     ebx, 'code'
        jmp     .ProcessTag



.process_bold:
        mov     ecx, fstateBold
        mov     ebx, 'b'
        jmp     .ProcessTag



.process_italic:
        mov     ecx, fstateItalic
        mov     ebx, 'i'
        jmp     .ProcessTag



.process_underline:
        mov     ecx, fstateUnderline
        mov     ebx, 'u'
        jmp     .ProcessTag



.process_strikeout:
        mov     ecx, fstateStrikeout
        mov     ebx, 's'



; ecx = state mask
; ebx = html tag

.ProcessTag:
        mov     dl, al

        test    [.state], ecx
        jz      .start_tag

; close tag
................................................................................
        je      .normal_char

        or      [.state], ecx

; open tag
        mov     byte [edi], '<'
        lea     edi, [edi+1]

.finish_tag:
        mov     [edi], ebx




.taglen:
        lea     edi, [edi+1]






        shr     ebx, 8

        jnz     .taglen





        mov     byte [edi], '>'
        lea     edi, [edi+1]

        jmp     .scan_line2


.white_space:
................................................................................
        mov     ecx, [.last_header]
        add     ecx, '/h0>'
        mov     [edi], ecx
        lea     edi, [edi+4]

        and     [.state], not (fstateHeader or fstateTextNow)   ; For the paragraph flow, the header loops like empty line.

; after the header end, starts subchapter

        mov     dword [edi], '<div'
        mov     dword [edi+4], ' cla'
        mov     dword [edi+8], 'ss="'
        mov     dword [edi+12], 'chap'
        mov     dword [edi+16], 'ter"'
        mov     byte  [edi+20], '>'
        add     edi, 21

        or      [.state], fstateSubChapter

.crlf:
        test    [.state], fstateTextPrev or fstateTextNow
        jz     @f
        mov     word [edi], $0a0d
        lea     edi, [edi+2]
@@:
        test    al, al
        jnz     .line_start2

        call    .close_subchapter

.finish:
        mov     dword [edi], 0
        stdcall StrCat, [.result], [.pHTML]
        retn


.is_link_begin:
................................................................................
        lea     edi, [edi+9]

        and     [.state], not fstateBlockSource
        jmp     .skip2

;....................................................................

.close_paragraph:
        test    [.state], fstatePara
        jz      .close_para_ok

        call    .close_inlines
        call    .close_all_links

        test    [.state], fstateTable
        jnz     .close_td

        mov     dword [edi], '</p>'
        lea     edi, [edi+4]
        jmp     .close_para_ok

.close_td:
        mov     dword [edi], '</td'
        mov     dword [edi+4], '>'+($0a0d shl 8)
        lea     edi, [edi+7]

.close_para_ok:
        and     [.state], not fstatePara
        retn

;....................................................................

.close_subchapter:

        test    [.state], fstateSubChapter
        jz      .close_subchapter_ok

        mov     dword [edi], '</di'
        mov      word [edi+4], 'v>'
        add     edi, 6

        and     [.state], not fstateSubChapter

.close_subchapter_ok:
        retn

;....................................................................

; closes all open inline tags.

.close_inlines:


        test    [.state], fstateBold
        jz      .bold_ok

        mov     dword [edi], '</b>'
        add     edi, 4

.bold_ok:
        test    [.state], fstateItalic
        jz      .italic_ok

        mov     dword [edi], '</i>'
        add     edi, 4

.italic_ok:
        test    [.state], fstateUnderline
        jz      .underline_ok

        mov     dword [edi], '</u>'
        add     edi, 4

.underline_ok:
        test    [.state], fstateStrikeout
        jz      .strike_ok

        mov     dword [edi], '</s>'
        add     edi, 4

.strike_ok:
        test    [.state], fstateInlineSource
        jz      .inline_source_ok

        mov     dword [edi],   '</co'
        mov     dword [edi+4], 'de>'
        add     edi, 7

.inline_source_ok:
        and     [.state], not (fstateBold or fstateItalic or fstateUnderline or fstateStrikeout or fstateInlineSource)















        retn


;....................................................................
; horizontal rule element

.horiz_rule:
................................................................................

; block quote
        call    .close_paragraph

        mov     al, fblkQuote
        call    .PushBlock

        mov     dword [edi],    '<div'
        mov     dword [edi+4],  ' cla'
        mov     dword [edi+8],  'ss="'
        mov     dword [edi+12], 'bq">'
        mov     dword [edi+16], '<h1 '
        mov     dword [edi+20], 'clas'
        mov     dword [edi+24], 's="b'
        mov     dword [edi+28], 'q">'
        lea     edi, [edi+31]

        push    esi
        add     esi, 6

        call    .CopyName

        mov     dword [edi],  '</h1'

        mov     byte [edi+4], '>'
        lea     edi, [edi+5]

        pop     esi
        jmp     .skip2


.not_quote:































































        cmp     dword [esi], ';key'
        jne     .not_keywords
        cmp     dword [esi+4], 'word'
        jne     .not_keywords
        cmp     byte [esi+8], 's'
        jne     .not_keywords

................................................................................

.not_desc:
        jmp     .skip2          ; ";" at the begining without keyword is comment. The line is ignored.


.end_block:
        call    .close_paragraph
        call    .close_subchapter
        call    .do_end_block
        jmp     .skip2

.end_all_blocks:
        call    .close_paragraph

.end_all_loop:
................................................................................
        retn

.what_block:
        cmp     eax, fblkQuote
        je      .end_quote
        cmp     eax, fblkTable
        je      .end_table







        clc
        retn

.end_quote:
        mov     dword [edi], '</di'
        mov     word  [edi+4], 'v>'


        lea     edi, [edi+6]
        clc
        retn

.end_table:
        mov     dword [edi], '</tr'
        mov     dword [edi+4], '>'+($0a0d shl 8)
        mov     dword [edi+7], '</ta'
................................................................................
        mov     dword [edi+11],'ble>'
        mov     word  [edi+15], $0a0d
        lea     edi, [edi+17]
        and     [.state], not fstateTable
        clc
        retn





















;....................................................................
.PushBlock:
        push    ecx
        mov     ecx, [.pblock]
        mov     [.blocks+ecx], al
        inc     ecx
        cmp     ecx, 1024
................................................................................
        retn

;....................................................................

; processing header items and building of the table of contents.

.header2:
        call    .close_subchapter
        xor     ecx, ecx

.scan_level2:
        inc     ecx
.scan_space2:
        lea     esi, [esi+1]
        mov     al, [esi]
................................................................................
        call    _NumToStrU
        mov     al, '.'
        stosb
        inc     ebx
        cmp     ebx, [esp]
        jbe     .loop_numbers


        pop     ecx
        jmp     .finID

.main:
        mov     eax, 'main'
        stosd

................................................................................

        mov     esi, edx

.end_cp_name:
        pop     edx ecx
        retn
endp









endmodule







|
>
>







 







<











>







 







<
<
<
<
<
<

|


|

|
<
<
|
>




>

|
<
>
|




|

>
>



|


>



|

>
>



|

>
>



|

>
>

<
>







 








|
|
>
>
>

<
<
>
>
>
>
>
>
|
>
|

>
>
>
>







 







<
<
<
<
<
<
<
<
<
<
<
<









<
<







 







|









<
<












<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



>




|
|





|
|





|
|





|
|





|
|
<



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
|
|
|
|
<
<
<
|






|
>
|
|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<







 







>
>
>
>
>
>





|
|
>
>
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<







 







>







 







<
<
<
<
<





11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
586
587
588
589
590
591
592






593
594
595
596
597
598
599


600
601
602
603
604
605
606
607
608

609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
655
...
673
674
675
676
677
678
679
680
681
682
683
684
685
686


687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
...
766
767
768
769
770
771
772












773
774
775
776
777
778
779
780
781


782
783
784
785
786
787
788
....
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326


1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338

















1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376

1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
....
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505



1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
....
1636
1637
1638
1639
1640
1641
1642

1643
1644
1645
1646
1647
1648
1649
....
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
....
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
....
1822
1823
1824
1825
1826
1827
1828

1829
1830
1831
1832
1833
1834
1835
....
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
....
2009
2010
2011
2012
2013
2014
2015





2016
2017
2018
2019
2020
fcloseImage             = 2
fcloseInlineImage       = 3
fcloseObject            = 4


fblkQuote       = 1
fblkTable       = 2
fblkUList       = 3
fblkOLIst       = 4
fblkSpoiler     = 5

fstateHeader    = $01
fstatePara      = $02
fstateWhite     = $04
fstateBold      = $08
fstateUnderline = $20
fstateStrikeout = $40
................................................................................

fstateTextNow  = $200         ; don't use the second byte for any other flags.
fstateTextPrev = $100

fstateInlineSource    =  $10000
fstateBlockSource     =  $20000
fstateTable           = $100000



; Translates some markdown text to HTML
; Arguments:
;     .markdown - pointer or handler of the markdown text.
;     .procFixLink - [proc .ptrLink] procedure that process the link address and returns
;                    handle to the processed link address. if [.procFixLink]=NULL, the links
;                    are inserted as they are in the HTML.
;     .fBacklinks - flag, that defines whether to insert after the headers back links to the
;                   table of contents item.
;     .pResult - pointer to TMarkdownResults structure where the result strings are returned.
;     .lParam - caller supplied parameter that is passed to procFixLink.
;
; Returns:
;   The procedure returns  4 string handles in the TMarkdownResults structure pointed by
;   .pResult argument.

proc TranslateMarkdown2, .markdown, .procFixLink, .fBacklinks, .pResult, .lParam

................................................................................
        lea     esi, [esi+1]

.td_ok:
        or      [.state], fstatePara
        jmp     .process_char

.not_td_open:






        cmp     al, '*'
        jne     .simple_p_tag

        cmp     byte [esi], ' '
        jne     .simple_p_tag

        mov     dword [edi], '<li>'


        add     edi, 4
        or      [.state], fstatePara

        inc     esi
        mov     al, [esi]
        inc     esi
        jmp     .process_char

.simple_p_tag:

        mov     dword [edi], '<p>'
        add     edi, 3
        jmp     .process_char

.process_inline_code:
        mov     ecx, fstateInlineSource
        mov     ebx, cInlineCodeTag
        jmp     .ProcessTag

cInlineCodeTag text "code"

.process_bold:
        mov     ecx, fstateBold
        mov     ebx, cBoldTag
        jmp     .ProcessTag

cBoldTag text "strong"

.process_italic:
        mov     ecx, fstateItalic
        mov     ebx, cItalicTag
        jmp     .ProcessTag

cItalicTag text "em"

.process_underline:
        mov     ecx, fstateUnderline
        mov     ebx, cUnderlinedTag
        jmp     .ProcessTag

cUnderlinedTag text 'span class="underlined"'

.process_strikeout:
        mov     ecx, fstateStrikeout
        mov     ebx, cStrikedTag

cStrikedTag text "del"

; ecx = state mask

; ebx = pointer to html tag string
.ProcessTag:
        mov     dl, al

        test    [.state], ecx
        jz      .start_tag

; close tag
................................................................................
        je      .normal_char

        or      [.state], ecx

; open tag
        mov     byte [edi], '<'
        lea     edi, [edi+1]

.copy_start:
        mov     al, [ebx]
        inc     ebx
        test    al, al
        jz      .end_tag



        stosb
        jmp     .copy_start


.finish_tag:
        mov     al, [ebx]
        lea     ebx, [ebx+1]
        cmp     al, " "
        jbe     .end_tag

        stosb
        jmp     .finish_tag

.end_tag:
        mov     byte [edi], '>'
        lea     edi, [edi+1]

        jmp     .scan_line2


.white_space:
................................................................................
        mov     ecx, [.last_header]
        add     ecx, '/h0>'
        mov     [edi], ecx
        lea     edi, [edi+4]

        and     [.state], not (fstateHeader or fstateTextNow)   ; For the paragraph flow, the header loops like empty line.













.crlf:
        test    [.state], fstateTextPrev or fstateTextNow
        jz     @f
        mov     word [edi], $0a0d
        lea     edi, [edi+2]
@@:
        test    al, al
        jnz     .line_start2



.finish:
        mov     dword [edi], 0
        stdcall StrCat, [.result], [.pHTML]
        retn


.is_link_begin:
................................................................................
        lea     edi, [edi+9]

        and     [.state], not fstateBlockSource
        jmp     .skip2

;....................................................................

.close_paragraph:       ; the <p> and <li> tags are not closed actually. Only the <td> tags.
        test    [.state], fstatePara
        jz      .close_para_ok

        call    .close_inlines
        call    .close_all_links

        test    [.state], fstateTable
        jnz     .close_td



        jmp     .close_para_ok

.close_td:
        mov     dword [edi], '</td'
        mov     dword [edi+4], '>'+($0a0d shl 8)
        lea     edi, [edi+7]

.close_para_ok:
        and     [.state], not fstatePara
        retn

;....................................................................

















; closes all open inline tags.

.close_inlines:
        push    esi

        test    [.state], fstateBold
        jz      .bold_ok

        mov     esi, cBoldTag
        call    .copy_one_close_tag

.bold_ok:
        test    [.state], fstateItalic
        jz      .italic_ok

        mov     esi, cItalicTag
        call    .copy_one_close_tag

.italic_ok:
        test    [.state], fstateUnderline
        jz      .underline_ok

        mov     esi, cUnderlinedTag
        call    .copy_one_close_tag

.underline_ok:
        test    [.state], fstateStrikeout
        jz      .strike_ok

        mov     esi, cStrikedTag
        call    .copy_one_close_tag

.strike_ok:
        test    [.state], fstateInlineSource
        jz      .inline_source_ok

        mov     esi, cInlineCodeTag
        call    .copy_one_close_tag


.inline_source_ok:
        and     [.state], not (fstateBold or fstateItalic or fstateUnderline or fstateStrikeout or fstateInlineSource)
        pop     esi
        retn

.copy_one_close_tag:
        mov     ax, '</'
        stosw

.coct_loop:
        lodsb
        cmp     al, " "
        jbe     .end_coct
        stosb
        jmp     .coct_loop

.end_coct:
        retn


;....................................................................
; horizontal rule element

.horiz_rule:
................................................................................

; block quote
        call    .close_paragraph

        mov     al, fblkQuote
        call    .PushBlock

        mov     dword [edi],    '<blo'
        mov     dword [edi+4],  'ckqu'
        mov     dword [edi+8],  'ote>'
        mov     dword [edi+12], '<hea'
        mov     dword [edi+16], 'der>'



        lea     edi, [edi+20]

        push    esi
        add     esi, 6

        call    .CopyName

        mov     dword [edi],   '</he'
        mov     dword [edi+4], 'ader'
        mov     byte  [edi+8], '>'
        lea     edi, [edi+9]

        pop     esi
        jmp     .skip2


.not_quote:
        cmp     dword [esi], ';uli'
        jne     .not_ulist
        cmp     word [esi+4], 'st'
        jne     .not_ulist

; unnumbered list
        call    .close_paragraph

        mov     al, fblkUList
        call    .PushBlock

        mov     dword [edi], '<ul>'
        add     edi, 4
        jmp     .skip2

.not_ulist:
        cmp     dword [esi], ';oli'
        jne     .not_olist
        cmp     word [esi+4], 'st'
        jne     .not_olist

; numbered list
        call    .close_paragraph

        mov     al, fblkOLIst
        call    .PushBlock

        mov     dword [edi], '<ol>'
        add     edi, 4
        jmp     .skip2

.not_olist:
        cmp     dword [esi],   ';spo'
        jne     .not_spoiler
        cmp     dword [esi+4], 'iler'
        jne     .not_spoiler

; spoiler
        call    .close_paragraph

        mov     al, fblkSpoiler
        call    .PushBlock

        mov     dword [edi],    '<det'    ;<details><summary>Spoiler</summary>
        mov     dword [edi+4],  'ails'
        mov     dword [edi+8],  '><su'
        mov     dword [edi+12], 'mmar'
        mov     word [edi+16],  'y>'
        add     edi, 18

        push    esi
        add     esi, 8
        call    .CopyName

        mov     dword [edi],   '</su'
        mov     dword [edi+4], 'mmar'
        mov     word  [edi+8], 'y>'
        add     edi, 10

        pop     esi
        jmp     .skip2

.not_spoiler:
        cmp     dword [esi], ';key'
        jne     .not_keywords
        cmp     dword [esi+4], 'word'
        jne     .not_keywords
        cmp     byte [esi+8], 's'
        jne     .not_keywords

................................................................................

.not_desc:
        jmp     .skip2          ; ";" at the begining without keyword is comment. The line is ignored.


.end_block:
        call    .close_paragraph

        call    .do_end_block
        jmp     .skip2

.end_all_blocks:
        call    .close_paragraph

.end_all_loop:
................................................................................
        retn

.what_block:
        cmp     eax, fblkQuote
        je      .end_quote
        cmp     eax, fblkTable
        je      .end_table
        cmp     eax, fblkUList
        je      .end_ulist
        cmp     eax, fblkOLIst
        je      .end_olist
        cmp     eax, fblkSpoiler
        je      .end_spoiler

        clc
        retn

.end_quote:
        mov     dword [edi],   '</bl'
        mov     dword [edi+4], 'ockq'
        mov     dword [edi+8], 'uote'
        mov     byte [edi+12], '>'
        lea     edi, [edi+13]
        clc
        retn

.end_table:
        mov     dword [edi], '</tr'
        mov     dword [edi+4], '>'+($0a0d shl 8)
        mov     dword [edi+7], '</ta'
................................................................................
        mov     dword [edi+11],'ble>'
        mov     word  [edi+15], $0a0d
        lea     edi, [edi+17]
        and     [.state], not fstateTable
        clc
        retn

.end_olist:
        mov     dword [edi], '</ol'
        jmp     .end_list

.end_ulist:
        mov     dword [edi], '</ul'
.end_list:
        mov     dword [edi+4], '>' + ($0a0d shl 8)
        add     edi, 7
        clc
        retn

.end_spoiler:
        mov     dword [edi],   '</de'
        mov     dword [edi+4], 'tail'
        mov     word  [edi+8], 's>'
        add     edi, 10
        clc
        retn

;....................................................................
.PushBlock:
        push    ecx
        mov     ecx, [.pblock]
        mov     [.blocks+ecx], al
        inc     ecx
        cmp     ecx, 1024
................................................................................
        retn

;....................................................................

; processing header items and building of the table of contents.

.header2:

        xor     ecx, ecx

.scan_level2:
        inc     ecx
.scan_space2:
        lea     esi, [esi+1]
        mov     al, [esi]
................................................................................
        call    _NumToStrU
        mov     al, '.'
        stosb
        inc     ebx
        cmp     ebx, [esp]
        jbe     .loop_numbers

        dec     edi
        pop     ecx
        jmp     .finID

.main:
        mov     eax, 'main'
        stosd

................................................................................

        mov     esi, edx

.end_cp_name:
        pop     edx ecx
        retn
endp









endmodule

Changes to freshlib/test_code/TestBBCode/bbcode.asm.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
include "%lib%/freshlib.asm"

include "hash_function.asm"


FILE_READ_CHUNK = 4096

;rb 237

start:
        InitializeAll


        stdcall TextCreate, sizeof.TText
        mov     edx, eax







|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
include "%lib%/freshlib.asm"

include "hash_function.asm"


FILE_READ_CHUNK = 4096

rb 237

start:
        InitializeAll


        stdcall TextCreate, sizeof.TText
        mov     edx, eax

Changes to freshlib/test_code/TestBBCode/prefix.tpl.

8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23


24
25
26
27
    h1, h2, h3, h4, h5, h6 {margin: 1rem 0 1rem 0;}:
    h1 {font-size: 2em}
    h2 {font-size: 1.8em}
    h3 {font-size: 1.6em}
    h4 {font-size: 1.4em}
    h5 {font-size: 1.2em}
    h6 {font-size: 1em}

    code {display: block; white-space: pre; background: #e0ffff; color: #000080; border-left: 8px solid #008080; padding: 1em 1ch; margin: 1em 2ch; }
    code.asm {background: black; color:lime; }
    table {border: 1px solid red;}
    td, th {border: 1px solid red; padding: 1em 2ch; }
    blockquote { border: 2px solid green; padding: 1em 2ch; }
    header {background-color: yellow; padding: 0 2ch; }
    img {display: block; margin: 1em auto; text-align: center;}
    img.emoticon { display: inline; margin: 0 4px; }
    p {color: green;}


  </style>

<body>








>
|








>
>




8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    h1, h2, h3, h4, h5, h6 {margin: 1rem 0 1rem 0;}:
    h1 {font-size: 2em}
    h2 {font-size: 1.8em}
    h3 {font-size: 1.6em}
    h4 {font-size: 1.4em}
    h5 {font-size: 1.2em}
    h6 {font-size: 1em}
    code {display: inline; font-size: 14px;}
    code.block {display: block; white-space: pre; background: #e0ffff; color: #000080; border-left: 8px solid #008080; padding: 1em 1ch; margin: 1em 2ch; }
    code.asm {background: black; color:lime; }
    table {border: 1px solid red;}
    td, th {border: 1px solid red; padding: 1em 2ch; }
    blockquote { border: 2px solid green; padding: 1em 2ch; }
    header {background-color: yellow; padding: 0 2ch; }
    img {display: block; margin: 1em auto; text-align: center;}
    img.emoticon { display: inline; margin: 0 4px; }
    p {color: green;}
    a.back::after {content: "^";}
    span.underlined {text-decoration: underline;}
  </style>

<body>

Changes to freshlib/test_code/TestBBCode/test.bbcode.

15
16
17
18
19
20
21


22
23
24
25
26
27
28
[b]This paragraph should be formatted with <strong></strong> tags.[/b]

[i]This paragraph should be formatted with <em></em> tags.[/i]

[u]This paragraph should be formatted with <span class="underlined"></span> tags.[/u]

[s]This paragraph should be formatted with <del></del> tags.[/s]



[url="><span style="color: red">]This is a XSS test. It should [b]NOT[/b] be colored in red![/url]

[url=https://board.asm32.info]This is a link <a href=""></a>[/url]

[url]https://board.asm32.info[/url]








>
>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[b]This paragraph should be formatted with <strong></strong> tags.[/b]

[i]This paragraph should be formatted with <em></em> tags.[/i]

[u]This paragraph should be formatted with <span class="underlined"></span> tags.[/u]

[s]This paragraph should be formatted with <del></del> tags.[/s]

[c]This paragraph should be formatted with <code></code> tags and monospaced font.[/c]

[url="><span style="color: red">]This is a XSS test. It should [b]NOT[/b] be colored in red![/url]

[url=https://board.asm32.info]This is a link <a href=""></a>[/url]

[url]https://board.asm32.info[/url]

Changes to freshlib/test_code/TestMarkdown/TestMarkdown.asm.

19
20
21
22
23
24
25





26
27
28
29
30
31
32
33
34
35
36


37
38
39
40
41
42
43
include "%lib%/freshlib.asm"


uglobal
  Result TMarkdownResults
endg








start:
        InitializeAll

; place your code here.

        stdcall ReadTheInputSlow

        stdcall TranslateMarkdown, edi, 0, 0, Result



        stdcall FileWriteString, [STDOUT], [Result.hContent]


        FinalizeAll
        stdcall TerminateAll, 0









>
>
>
>
>









|

>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
include "%lib%/freshlib.asm"


uglobal
  Result TMarkdownResults
endg

iglobal
  cHeader file "../TestBBCode/prefix.tpl"
          dd 0
endg



start:
        InitializeAll

; place your code here.

        stdcall ReadTheInputSlow

        stdcall TranslateMarkdown2, edi, 0, TRUE, Result, 0

        stdcall FileWriteString, [STDOUT], cHeader
        stdcall FileWriteString, [STDOUT], [Result.hIndex]
        stdcall FileWriteString, [STDOUT], [Result.hContent]


        FinalizeAll
        stdcall TerminateAll, 0


Changes to freshlib/test_code/TestMarkdown/TestMarkdown.fpr.

cannot compute difference between binary files

Deleted freshlib/test_code/TestMarkdown/image.png.

cannot compute difference between binary files

Changes to freshlib/test_code/TestMarkdown/test.markdown.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27











28
29





















30
31
32

33

34












































































35
36
37
38
39
40
41
42
43
44
45
46
# Header 1

This is a test file for the markdown parser.


## Header 1.1

Here are some image:

           [!img1][Some alt text]

           [!image.png]

And here, some object:

        [$128x48:test.swf][With inline address.]

        [$Flash1][This is simple demonstration of Fresh IDE power.]

        [$Flash2][Broken link processing]

        [$test.swf][There should be no size, but the animation should appear.]

        [$x480test.swf][Broken3]

## Header 1.2












Another paragraph.






















Some more text to test the sub-chapters.

### Header 1.2.1


















































































[$Flash1] 64x48:test.swf
[$Flash2] 64:test.swf
[!img1] image.png







|

|


|

|



|

|
|
|
|
|
|
|
|
|
|
|

|

>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<
>

>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Test of the MiniMagAsm markup.

This is a test file for the MiniMagAsm kind of markdown parser.


## Header 1

Here are some images:

           [!img1][Some alt text]

           [!../TestBBCode/anon.svg]

;And here, some object:
;
;        [$128x48:test.swf][With inline address.]
;
;        [$Flash1][This is simple demonstration of Fresh IDE power.]
;
;        [$Flash2][Broken link processing]
;
;        [$test.swf][There should be no size, but the animation should appear.]
;
;        [$x480test.swf][Broken3]

## Code block without syntax specified

;begin
        stdcall LoadBinaryFile, "prefix.tpl"
        jc      .prefix_ok
        push    eax
        stdcall FileWrite, [STDOUT], eax, ecx
        pop     eax
.prefix_ok:

;end


Another paragraph.

;quote Anonymous
<<Block quote with author name. and nested block quote with formatting>>
;quote johnfound
Here is my *super asm* code! (Code block with language specified.)

;begin asm
        stdcall LoadBinaryFile, "prefix.tpl"
        jc      .prefix_ok
        push    eax
        stdcall FileWrite, [STDOUT], eax, ecx
        pop     eax
.prefix_ok:

;end

;end

Your /code/ *sucks!*

;end

Some more text to test the sub-chapters.


### Bold and italic.

Another chapter.

   *This is bold*

   /This is italic/

#### Level 4

;ulist
* List item 1

* List item 2

* List item 3
;end

;olist
* List item 1

* List item 2
;ulist
* Subitem 1

* Subitem 2

* Subitem 3
;end

* List item 3
;end

##### Level 5

Table formatting:

;table
1

2

3

;-------------------

4

5

6

;---------------------

7

8

9

;end

###### Level 6

  The maximal level of H tags.

;spoiler Spoiler
  Vader is Luke's father!
;end


### Underlined and Strikethrough.

  _This is underlined_

  -Deleted text-

### One more header.

 This is inline `code formatting`, displayed with monospaced font.


[$Flash1] 64x48:test.swf
[$Flash2] 64:test.swf
[!img1] ../TestBBCode/anon.svg