Browse Source

enable HTML5 tags handling with `with_html5_tags` function

Masayuki Matsuki 5 years ago
parent
commit
51561a1892
3 changed files with 43 additions and 0 deletions
  1. 5
    0
      Discount.xs
  2. 14
    0
      lib/Text/Markdown/Discount.pm
  3. 24
    0
      t/13.html5.t

+ 5
- 0
Discount.xs View File

@@ -72,3 +72,8 @@ TextMarkdown__markdown(sv_str, flags)
72 72
         RETVAL = r;
73 73
     OUTPUT:
74 74
         RETVAL
75
+
76
+void
77
+TextMarkdown_with_html5_tags()
78
+    CODE:
79
+        mkd_with_html5_tags();

+ 14
- 0
lib/Text/Markdown/Discount.pm View File

@@ -87,6 +87,20 @@ is not compatible with the C<markdown()> function in L<Text::Markdown>.
87 87
 
88 88
 I<markdown> is exported by default.
89 89
 
90
+
91
+=head2 FUNCTION
92
+
93
+=over
94
+
95
+=item C<Text::Markdown::Discount::with_html5_tags()>
96
+
97
+Enabling html5 elements handling.
98
+
99
+Once calling it, following B<ALL> C<< Text::Markdown::Discount::markdown() >>
100
+calls are affected with html5 enabled in same Perl process and there is no way to disable it.
101
+
102
+=back
103
+
90 104
 =head1 SEE ALSO
91 105
 
92 106
 There are other modules on CPAN for converting Markdown:

+ 24
- 0
t/13.html5.t View File

@@ -0,0 +1,24 @@
1
+use strict;
2
+use warnings;
3
+use utf8;
4
+use Test::More tests => 2;
5
+use Text::Markdown::Discount qw/markdown/;
6
+
7
+my $html = '<article>abc</article>';
8
+{
9
+    is trim(markdown($html)), '<p><article>abc</article></p>';
10
+}
11
+
12
+Text::Markdown::Discount::with_html5_tags();
13
+
14
+{
15
+    my $md = Text::Markdown::Discount->new(html5 => 1);
16
+    is trim(markdown($html)), '<article>abc</article>';
17
+}
18
+
19
+sub trim {
20
+    my $text = shift;
21
+    $text =~ s/\A\s+//ms;
22
+    $text =~ s/\s+$//ms;
23
+    $text;
24
+}

Loading…
Cancel
Save