Ejemplo n.º 1
0
 def apply_markdown(self):
     self.cancel_html = self.html
     has_def_list = False
     if "<dl>" in self.html:
         has_def_list = True
         self.create_correct_md_for_def_list()
         self.html = self.note.fields[self.current_field]
     clean_md = utility.convert_html_to_markdown(self.html)
     if has_def_list:
         clean_md = utility.remove_leading_whitespace_from_dd_element(
             clean_md)
     clean_md = utility.remove_whitespace_before_abbreviation_definition(
         clean_md)
     clean_md_escaped = utility.escape_html_chars(clean_md)
     if not clean_md:
         return
     # check for changed Markdown between the stored data and the current text
     if self.has_data and self.isconverted == "True":
         compare_md = utility.convert_markdown_to_html(self.md)
         compare_md = utility.put_colons_in_html_def_list(compare_md)
         compare_md = utility.convert_html_to_markdown(compare_md)
         if has_def_list:
             compare_md = utility.remove_leading_whitespace_from_dd_element(
                 compare_md)
         compare_md = utility.remove_whitespace_before_abbreviation_definition(
             compare_md)
         if not any(x in compare_md
                    for x in ("&amp;", "&quot;", "&apos;", "&gt;", "&lt;")):
             compare_md_escaped = utility.escape_html_chars(compare_md)
             compare_md = compare_md_escaped
         if (utility.is_same_markdown(clean_md_escaped, compare_md)
                 or self.p.get(const.MARKDOWN_ALWAYS_REVERT)):
             self.revert_to_stored_markdown()
         else:
             self.handle_conflict()
     else:
         # make abbreviations behave correctly
         new_html = utility.convert_markdown_to_html(clean_md)
         # needed for proper display of images
         if "<img" in new_html:
             new_html = utility.unescape_html(new_html)
         html_with_data = utility.make_data_ready_to_insert(
             self.current_note_id_and_field, "True", clean_md_escaped,
             new_html)
         self.insert_markup_in_field(html_with_data,
                                     self.editor_instance.currentField)
         self.align_elements()
         const.MARKDOWN_PREFS["disable_buttons"] = True
         self.warn_about_changes(self.editor_instance, self.current_field,
                                 const.MARKDOWN_BG_COLOR)
Ejemplo n.º 2
0
 def apply_markdown(self):
     self.cancel_html = self.html
     has_def_list = False
     if "<dl>" in self.html:
         has_def_list = True
         self.create_correct_md_for_def_list()
         self.html = self.note.fields[self.current_field]
     clean_md = utility.convert_html_to_markdown(self.html)
     if has_def_list:
         clean_md = utility.remove_leading_whitespace_from_dd_element(clean_md)
     clean_md = utility.remove_whitespace_before_abbreviation_definition(
             clean_md)
     clean_md_escaped = utility.escape_html_chars(clean_md)
     if not clean_md:
         return
     # check for changed Markdown between the stored data and the current text
     if (self.has_data and self.isconverted == "True"):
         compare_md = utility.convert_markdown_to_html(self.md)
         compare_md = utility.put_colons_in_html_def_list(compare_md)
         compare_md = utility.convert_html_to_markdown(compare_md)
         if has_def_list:
             compare_md = utility.remove_leading_whitespace_from_dd_element(compare_md)
         compare_md = utility.remove_whitespace_before_abbreviation_definition(
                 compare_md)
         if not any(x in compare_md for x in("&amp;", "&quot;", "&apos;",
                                             "&gt;", "&lt;")):
             compare_md_escaped = utility.escape_html_chars(compare_md)
             compare_md = compare_md_escaped
         if (utility.is_same_markdown(clean_md_escaped, compare_md) or
                preferences.PREFS.get(const.MARKDOWN_ALWAYS_REVERT)):
             self.revert_to_stored_markdown()
         else:
             self.handle_conflict()
     else:
         # make abbreviations behave correctly
         new_html = utility.convert_markdown_to_html(clean_md)
         # needed for proper display of images
         if "<img" in new_html:
             new_html = utility.unescape_html(new_html)
         html_with_data = utility.make_data_ready_to_insert(
                 self.current_note_id_and_field, "True",
                 clean_md_escaped, new_html)
         self.insert_markup_in_field(
                 html_with_data, self.editor_instance.currentField)
         self.align_elements()
         const.MARKDOWN_PREFS["disable_buttons"] = True
         self.warn_about_changes(self.editor_instance,
                                 self.current_field,
                                 const.MARKDOWN_BG_COLOR)
Ejemplo n.º 3
0
 def overwrite_stored_data(self):
     """
     Create new Markdown from the current HTML.
     """
     clean_md = utility.convert_html_to_markdown(self.html,
                                                 keep_empty_lines=True)
     clean_md = utility.remove_whitespace_before_abbreviation_definition(
         clean_md)
     if "<dl" in self.html:
         clean_md = utility.remove_leading_whitespace_from_dd_element(
             clean_md, add_newline=True)
     if re.search(const.IS_LINK_OR_IMG_REGEX, clean_md):
         clean_md = utility.escape_html_chars(clean_md)
     new_html = utility.convert_clean_md_to_html(clean_md, put_breaks=True)
     self.insert_markup_in_field(new_html, self.current_field)
     const.MARKDOWN_PREFS["disable_buttons"] = False
     const.MARKDOWN_PREFS["isconverted"] = False
     self.remove_warn_msg(self.editor_instance, self.current_field)
Ejemplo n.º 4
0
 def overwrite_stored_data(self):
     """
     Create new Markdown from the current HTML.
     """
     clean_md = utility.convert_html_to_markdown(
             self.html, keep_empty_lines=True)
     clean_md = utility.remove_whitespace_before_abbreviation_definition(
             clean_md)
     if "<dl" in self.html:
         clean_md = utility.remove_leading_whitespace_from_dd_element(
                 clean_md, add_newline=True)
     if re.search(const.IS_LINK_OR_IMG_REGEX, clean_md):
         clean_md = utility.escape_html_chars(clean_md)
     new_html = utility.convert_clean_md_to_html(clean_md,
                                                 put_breaks=True)
     self.insert_markup_in_field(new_html, self.current_field)
     const.MARKDOWN_PREFS["disable_buttons"] = False
     const.MARKDOWN_PREFS["isconverted"] = False
     self.remove_warn_msg(self.editor_instance, self.current_field)