def __get_syntax_prms__(self): def tweak_prms_block(blocks: str) -> str: out = "" for b in blocks: if b.__contains__("parsed-literal::"): lines = rst2md.tr_plain(b).splitlines() lines = list(filter(None, lines)) n_ws = np.zeros(len(lines), int) for ix, l in enumerate(lines): n_ws[ix] = len(l) - len(l.lstrip()) ws_min = np.min(n_ws) for ix, l in enumerate(lines): l_str = l[:ws_min].replace( " ", ' ') + l[ws_min:] + " \n" if n_ws[ix] == ws_min: out += " * " + l_str else: out += " " + l_str else: out += b + " \n" return rst2md.tr_inline_math(rst2md.rm_markup(out)) blocks = self.__section2blocks__(self.__sections__[1]) self.syntax = rst2md.tr_plain(blocks[0]).replace("*", "") prms_block = tweak_prms_block(blocks[1:]) self.parameters = rst2md.tr_inline_doc(prms_block)
def __get_syntax_prms__(self): def tweak_prms_block(blocks: str) -> str: out = "" for b in blocks: if b.__contains__("parsed-literal::") or b.__contains__("code-block::"): lines = rst2md.tr_plain(b).splitlines() lines = list(filter(None, lines)) n_ws = np.zeros(len(lines), int) for ix, l in enumerate(lines): n_ws[ix] = len(l) - len(l.lstrip()) ws_min = np.min(n_ws) for ix, l in enumerate(lines): l_str = l[:ws_min].replace( " ", ' ') + l[ws_min:] + " \n" if n_ws[ix] == ws_min: out += " * " + l_str else: out += " " + l_str else: out += b + " \n" out = rst2md.rm_markup(out) out = rst2md.tr_inline_math(out) out = rst2md.fix_tr_markup_bugs(out) return out def get_multiple_syntaxes(syn_clean): syntaxes = [] lines = syn_clean.splitlines() cmd_word = lines[0].split(" ")[0].strip() for l in lines: if l.strip().split(" ")[0].strip() == cmd_word: syntaxes.append(l.strip()) return syntaxes blocks = self.__section2blocks__(self.__sections__[1]) syntax_clean = (rst2md.tr_plain(blocks[0]) .replace("*", "").strip()) syntax_array = get_multiple_syntaxes(syntax_clean) self.syntax = syntax_array self.n_syntax = len(syntax_array) prms_block = tweak_prms_block(blocks[1:]) self.parameters = rst2md.tr_inline_doc(prms_block)