Commit 6277c5b8 authored by Robert's avatar Robert

Convert html to markdown on import

parent ce2b424d
......@@ -75,12 +75,13 @@ def nolinebreaks(value):
@register.filter
def html2text(html, preset='mail'):
text_maker = python_html2text.HTML2Text()
text_maker.body_width = 0
if preset == 'mail':
text_maker.inline_links = False
text_maker.links_each_paragraph = True
text_maker.use_automatic_links = True
elif preset == 'import':
pass
text_maker.escape_snob = True
return text_maker.handle(html).rstrip()
......
......@@ -8,6 +8,7 @@ import feedparser
import requests
import core
from core.templatetags.core import html2text
from features.associations import models as associations
from features.content import models as content
from features.content.signals import post_create
......@@ -47,7 +48,7 @@ class Command(django.core.management.base.BaseCommand):
key = entry.get('id', entry.get('link'))
if key and not models.Imported.objects.filter(key=key).exists():
title = entry.get('title')
text = entry.get('summary')
text = html2text(entry.get('summary'), preset='import')
if title and text:
c = content.Content.objects.create(title=title)
link = entry.get('link')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment