Mercurial > hg > octave-lyh
comparison scripts/help/get_first_help_sentence.m @ 11587:c792872f8942
all script files: untabify and strip trailing whitespace
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:35:29 -0500 |
parents | fd0a3ac60b0e |
children | 91ccd08fe80c |
comparison
equal
deleted
inserted
replaced
11586:12df7854fa7c | 11587:c792872f8942 |
---|---|
44 function [retval, status] = get_first_help_sentence (name, max_len = 80) | 44 function [retval, status] = get_first_help_sentence (name, max_len = 80) |
45 ## Check input | 45 ## Check input |
46 if (nargin == 0) | 46 if (nargin == 0) |
47 error ("get_first_help_sentence: not enough input arguments"); | 47 error ("get_first_help_sentence: not enough input arguments"); |
48 endif | 48 endif |
49 | 49 |
50 if (!ischar (name)) | 50 if (!ischar (name)) |
51 error ("get_first_help_sentence: first input must be a string"); | 51 error ("get_first_help_sentence: first input must be a string"); |
52 endif | 52 endif |
53 | 53 |
54 if (!isnumeric (max_len) || max_len <= 0 || max_len != round (max_len)) | 54 if (!isnumeric (max_len) || max_len <= 0 || max_len != round (max_len)) |
55 error ("get_first_help_sentence: second input must be positive integer"); | 55 error ("get_first_help_sentence: second input must be positive integer"); |
56 endif | 56 endif |
57 | 57 |
58 ## First, we get the raw help text | 58 ## First, we get the raw help text |
59 [help_text, format] = get_help_text (name); | 59 [help_text, format] = get_help_text (name); |
60 | 60 |
61 ## Then, we take action depending on the format | 61 ## Then, we take action depending on the format |
62 switch (lower (format)) | 62 switch (lower (format)) |
63 case "plain text" | 63 case "plain text" |
64 [retval, status] = first_sentence_plain_text (help_text, max_len); | 64 [retval, status] = first_sentence_plain_text (help_text, max_len); |
65 case "texinfo" | 65 case "texinfo" |
93 ## render the text to plain text using makeinfo, and then extract the first line. | 93 ## render the text to plain text using makeinfo, and then extract the first line. |
94 function [retval, status] = first_sentence_texinfo (help_text, max_len) | 94 function [retval, status] = first_sentence_texinfo (help_text, max_len) |
95 ## Lines ending with "@\n" are continuation lines, so they should be concatenated | 95 ## Lines ending with "@\n" are continuation lines, so they should be concatenated |
96 ## with the following line. | 96 ## with the following line. |
97 help_text = strrep (help_text, "@\n", " "); | 97 help_text = strrep (help_text, "@\n", " "); |
98 | 98 |
99 ## Find, and remove, lines that start with @def. This should remove things | 99 ## Find, and remove, lines that start with @def. This should remove things |
100 ## such as @deftypefn, @deftypefnx, @defvar, etc. | 100 ## such as @deftypefn, @deftypefnx, @defvar, etc. |
101 keep = true (size (help_text)); | 101 keep = true (size (help_text)); |
102 def_idx = strfind (help_text, "@def"); | 102 def_idx = strfind (help_text, "@def"); |
103 if (!isempty (def_idx)) | 103 if (!isempty (def_idx)) |
108 keep (def_idx (k):end) = false; | 108 keep (def_idx (k):end) = false; |
109 else | 109 else |
110 keep (def_idx (k):endl) = false; | 110 keep (def_idx (k):endl) = false; |
111 endif | 111 endif |
112 endfor | 112 endfor |
113 | 113 |
114 ## Remove the @end ... that corresponds to the @def we removed above | 114 ## Remove the @end ... that corresponds to the @def we removed above |
115 def1 = def_idx (1); | 115 def1 = def_idx (1); |
116 space_idx = find (help_text == " "); | 116 space_idx = find (help_text == " "); |
117 space_idx = space_idx (find (space_idx > def1, 1)); | 117 space_idx = space_idx (find (space_idx > def1, 1)); |
118 bracket_idx = find (help_text == "{" | help_text == "}"); | 118 bracket_idx = find (help_text == "{" | help_text == "}"); |
131 if (isempty (endl)) | 131 if (isempty (endl)) |
132 keep (end_idx:end) = false; | 132 keep (end_idx:end) = false; |
133 else | 133 else |
134 keep (end_idx:endl) = false; | 134 keep (end_idx:endl) = false; |
135 endif | 135 endif |
136 | 136 |
137 help_text = help_text (keep); | 137 help_text = help_text (keep); |
138 endif | 138 endif |
139 | 139 |
140 ## Run makeinfo to generate plain text | 140 ## Run makeinfo to generate plain text |
141 [help_text, status] = __makeinfo__ (help_text, "plain text"); | 141 [help_text, status] = __makeinfo__ (help_text, "plain text"); |
142 | 142 |
143 ## Extract first line with plain text method. | 143 ## Extract first line with plain text method. |
144 retval = first_sentence_plain_text (help_text, max_len); | 144 retval = first_sentence_plain_text (help_text, max_len); |
145 endfunction | 145 endfunction |
146 | 146 |
147 ## This function extracts the first sentence from a html help text. | 147 ## This function extracts the first sentence from a html help text. |
148 ## The function simply removes the tags and treats the text as plain text. | 148 ## The function simply removes the tags and treats the text as plain text. |
149 function [retval, status] = first_sentence_html (help_text, max_len) | 149 function [retval, status] = first_sentence_html (help_text, max_len) |
150 ## Strip tags | 150 ## Strip tags |
151 [help_text, status] = strip_html_tags (help_text); | 151 [help_text, status] = strip_html_tags (help_text); |
152 | 152 |
153 ## Extract first line with plain text method. | 153 ## Extract first line with plain text method. |
154 retval = first_sentence_plain_text (help_text, max_len); | 154 retval = first_sentence_plain_text (help_text, max_len); |
155 endfunction | 155 endfunction |
156 | 156 |