Skip to content

Commit

Permalink
1. remove html parser
Browse files Browse the repository at this point in the history
  • Loading branch information
WUJISHANXIA committed Oct 15, 2017
1 parent f45dcfe commit 36b79b0
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions bootcamp/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
import markdown
from taggit.managers import TaggableManager

PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3

if PY3:
from html.parser import HTMLParser
else:
from HTMLParser import HTMLParser


@python_2_unicode_compatible
class Article(models.Model):
Expand Down Expand Up @@ -79,11 +71,7 @@ def get_summary(self):
return self.content

def get_summary_as_markdown(self):
markdown_html = markdown.markdown(self.get_summary(), safe_mode='escape')
summary_parser = SummaryParser()
summary_parser.feed(markdown_html)
summary = self.insert_space_to_long_word(summary_parser.summary)
return summary
return markdown.markdown(self.get_summary(), safe_mode='escape')

def get_comments(self):
return ArticleComment.objects.filter(article=self)
Expand Down Expand Up @@ -123,18 +111,4 @@ def __str__(self):
return '{0} - {1}'.format(self.user.username, self.article.title)

def get_comment_as_markdown(self):
return markdown.markdown(self.comment, safe_mode='escape')


class SummaryParser(HTMLParser):
"""Get a summary of the HTML-format document"""

def __init__(self):
HTMLParser.__init__(self)
self.summary = ''

def handle_data(self, data):
if self.summary:
self.summary = ' '.join([self.summary, data])
else:
self.summary = data
return markdown.markdown(self.comment, safe_mode='escape')

0 comments on commit 36b79b0

Please sign in to comment.