OSDN Git Service

Plugin::NewslashHelpers: add strip_html_tag()
authorhylom <hylom@users.sourceforge.jp>
Fri, 19 Apr 2019 12:03:45 +0000 (21:03 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 19 Apr 2019 12:03:45 +0000 (21:03 +0900)
src/newslash_web/lib/Newslash/Plugin/NewslashHelpers.pm

index ceeea8a..fce0098 100644 (file)
@@ -45,6 +45,7 @@ sub register {
                   the_path
                   get_timestamp_by_id
                   tidy_html clean_html escape_html format_htmltext escape_plaintext strip_by_mode
+                  strip_html_tag
                   get_authors
                   extract_description
                 ]) {
@@ -180,6 +181,25 @@ sub _get_authors {
     return $authors;
 }
 
+=head2 strip_html_tag($text)
+
+  strip html tag from text
+
+=cut
+
+sub _strip_html_tag {
+    my ($c, $str) = @_;
+    my $dom = Mojo::DOM->new($str);
+    my $text;
+    if (!$dom) {
+        $c->app->log->error("NewslashHelpers::strip_html_tag: html parse failed: $str");
+        $text = $str;
+    }
+    else {
+        $text = $dom->all_text;
+    }
+}
+
 =head2 extract_description($text, $min_length, $max_length)
 
   extract description from text string