Browse Source

upgrade Discount to 2.1.7 and add more test. close #17

Masayoshi Sekimura 5 years ago
parent
commit
33c54a64b9

+ 1
- 1
discount/COPYRIGHT View File

@@ -10,7 +10,7 @@ are met:
10 10
 2.  Redistributions in binary form must reproduce the original copyright
11 11
     notice, this list of conditions and the following disclaimer in the
12 12
     documentation and/or other materials provided with the distribution.
13
-    Neither my name (David L Parsons) nor the names of contributors to
13
+3.  Neither my name (David L Parsons) nor the names of contributors to
14 14
     this code may be used to endorse or promote products derived
15 15
     from this work without specific prior written permission.
16 16
 

+ 7
- 7
discount/Makefile.in View File

@@ -64,7 +64,7 @@ $(DESTDIR)$(LIBDIR):
64 64
 	@INSTALL_DIR@ $(DESTDIR)$(LIBDIR)
65 65
 
66 66
 version.o: version.c VERSION
67
-	$(CC) -DVERSION=\"`cat VERSION`\" -c version.c
67
+	$(CC) $(CFLAGS) -DVERSION=\"`cat VERSION`\" -c version.c
68 68
 
69 69
 VERSION:
70 70
 	@true
@@ -76,23 +76,23 @@ blocktags: mktags
76 76
 
77 77
 # example programs
78 78
 @THEME@theme:  theme.o $(MKDLIB) mkdio.h
79
-@THEME@	$(CC) $(LFLAGS) -o theme theme.o pgm_options.o -lmarkdown @LIBS@
79
+@THEME@	$(CC) $(CFLAGS) $(LFLAGS) -o theme theme.o pgm_options.o -lmarkdown @LIBS@
80 80
 
81 81
 
82 82
 mkd2html:  mkd2html.o $(MKDLIB) mkdio.h
83
-	$(CC) $(LFLAGS) -o mkd2html mkd2html.o -lmarkdown @LIBS@
83
+	$(CC) $(CFLAGS) $(LFLAGS) -o mkd2html mkd2html.o -lmarkdown @LIBS@
84 84
 
85 85
 markdown: main.o pgm_options.o $(MKDLIB)
86
-	$(CC) $(LFLAGS) -o markdown main.o pgm_options.o -lmarkdown @LIBS@
86
+	$(CC) $(CFLAGS) $(LFLAGS) -o markdown main.o pgm_options.o -lmarkdown @LIBS@
87 87
 	
88 88
 makepage:  makepage.c pgm_options.o $(MKDLIB) mkdio.h
89
-	$(CC) $(LFLAGS) -o makepage makepage.c pgm_options.o -lmarkdown @LIBS@
89
+	$(CC) $(CFLAGS) $(LFLAGS) -o makepage makepage.c pgm_options.o -lmarkdown @LIBS@
90 90
 
91 91
 pgm_options.o: pgm_options.c mkdio.h config.h
92
-	$(CC) -I. -c pgm_options.c
92
+	$(CC) $(CFLAGS) -I. -c pgm_options.c
93 93
 
94 94
 main.o: main.c mkdio.h config.h
95
-	$(CC) -I. -c main.c
95
+	$(CC) $(CFLAGS) -I. -c main.c
96 96
 
97 97
 $(MKDLIB): $(OBJS)
98 98
 	./librarian.sh make $(MKDLIB) VERSION $(OBJS)

+ 1
- 1
discount/VERSION View File

@@ -1 +1 @@
1
-2.1.6
1
+2.1.7

+ 13
- 2
discount/configure.inc View File

@@ -868,6 +868,18 @@ AC_C_INLINE() {
868 868
 # AC_SCALAR_TYPES checks to see if the compiler can generate 2 and 4 byte ints.
869 869
 #
870 870
 AC_SCALAR_TYPES () {
871
+
872
+    rc=1
873
+    LOGN "defining WORD & DWORD scalar types"
874
+    
875
+    if AC_QUIET AC_CHECK_HEADERS WinDef.h; then
876
+	# windows machine; BYTE, WORD, DWORD already
877
+	# defined
878
+	echo "#include <WinDef.h>" >> $__cwd/config.h
879
+	TLOG " (defined in WinDef.h)"
880
+	return 0
881
+    fi
882
+	
871 883
     cat > ngc$$.c << EOF
872 884
 #include <stdio.h>
873 885
 #include <string.h>
@@ -908,8 +920,6 @@ char **argv;
908 920
     exit(0);
909 921
 }
910 922
 EOF
911
-    rc=1
912
-    LOGN "defining WORD & DWORD scalar types"
913 923
     if $AC_CC ngc$$.c -o ngc$$; then
914 924
 	while [ "$1" ]; do
915 925
 	    case "$1" in
@@ -933,6 +943,7 @@ EOF
933 943
     0) TLOG "" ;;
934 944
     *) AC_FAIL " ** FAILED **" ;;
935 945
     esac
946
+    return $rc
936 947
 }
937 948
 
938 949
 

+ 13
- 3
discount/generate.c View File

@@ -73,6 +73,10 @@ isthisspace(MMIOT *f, int i)
73 73
 {
74 74
     int c = peek(f, i);
75 75
 
76
+    if ( c == EOF )
77
+	return 1;
78
+    if ( c & 0x80 )
79
+	return 0;
76 80
     return isspace(c) || (c < ' ');
77 81
 }
78 82
 
@@ -1582,11 +1586,17 @@ printblock(Paragraph *pp, MMIOT *f)
1582 1586
 
1583 1587
 
1584 1588
 static void
1585
-printcode(Line *t, MMIOT *f)
1589
+printcode(Line *t, char *lang, MMIOT *f)
1586 1590
 {
1587 1591
     int blanks;
1588 1592
 
1589
-    Qstring("<pre><code>", f);
1593
+    Qstring("<pre><code", f);
1594
+    if (lang) {
1595
+      Qstring(" class=\"", f);
1596
+      Qstring(lang, f);
1597
+      Qstring("\"", f);
1598
+    }
1599
+    Qstring(">", f);
1590 1600
     for ( blanks = 0; t ; t = t->next ) {
1591 1601
 	if ( S(t->text) > t->dle ) {
1592 1602
 	    while ( blanks ) {
@@ -1699,7 +1709,7 @@ display(Paragraph *p, MMIOT *f)
1699 1709
 	break;
1700 1710
 	
1701 1711
     case CODE:
1702
-	printcode(p->text, f);
1712
+	printcode(p->text, p->lang, f);
1703 1713
 	break;
1704 1714
 	
1705 1715
     case QUOTE:

+ 22
- 8
discount/markdown.c View File

@@ -177,6 +177,9 @@ splitline(Line *t, int cutpoint)
177 177
 }
178 178
 
179 179
 #define UNCHECK(l) ((l)->flags &= ~CHECKED)
180
+#define UNLESS_FENCED(t) if (fenced) { \
181
+    other = 1; l->count += (c == ' ' ? 0 : -1); \
182
+  } else { t; }
180 183
 
181 184
 /*
182 185
  * walk a line, seeing if it's any of half a dozen interesting regular
@@ -188,8 +191,8 @@ checkline(Line *l)
188 191
     int eol, i;
189 192
     int dashes = 0, spaces = 0,
190 193
 	equals = 0, underscores = 0,
191
-	stars = 0, tildes = 0,
192
-	backticks = 0;
194
+	stars = 0, tildes = 0, other = 0,
195
+	backticks = 0, fenced = 0;
193 196
 
194 197
     l->flags |= CHECKED;
195 198
     l->kind = chk_text;
@@ -206,16 +209,19 @@ checkline(Line *l)
206 209
 	if ( c != ' ' ) l->count++;
207 210
 
208 211
 	switch (c) {
209
-	case '-':  dashes = 1; break;
210
-	case ' ':  spaces = 1; break;
212
+	case '-':  UNLESS_FENCED(dashes = 1); break;
213
+	case ' ':  UNLESS_FENCED(spaces = 1); break;
211 214
 	case '=':  equals = 1; break;
212
-	case '_':  underscores = 1; break;
215
+	case '_':  UNLESS_FENCED(underscores = 1); break;
213 216
 	case '*':  stars = 1; break;
214 217
 #if WITH_FENCED_CODE
215
-	case '~':  tildes = 1; break;
216
-	case '`':  backticks = 1; break;
218
+	case '~':  if (other) return; fenced = 1; tildes = 1; break;
219
+	case '`':  if (other) return; fenced = 1; backticks = 1; break;
217 220
 #endif
218
-	default:   return;
221
+	default:
222
+    other = 1;
223
+    l->count--;
224
+    if (!fenced) return;
219 225
 	}
220 226
     }
221 227
 
@@ -638,6 +644,14 @@ fencedcodeblock(ParagraphRoot *d, Line **ptr)
638 644
 	if ( iscodefence(r->next, first->count, first->kind) ) {
639 645
 	    (*ptr) = r->next->next;
640 646
 	    ret = Pp(d, first->next, CODE);
647
+      if (S(first->text) - first->count > 0) {
648
+        char *lang_attr = T(first->text) + first->count;
649
+        while ( *lang_attr != 0 && *lang_attr == ' ' ) lang_attr++;
650
+        ret->lang = strdup(lang_attr);
651
+      }
652
+      else {
653
+        ret->lang = 0;
654
+      }
641 655
 	    ___mkd_freeLine(first);
642 656
 	    ___mkd_freeLine(r->next);
643 657
 	    r->next = 0;

+ 1
- 0
discount/markdown.h View File

@@ -49,6 +49,7 @@ typedef struct paragraph {
49 49
     struct paragraph *down;	/* recompiled contents of this paragraph */
50 50
     struct line *text;		/* all the text in this paragraph */
51 51
     char *ident;		/* %id% tag for QUOTE */
52
+    char *lang;         /* lang attribute for CODE */
52 53
     enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
53 54
 	   HTML, STYLE, DL, UL, OL, AL, LISTITEM,
54 55
 	   HDR, HR, TABLE, SOURCE } typ;

+ 1
- 1
discount/mkd2html.c View File

@@ -81,7 +81,7 @@ char **argv;
81 81
     CREATE(footers);
82 82
     pgm = basename(argv[0]);
83 83
 
84
-    while ( argc ) {
84
+    while ( argc > 1 ) {
85 85
 	if ( strcmp(argv[1], "-css") == 0 ) {
86 86
 	    EXPAND(css) = argv[2];
87 87
 	    argc -= 2;

+ 2
- 0
discount/resource.c View File

@@ -51,6 +51,8 @@ ___mkd_freeParagraph(Paragraph *p)
51 51
 	___mkd_freeLines(p->text);
52 52
     if (p->ident)
53 53
 	free(p->ident);
54
+    if (p->lang)
55
+	free(p->lang);
54 56
     free(p);
55 57
 }
56 58
 

+ 3
- 0
discount/tags.c View File

@@ -26,6 +26,9 @@ mkd_define_tag(char *id, int selfclose)
26 26
      * either the standard or extra tag tables.
27 27
      */
28 28
     if ( !(p = mkd_search_tags(id, strlen(id))) ) {
29
+	/* extratags could be deallocated */
30
+	if ( S(extratags) == 0 )
31
+	    CREATE(extratags);
29 32
 	p = &EXPAND(extratags);
30 33
 	p->id = id;
31 34
 	p->size = strlen(id);

+ 49
- 0
discount/tests/code.t View File

@@ -100,6 +100,55 @@ code
100 100
 code
101 101
 ~~~</p>'
102 102
 
103
+try 'fenced code block with lang attribute' \
104
+'```lang
105
+code
106
+```' \
107
+'<pre><code class="lang">code
108
+</code></pre>'
109
+
110
+try 'fenced code block with lang-name attribute' \
111
+'```lang-name
112
+code
113
+```' \
114
+'<pre><code class="lang-name">code
115
+</code></pre>'
116
+
117
+try 'fenced code block with lang_name attribute' \
118
+'```lang_name
119
+code
120
+```' \
121
+'<pre><code class="lang_name">code
122
+</code></pre>'
123
+
124
+try 'fenced code block with lang attribute and space' \
125
+'``` lang
126
+code
127
+```' \
128
+'<pre><code class="lang">code
129
+</code></pre>'
130
+
131
+try 'fenced code block with lang attribute and multiple spaces' \
132
+'```       lang
133
+code
134
+```' \
135
+'<pre><code class="lang">code
136
+</code></pre>'
137
+
138
+try 'fenced code block with lang-name attribute and space' \
139
+'``` lang-name
140
+code
141
+```' \
142
+'<pre><code class="lang-name">code
143
+</code></pre>'
144
+
145
+try 'fenced code block with lang_name attribute and space' \
146
+'``` lang_name
147
+code
148
+```' \
149
+'<pre><code class="lang_name">code
150
+</code></pre>'
151
+
103 152
 fi
104 153
 
105 154
 summary $0

+ 1
- 1
lib/Text/Markdown/Discount.pm View File

@@ -25,7 +25,7 @@ our @EXPORT = qw(
25 25
 	
26 26
 );
27 27
 
28
-our $VERSION = '0.10';
28
+our $VERSION = '0.11';
29 29
 
30 30
 require XSLoader;
31 31
 XSLoader::load('Text::Markdown::Discount', $VERSION);

+ 31
- 1
t/12.utf8.t View File

@@ -1,7 +1,7 @@
1 1
 use strict;
2 2
 use warnings;
3 3
 use utf8;
4
-use Test::More tests => 4;
4
+use Test::More tests => 12;
5 5
 use Text::Markdown::Discount;
6 6
 
7 7
 {
@@ -18,3 +18,33 @@ use Text::Markdown::Discount;
18 18
     like $html, qr!<h1>あ</h1>!;
19 19
     ok !utf8::is_utf8($html);
20 20
 }
21
+
22
+{
23
+    my $perl_string = '*イーエム*';
24
+    my $html = Text::Markdown::Discount::markdown($perl_string);
25
+    like $html, qr!<em>イーエム</em>!;
26
+    ok utf8::is_utf8($html);
27
+}
28
+
29
+{
30
+    no utf8;
31
+    my $byte = '*イーエム*';
32
+    my $html = Text::Markdown::Discount::markdown($byte);
33
+    like $html, qr!<em>イーエム</em>!;
34
+    ok !utf8::is_utf8($html);
35
+}
36
+
37
+{
38
+    my $perl_string = '_イーエム_';
39
+    my $html = Text::Markdown::Discount::markdown($perl_string);
40
+    like $html, qr!<em>イーエム</em>!;
41
+    ok utf8::is_utf8($html);
42
+}
43
+
44
+{
45
+    no utf8;
46
+    my $byte = '_イーエム_';
47
+    my $html = Text::Markdown::Discount::markdown($byte);
48
+    like $html, qr!<em>イーエム</em>!;
49
+    ok !utf8::is_utf8($html);
50
+}