def get_markdown(self): description = self.description # TODO: escapar os caracteres especiais dentro das tags do TeX # tex_parser = re.compile(r'\$(.*?)\$') # description = tex_parser.finditer(description) markdown_text = markdown(description) return mark_safe(markdown_text)
def get_appliances(request): logger.info('Get appliances json endpoint requested.') keywords = request.GET.getlist('keywords') search = request.GET.get('search') logger.debug('URL query params: search=%s, keywords=%s', search, keywords) if keywords: appliances = Appliance.objects.filter(keywords__in=keywords) if appliances and search: appliances = appliances.filter( Q(name__icontains=search) | Q(description__icontains=search) | Q(author_name__icontains=search)) elif search: appliances = Appliance.objects.filter( Q(name__icontains=search) | Q(description__icontains=search) | Q(author_name__icontains=search)) else: appliances = Appliance.objects.all() # filter out any that need review unless they belong to me if request.user.is_authenticated(): appliances = appliances.filter(Q(needs_review = False) | Q(created_by = request.user)) else: appliances = appliances.exclude(needs_review = True) for appliance in appliances: appliance.description = markdown_deux.markdown(appliance.description) logger.debug('Total matching appliances found: %d.', appliances.count()) serializer = ApplianceJSONSerializer() response = { 'status': 'success', 'message': '', 'result': json.loads(serializer.serialize(appliances)) } return JsonResponse(response)
def render(self, context): value = self.nodelist.render(context) try: return mark_safe(markdown_deux.markdown(value, self.style)) except ImportError: if settings.DEBUG: raise template.TemplateSyntaxError("Error in `markdown` tag: " "The python-markdown2 library isn't installed.") return force_text(value)
def get_stylized_min(self): if self.stylized_min is None: if self.lexer == 'markdown': self.stylized_min = markdown(self.code[:1000], 'default') else: self.stylized_min = highlight(self.code[:1000], get_lexer_by_name(self.lexer, encoding='UTF-8'), HtmlFormatter(linenos='table', linenospecial=1, lineanchors='line')) return self.stylized_min
def send_email(self): from_email = settings.DEFAULT_FROM_EMAIL subject = "[HAWC] {0}" .format(self.cleaned_data['subject']) message = "" recipient_list = self.assessment.get_project_manager_emails() html_message = markdown(self.cleaned_data['message']) send_mail(subject, message, from_email, recipient_list, html_message=html_message, fail_silently=False)
def NewMessage(request, channel_slug): channel = get_object_or_404(Channel, slug=channel_slug) if request.method == "POST" : if channel.is_default or request.user in channel.subscribers.all() : content = markdown(request.POST.get('message')) new_message = Message(author=request.user, channel=channel, content=content) new_message.save() else : messages.error(request, "Une erreur s'est produite. Vous n'avez peut-être pas les droits pour envoyer ce message.") return HttpResponseRedirect(reverse('chatroom', kwargs={ 'channel_slug': channel_slug }))
def process_related(self, request, user_profile, input_data, template_args, **kwargs): """ Displays and manages the item related_url behavior Her is the switch for external services integration """ # check if related-url is set # and switch depending on the service it represents # it's much more like an embed # # check for url node = kwargs['node'] if node.related_url: if node.related_url.startswith('https://twitter.com') and input_data.get('keyword'): wk = TwitterWorker(user_profile, kwargs['node'], input_data, kwargs) items = wk.prepare() template_args['nodes'] = items #return self.render(request, template_args, **kwargs) elif node.related_url.startswith('http://www.meetup.com'): # and #input_data.get('keyword'): wk = MeetupWorker(user_profile, kwargs['node'], input_data, kwargs) items = wk.prepare() template_args['nodes'] = items #return self.render(request, template_args, **kwargs) elif node.related_url.startswith('https://googlecalendar.com'): pass elif node.related_url.startswith('https://hackpad.com/'): hackpad_id = node.related_url.split('-')[-1] print 'importing hackpad' # import hackpad content HACKPAD_CLIENT_ID = 'vTuK1ArKv5m' HACKPAD_CLIENT_SECRET = '5FuDkwdgc8Mo0y2OuhMijuzFfQy3ni5T' hackpad = Hackpad(consumer_key=HACKPAD_CLIENT_ID, consumer_secret=HACKPAD_CLIENT_SECRET) #node.description = '' #node.description = hackpad.get_pad_content(hackpad_id, asUser='', response_format='md') hackpad_content = hackpad.get_pad_content(hackpad_id, asUser='', response_format='md') #node.description = unicode(decode(hackpad_content, 'latin1')) try: node.get_translation().content = markdown_deux.markdown( unicode(decode(hackpad_content, 'latin1')) ) node.save() except: pass #print node.content return self.manage_item_pipe(request, user_profile, input_data, template_args, **kwargs)
def markdown_comment(request): # Exclusively for ajax posts. Return a user's comment in markdown converted # to safe html for posting. if request.is_ajax(): return HttpResponse( json.dumps( {"comment": markdown_deux.markdown(request.POST.get("comment", ""), style="comment_style")}, ensure_ascii=False, ), mimetype="application/javascript", )
def get_stylized_min(self): if self.stylized_min is None: if self.lexer == "markdown": self.stylized_min = markdown(self.code[:1000], "default") else: self.stylized_min = highlight( self.code[:1000], get_lexer_by_name(self.lexer, encoding="UTF-8"), HtmlFormatter(linenos="table", linenospecial=1, lineanchors="line"), ) return self.stylized_min
def summary_text(text, length=40): html_text = markdown_deux.markdown(text, "trusted") stripped_text = strip_tags(html_text).strip() word_separator = re.compile('[ ]') words = word_separator.split(stripped_text) if len(words) > length: shortened_text = "%s ..." % (' '.join(words[0:length])) else: shortened_text = ' '.join(words) return shortened_text
def markdown_filter(value, style="default"): """Processes the given value as Markdown, optionally using a particular Markdown style/config Syntax:: {{ value|markdown }} {# uses the "default" style #} {{ value|markdown:"mystyle" }} Markdown "styles" are defined by the `MARKDOWN_DEUX_STYLES` setting. """ try: return mark_safe(markdown_deux.markdown(value, style)) except ImportError: if settings.DEBUG: raise template.TemplateSyntaxError("Error in `markdown` filter: " "The python-markdown2 library isn't installed.") return force_text(value)
def get_content_html(self): if self.content_language == self.HTML: return self.content elif self.content_language == self.MD: return markdown(self.content)
def multipart_markdown(md_text, template_text=True): if template_text: md_text = Template(md_text).render(TemplateTextContext()) return to_multipart(md_text, markdown(md_text))
def get_markdown(self): experience_required = self.experience_required markdown_text = markdown(experience_required) return mark_safe(markdown_text)
def about_markdown(self): about = self.about return mark_safe(markdown(about))
def get_markdown(self): content = self.content # Converting content into markdown return mark_safe(markdown(content))
def get_markdown_text(self): return mark_safe(markdown(self.text))
def get_markdown(self): notice_board = self.notice_board markdown_text = markdown(notice_board) return mark_safe(markdown_text)
def render_template_markdown(content, markdown_settings=None, context=Context()): tt=Template(content) template_content = tt.render(context) html_content = markdown_deux.markdown(template_content, markdown_settings) return mark_safe(html_content)
def markdown(self): return mark_safe(markdown(self.content))
def get_markdown(self): content = self.content return mark_safe(markdown(content))
def get_html(self): content = self.body html_text = markdown(content) return mark_safe(html_text)
def get_draft_statement_html(question): if question.draft_statement: html = markdown_deux.markdown(question.draft_statement, 'default') else: html = '' return html
def get_markdown(self): lecture_note = self.lecture_note markdown_text = markdown(lecture_note) return mark_safe(markdown_text)
def statement_html(self): if self.statement_language == self.MD: return markdown(self.statement) else: return self.statement
def get_markdown(self): text = self.text markdown_text = markdown(text) return mark_safe(markdown_text)
def get_markdown(self): content = self.description markdown_text = markdown(content) return mark_safe(markdown_text)
def get_markdown_summary(self): post_summary = self.post_summary markdown_text = markdown(post_summary) return mark_safe(markdown_text)
def get_markdown(self): content = self.content md = markdown(content) return mark_safe(md)
def get_markdown(self): abstract = self.abstract markdown_text = markdown(abstract) return mark_safe(markdown_text)
def markdown(self): content = self.content return mark_safe(markdown(content))
def save(self, *args, **kwargs): if not self.slug: self.slug = slugify_uniquely(self.title, Snipt) if not self.key: self.key = md5.new(self.slug + str(datetime.datetime.now()) + str(random.random())).hexdigest() if self.lexer == 'markdown': self.stylized = markdown(self.code, 'default') # Snipt embeds for match in re.findall('\[\[(\w{32})\]\]', self.stylized): self.stylized = self.stylized.replace('[[' + str(match) + ']]', '<script type="text/javascript" src="https://snipt.net/embed/{}/?snipt"></script><div id="snipt-embed-{}"></div>'.format(match, match)) # YouTube embeds for match in re.findall('\[\[youtube-(\w{11})\-(\d+)x(\d+)\]\]', self.stylized): self.stylized = self.stylized.replace('[[youtube-{}-{}x{}]]'.format(str(match[0]), str(match[1]), str(match[2])), '<iframe width="{}" height="{}" src="https://www.youtube.com/embed/{}" frameborder="0" allowfullscreen></iframe>'.format(match[1], match[2], match[0])) # Vimeo embeds for match in re.findall('\[\[vimeo-(\d+)\-(\d+)x(\d+)\]\]', self.stylized): self.stylized = self.stylized.replace('[[vimeo-{}-{}x{}]]'.format(str(match[0]), str(match[1]), str(match[2])), '<iframe src="https://player.vimeo.com/video/{}" width="{}" height="{}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'.format(match[0], match[1], match[2])) else: self.stylized = highlight(self.code, get_lexer_by_name(self.lexer, encoding='UTF-8'), HtmlFormatter(linenos='table', linenospecial=1, lineanchors='line')) self.line_count = len(self.code.split('\n')) if self.lexer == 'markdown': lexer_for_embedded = 'text' else: lexer_for_embedded = self.lexer embedded = highlight(self.code, get_lexer_by_name(lexer_for_embedded, encoding='UTF-8'), HtmlFormatter( style='native', noclasses=True, prestyles=""" background-color: #1C1C1C; border-radius: 5px; color: #D0D0D0; display: block; font: 11px Monaco, monospace; margin: 0; overflow: auto; padding: 15px; -webkit-border-radius: 5px; -moz-border-radius: 5px; """)) embedded = (embedded.replace("\\\"","\\\\\"") .replace('\'','\\\'') .replace("\\", "\\\\") .replace('background: #202020', '')) self.embedded = embedded return super(Snipt, self).save(*args, **kwargs)
def pre_save_post_receiver(sender, instance, *args, **kwargs): instance.slug = create_slug(instance) if instance.content: instance.read_time = get_read_time(markdown(instance.content))
def item_description(self, item): return markdown(item.text)
def get_markdown(self): description = self.description markdown_text = markdown(description) return mark_safe(markdown_text)
def getContent(self): return markdown(self.content)
def get_markdown(self): content = self.content markdown_text = markdown(content) #print("html string markdown text in post models: ", markdown_text) return mark_safe(markdown_text)
def text_as_html(self): return markdown(self.text)
def get_mark_down(self): marked_content = markdown(self.content) return mark_safe(marked_content)
def get_markdown(self): content = self.content return mark_safe(markdown_deux.markdown(content))
def get_markdown(self): body = self.body return mark_safe(markdown(body))
def get_markdown_bio(self): bio = self.bio return mark_safe(markdown(bio))
def message_markdown(self): message = self.message return mark_safe(markdown(message))
def set_text_to_markdown(self): self.text = markdown(self.plain_text)
def item_description(self, item): return markdown_deux.markdown(item.text, style='post_style')
def questtext_html(self): import markdown_deux return markdown_deux.markdown(self.questtext)[3:-5]
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) md = get_template(self.template_name).template.source md_with_toc = markdown_deux.markdown(md, "default") context["toc"] = md_with_toc.toc_html return context
def get_markdown(self): #za markdown teksta, pretvaramo sve ovdje i iz template-a pozivamo text = self.text return mark_safe(markdown(text))
def save(self, *args, **kwargs): if not self.slug: self.slug = slugify_uniquely(self.title, Snipt) if not self.key: self.key = hashlib.md5((self.slug + str(datetime.datetime.now()) + str(random.random())).encode('utf-8')).hexdigest() if self.lexer == 'markdown': self.stylized = markdown(self.code, 'default') # Snipt embeds for match in re.findall('\[\[(\w{32})\]\]', self.stylized): self.stylized = self.stylized.replace('[[' + str(match) + ']]', """ <script type="text/javascript" src="https://snipt.net/embed/{}/?snipt"> </script> <div id="snipt-embed-{}"></div>""".format(match, match)) # YouTube embeds for match in re.findall('\[\[youtube-(\w{11})\-(\d+)x(\d+)\]\]', self.stylized): self.stylized = self.stylized \ .replace('[[youtube-{}-{}x{}]]'.format( str(match[0]), str(match[1]), str(match[2])), """<iframe width="{}" height="{}" src="https://www.youtube.com/embed/{}" frameborder="0" allowfullscreen></iframe>""" .format(match[1], match[2], match[0])) # Vimeo embeds for match in re.findall('\[\[vimeo-(\d+)\-(\d+)x(\d+)\]\]', self.stylized): self.stylized = self.stylized \ .replace('[[vimeo-{}-{}x{}]]'.format( str(match[0]), str(match[1]), str(match[2])), """<iframe src="https://player.vimeo.com/video/{}" width="{}" height="{}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>""" .format(match[0], match[1], match[2])) # Tweet embeds for match in re.findall('\[\[tweet-(\d+)\]\]', self.stylized): self.stylized = self.stylized \ .replace( '[[tweet-{}]]'.format(str(match)), '<div class="embedded-tweet" data-tweet-id="{}"></div>' .format(str(match))) # Parse Snipt usernames for match in re.findall('@(\w+) ', self.stylized): # Try and get the Snipt user by username. user = get_object_or_None(User, username=match) if user: url = user.profile.get_user_profile_url() self.stylized = self.stylized \ .replace('@{} '.format(str(match)), '<a href="{}">@{}</a> '.format(url, match)) else: self.stylized = highlight(self.code, get_lexer_by_name(self.lexer, encoding='UTF-8'), HtmlFormatter(linenos='table', anchorlinenos=True, lineanchors='L', linespans='L', )) self.line_count = len(self.code.split('\n')) if self.lexer == 'markdown': lexer_for_embedded = 'text' else: lexer_for_embedded = self.lexer embedded = highlight(self.code, get_lexer_by_name(lexer_for_embedded, encoding='UTF-8'), HtmlFormatter( style='native', noclasses=True, prestyles=""" background-color: #1C1C1C; border-radius: 5px; color: #D0D0D0; display: block; font: 11px Monaco, monospace; margin: 0; overflow: auto; padding: 15px; -webkit-border-radius: 5px; -moz-border-radius: 5px; """)) embedded = (embedded.replace("\\\"", "\\\\\"") .replace('\'', '\\\'') .replace("\\", "\\\\") .replace('background: #202020', '')) self.embedded = embedded snipt = super(Snipt, self).save(*args, **kwargs) diff = self._unidiff_output(self.original_code or '', self.code) if (diff != ''): log_entry = SniptLogEntry(user=self.last_user_saved, snipt=self, code=self.code, diff=diff) log_entry.save() return snipt
def get_markdown(self): return mark_safe(markdown(self.body))
def get_html_description(self, obj): return markdown_deux.markdown(obj.description)
def get_markdown(self): content = self.content return markdown(content)
def get_html_message(self, obj): return markdown_deux.markdown(obj.localized_message_activity)
def get_markdown(self): content = self.content markdown_text = markdown(content) return mark_safe(markdown_text)
def get_html(self): content = self.content return mark_safe(markdown(content))
def get_markdown(self): body = self.body markdown_text = markdown(body) return mark_safe(markdown_text)