def _make_line(self, line: str) -> str: if not str(self.indent_type).strip(" \t") and self.convert_indents: if self.indent_type == '\t': line = convert_indents(line, tab_width=1, from_=" ", to='\t') else: # pragma: no cover line = convert_indents(line, tab_width=1, from_='\t', to=self.indent_type) return f"{self.indent}{line}".rstrip()
def run(self) -> List[Node]: """ Process the content of the code block. """ code = '\n'.join(self.content) if "tab-width" in self.options: tab_width = self.options["tab-width"] else: tab_width = 4 code = convert_indents(code, tab_width=tab_width, from_=' ' * self.config.docutils_tab_width) self.content = StringList(code.split('\n')) return super().run()
def test_convert_indents(): # TODO: test 'to' assert convert_indents("hello world") == "hello world" assert convert_indents("\thello world") == " hello world" assert convert_indents("\t\thello world") == " hello world" assert convert_indents("\t hello world") == " hello world" assert convert_indents("hello world", tab_width=2) == "hello world" assert convert_indents("\thello world", tab_width=2) == " hello world" assert convert_indents("\t\thello world", tab_width=2) == " hello world" assert convert_indents("\t hello world", tab_width=2) == " hello world" assert convert_indents("hello world", from_=" ") == "hello world" assert convert_indents(" hello world", from_=" ") == " hello world" assert convert_indents(" hello world", from_=" ") == " hello world" assert convert_indents(" hello world", from_=" ") == " hello world" assert convert_indents("hello world", tab_width=2, from_=" ") == "hello world" assert convert_indents(" hello world", tab_width=2, from_=" ") == " hello world" assert convert_indents(" hello world", tab_width=2, from_=" ") == " hello world"