From d1c5bf1e4ab2a91c30d2bcbd1e08a1a02c73ad41 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 23 Mar 2015 15:14:07 +0100 Subject: [PATCH] fix(docs): remove newlines interpreted as test When documenting mandatory arguments of a methods builder, it was possible to document 'parts', which have a long multi-line description with empty lines inbetween. This caused the indentation to be funny and tricked rustdoc into thinking these are indented doc-tests. Now we remove these empty lines, also hoping we dont encounter lines with just whitespace in them. The latter would require a tiny update of our regex. --- src/mako/lib/rbuild.mako | 4 ++-- src/mako/lib/util.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mako/lib/rbuild.mako b/src/mako/lib/rbuild.mako index f9e0cf39a4b..add61f97161 100644 --- a/src/mako/lib/rbuild.mako +++ b/src/mako/lib/rbuild.mako @@ -6,7 +6,7 @@ rust_copy_value_s, is_required_property, organize_params, REQUEST_VALUE_PROPERTY_NAME, build_all_params, rb_type_params_s, hub_type_params_s, mb_type_params_s, mb_additional_type_params, struct_type_bounds_s, METHODS_RESOURCE, SPACES_PER_TAB, prefix_all_but_first_with, - METHODS_BUILDER_MARKER_TRAIT) + METHODS_BUILDER_MARKER_TRAIT, remove_empty_lines) %>\ <%namespace name="util" file="util.mako"/>\ <%namespace name="lib" file="lib.mako"/>\ @@ -91,7 +91,7 @@ impl${rb_params} ${ThisType} { arg_prefix = "/// * `" + p.name + "` - " %>\ ${arg_prefix}${p.get('description', "No description provided.") - | prefix_all_but_first_with(' ' * SPACES_PER_TAB + '///' + ' ' * (len(arg_prefix) - len('///')))} + | remove_empty_lines, prefix_all_but_first_with(' ' * SPACES_PER_TAB + '///' + ' ' * (len(arg_prefix) - len('///')))} % endfor % endif pub fn ${mangle_ident(a)}${type_params}(&self${method_args}) -> ${RType}${mb_tparams} { diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 3b95ce8e52f..f26068a8878 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -150,6 +150,10 @@ def unindent_inner(s): return re_linestart.sub(' ' * tabs * SPACES_PER_TAB, s) return unindent_inner +# filter to remove empty lines from a string +def remove_empty_lines(s): + return re.sub("^\n", '', s, flags=re.MULTILINE) + # Prepend prefix to each line but the first def prefix_all_but_first_with(prefix): def indent_inner(s):