1 ## Copyright (C) 2009-2012 Søren Hauberg
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {[@var{text}, @var{status}] =} __strip_html_tags__ (@var{html_text})
21 ## Undocumented internal function.
24 ## Remove HTML tags from text. This is used as a simple HTML-to-text
27 function [text, status] = __strip_html_tags__ (html_text)
28 start = find (html_text == "<");
29 stop = find (html_text == ">");
30 if (length (start) == length (stop))
32 for n = length(start):-1:1
33 text (start (n):stop (n)) = [];
35 text = strip_superfluous_endlines (text);
38 warning ("help: invalid HTML data -- raw HTML source follows...");
45 ## This function removes end-lines (\n) that makes printing look bad
46 function text = strip_superfluous_endlines (text)
47 ## Find groups of end-lines
48 els = find (text == "\n");
50 groups = [els(1), 1]; # list containing [start, length] of each group
51 for k = 1:length (dels)
55 groups (end+1, 1:2) = [els(k+1), 1];
59 keep = true (size (text));
61 ## Remove end-lines in the beginning
62 if (groups (1, 1) == 1)
63 keep (1:groups (1, 2)) = false;
66 ## Remove end-lines from the end
67 if (sum (groups (end, :)) - 1 == length (text))
68 keep (groups (end, 1):end) = false;
71 ## Remove groups of end-lines with more than 3 end-lines next to each other
72 idx = find (groups (:, 2) >= 3);
73 for k = 1:length (idx)
74 start = groups (idx (k), 1);
75 stop = start + groups (idx (k), 2) - 1;
76 keep (start+2:stop) = false;
79 ## Actually remove the elements