def format_with_beautifier(self, text): stdout, stderr = '', '' try: stdout = htmlbeautifier.beautify(text, self.options) except Exception as e: stderr = str(e) if (not stderr and not stdout): stderr = 'Formatting error!' return stdout, stderr
def format(self, text): text = text.decode("utf-8") opts = self.formatter.settings.get('codeformatter_html_options') stderr = "" stdout = "" options = htmlbeautifier.default_options() if ("indent_size" in opts and opts["indent_size"]): options.indent_size = opts["indent_size"] else: options.indent_size = 4 if ("indent_char" in opts and opts["indent_char"]): options.indent_char = str(opts["indent_char"]) else: options.indent_char = " " if ("indent_with_tabs" in opts and opts["indent_with_tabs"]): options.indent_with_tabs = True else: options.indent_with_tabs = False if ("preserve_newlines" in opts and opts["preserve_newlines"]): options.preserve_newlines = True else: options.preserve_newlines = False if ("max_preserve_newlines" in opts and opts["max_preserve_newlines"]): options.max_preserve_newlines = opts["max_preserve_newlines"] else: options.max_preserve_newlines = 10 if ("indent_tags" in opts and opts["indent_tags"]): options.indent_tags = str(opts["indent_tags"]) try: stdout = htmlbeautifier.beautify(text, options) except Exception as e: stderr = str(e) if (not stderr and not stdout): stderr = "Formatting error!" return stdout, stderr
def format(self, text): text = text.decode("utf-8") stderr = "" stdout = "" options = htmlbeautifier.default_options() if "indent_size" in self.opts: options.indent_size = self.opts["indent_size"] if "indent_char" in self.opts: options.indent_char = str(self.opts["indent_char"]) if "minimum_attribute_count" in self.opts: options.minimum_attribute_count = self.opts["minimum_attribute_count"] if "first_attribute_on_new_line" in self.opts: options.first_attribute_on_new_line = self.opts["first_attribute_on_new_line"] if "indent_with_tabs" in self.opts: options.indent_with_tabs = self.opts["indent_with_tabs"] if "expand_tags" in self.opts: options.expand_tags = self.opts["expand_tags"] if "expand_javascript" in self.opts: options.expand_javascript = self.opts["expand_javascript"] if "reduce_empty_tags" in self.opts: options.reduce_empty_tags = self.opts["reduce_empty_tags"] if "exception_on_tag_mismatch" in self.opts: options.exception_on_tag_mismatch = self.opts["exception_on_tag_mismatch"] if "custom_singletons" in self.opts: options.custom_singletons = self.opts["custom_singletons"] try: stdout = htmlbeautifier.beautify(text, options) except Exception as e: stderr = str(e) if (not stderr and not stdout): stderr = "Formatting error!" return stdout, stderr
def format(self, text): text = text.decode("utf-8") stderr = "" stdout = "" options = htmlbeautifier.default_options() if "indent_size" in self.opts: options.indent_size = self.opts["indent_size"] if "indent_char" in self.opts: options.indent_char = str(self.opts["indent_char"]) if "minimum_attribute_count" in self.opts: options.minimum_attribute_count = self.opts[ "minimum_attribute_count"] if "indent_with_tabs" in self.opts: options.indent_with_tabs = self.opts["indent_with_tabs"] if "expand_tags" in self.opts: options.expand_tags = self.opts["expand_tags"] if "expand_javascript" in self.opts: options.expand_javascript = self.opts["expand_javascript"] if "reduce_empty_tags" in self.opts: options.reduce_empty_tags = self.opts["reduce_empty_tags"] if "exception_on_tag_mismatch" in self.opts: options.exception_on_tag_mismatch = self.opts[ "exception_on_tag_mismatch"] try: stdout = htmlbeautifier.beautify(text, options) except Exception as e: stderr = str(e) if (not stderr and not stdout): stderr = "Formatting error!" return stdout, stderr
def format(self, text): text = text.decode("utf-8") opts = self.formatter.settings.get("codeformatter_html_options") stderr = "" stdout = "" options = htmlbeautifier.default_options() if "indent_size" in opts: options.indent_size = opts["indent_size"] if "indent_char" in opts: options.indent_char = str(opts["indent_char"]) if "minimum_attribute_count" in opts: options.minimum_attribute_count = opts["minimum_attribute_count"] if "indent_with_tabs" in opts: options.indent_with_tabs = opts["indent_with_tabs"] if "expand_tags" in opts: options.expand_tags = opts["expand_tags"] if "expand_javascript" in opts: options.expand_javascript = opts["expand_javascript"] if "reduce_empty_tags" in opts: options.reduce_empty_tags = opts["reduce_empty_tags"] if "exception_on_tag_mismatch" in opts: options.exception_on_tag_mismatch = opts["exception_on_tag_mismatch"] try: stdout = htmlbeautifier.beautify(text, options) except Exception as e: stderr = str(e) if not stderr and not stdout: stderr = "Formatting error!" return stdout, stderr
def format(self, text): text = text.decode("utf-8") stderr = "" stdout = "" formatter = "" if "formatter_version" in self.opts: formatter = self.opts["formatter_version"] if use_bs4 == False and self.opts["formatter_version"] == "bs4": formatter = "regexp" sublime.error_message(u'CodeFormatter\n\nUnable to load BeautifulSoup HTML formatter. The old RegExp-based formatter was automatically used for you instead.') if formatter == "bs4" and use_bs4: p_indent_size = 4 if "indent_size" in self.opts: p_indent_size = self.opts["indent_size"] try: soup = BeautifulSoup(text, 'html.parser') stdout = soup.prettify(formatter=None,indent_size=p_indent_size) except Exception as e: stderr = str(e) else: options = htmlbeautifier.default_options() if "indent_size" in self.opts: options.indent_size = self.opts["indent_size"] if "indent_char" in self.opts: options.indent_char = str(self.opts["indent_char"]) if "minimum_attribute_count" in self.opts: options.minimum_attribute_count = self.opts["minimum_attribute_count"] if "first_attribute_on_new_line" in self.opts: options.first_attribute_on_new_line = self.opts["first_attribute_on_new_line"] if "indent_with_tabs" in self.opts: options.indent_with_tabs = self.opts["indent_with_tabs"] if "expand_tags" in self.opts: options.expand_tags = self.opts["expand_tags"] if "reduce_empty_tags" in self.opts: options.reduce_empty_tags = self.opts["reduce_empty_tags"] if "exception_on_tag_mismatch" in self.opts: options.exception_on_tag_mismatch = self.opts["exception_on_tag_mismatch"] if "custom_singletons" in self.opts: options.custom_singletons = self.opts["custom_singletons"] try: stdout = htmlbeautifier.beautify(text, options) except Exception as e: stderr = str(e) if (not stderr and not stdout): stderr = "Formatting error!" return stdout, stderr
def format(self, text): text = text.decode('utf-8') stderr = '' stdout = '' formatter = '' if 'formatter_version' in self.opts: formatter = self.opts['formatter_version'] if use_bs4 is False and self.opts['formatter_version'] == 'bs4': formatter = 'regexp' sublime.error_message( u'CodeFormatter\n\nUnable to load BeautifulSoup HTML ' u'formatter. The old RegExp-based formatter was ' u'automatically used for you instead.') if formatter == 'bs4' and use_bs4: p_indent_size = 4 if 'indent_size' in self.opts: p_indent_size = self.opts['indent_size'] try: soup = BeautifulSoup(text, 'html.parser') stdout = soup.prettify(formatter=None, indent_size=p_indent_size) except Exception as e: stderr = str(e) else: options = htmlbeautifier.default_options() if 'indent_size' in self.opts: options.indent_size = self.opts['indent_size'] if 'indent_char' in self.opts: options.indent_char = str(self.opts['indent_char']) if 'minimum_attribute_count' in self.opts: options.minimum_attribute_count = ( self.opts['minimum_attribute_count']) if 'first_attribute_on_new_line' in self.opts: options.first_attribute_on_new_line = ( self.opts['first_attribute_on_new_line']) if 'indent_with_tabs' in self.opts: options.indent_with_tabs = self.opts['indent_with_tabs'] if 'expand_tags' in self.opts: options.expand_tags = self.opts['expand_tags'] if 'reduce_empty_tags' in self.opts: options.reduce_empty_tags = self.opts['reduce_empty_tags'] if 'reduce_whole_word_tags' in self.opts: options.reduce_whole_word_tags = ( self.opts['reduce_whole_word_tags']) if 'exception_on_tag_mismatch' in self.opts: options.exception_on_tag_mismatch = ( self.opts['exception_on_tag_mismatch']) if 'custom_singletons' in self.opts: options.custom_singletons = self.opts['custom_singletons'] try: stdout = htmlbeautifier.beautify(text, options) except Exception as e: stderr = str(e) if (not stderr and not stdout): stderr = 'Formatting error!' return stdout, stderr
def format(self, text): text = text.decode('utf-8') stderr = '' stdout = '' formatter = '' if 'formatter_version' in self.opts: formatter = self.opts['formatter_version'] if use_bs4 is False and self.opts['formatter_version'] == 'bs4': formatter = 'regexp' sublime.error_message( u'CodeFormatter\n\nUnable to load BeautifulSoup HTML ' u'formatter. The old RegExp-based formatter was ' u'automatically used for you instead.' ) if formatter == 'bs4' and use_bs4: p_indent_size = 4 if 'indent_size' in self.opts: p_indent_size = self.opts['indent_size'] try: soup = BeautifulSoup(text, 'html.parser') stdout = soup.prettify( formatter=None, indent_size=p_indent_size) except Exception as e: stderr = str(e) else: options = htmlbeautifier.default_options() if 'indent_size' in self.opts: options.indent_size = self.opts['indent_size'] if 'indent_char' in self.opts: options.indent_char = str(self.opts['indent_char']) if 'minimum_attribute_count' in self.opts: options.minimum_attribute_count = ( self.opts['minimum_attribute_count'] ) if 'first_attribute_on_new_line' in self.opts: options.first_attribute_on_new_line = ( self.opts['first_attribute_on_new_line'] ) if 'indent_with_tabs' in self.opts: options.indent_with_tabs = self.opts['indent_with_tabs'] if 'expand_tags' in self.opts: options.expand_tags = self.opts['expand_tags'] if 'reduce_empty_tags' in self.opts: options.reduce_empty_tags = self.opts['reduce_empty_tags'] if 'reduce_whole_word_tags' in self.opts: options.reduce_whole_word_tags = ( self.opts['reduce_whole_word_tags'] ) if 'exception_on_tag_mismatch' in self.opts: options.exception_on_tag_mismatch = ( self.opts['exception_on_tag_mismatch'] ) if 'custom_singletons' in self.opts: options.custom_singletons = self.opts['custom_singletons'] try: stdout = htmlbeautifier.beautify(text, options) except Exception as e: stderr = str(e) if (not stderr and not stdout): stderr = 'Formatting error!' return stdout, stderr
def format(self, text): text = text.decode("utf-8") stderr = "" stdout = "" formatter = "" if "formatter_version" in self.opts: formatter = self.opts["formatter_version"] if use_bs4 == False and self.opts["formatter_version"] == "bs4": formatter = "regexp" sublime.error_message( u'CodeFormatter\n\nUnable to load BeautifulSoup HTML formatter. The old RegExp-based formatter was automatically used for you instead.' ) if formatter == "bs4" and use_bs4: p_indent_size = 4 if "indent_size" in self.opts: p_indent_size = self.opts["indent_size"] try: soup = BeautifulSoup(text, 'html.parser') stdout = soup.prettify(formatter=None, indent_size=p_indent_size) except Exception as e: stderr = str(e) else: options = htmlbeautifier.default_options() if "indent_size" in self.opts: options.indent_size = self.opts["indent_size"] if "indent_char" in self.opts: options.indent_char = str(self.opts["indent_char"]) if "minimum_attribute_count" in self.opts: options.minimum_attribute_count = self.opts[ "minimum_attribute_count"] if "first_attribute_on_new_line" in self.opts: options.first_attribute_on_new_line = self.opts[ "first_attribute_on_new_line"] if "indent_with_tabs" in self.opts: options.indent_with_tabs = self.opts["indent_with_tabs"] if "expand_tags" in self.opts: options.expand_tags = self.opts["expand_tags"] if "reduce_empty_tags" in self.opts: options.reduce_empty_tags = self.opts["reduce_empty_tags"] if "reduce_whole_word_tags" in self.opts: options.reduce_whole_word_tags = self.opts[ "reduce_whole_word_tags"] if "exception_on_tag_mismatch" in self.opts: options.exception_on_tag_mismatch = self.opts[ "exception_on_tag_mismatch"] if "custom_singletons" in self.opts: options.custom_singletons = self.opts["custom_singletons"] try: stdout = htmlbeautifier.beautify(text, options) except Exception as e: stderr = str(e) if (not stderr and not stdout): stderr = "Formatting error!" return stdout, stderr