Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
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 }))
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
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",
        )
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
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)
Ejemplo n.º 12
0
 def get_content_html(self):
     if self.content_language == self.HTML:
         return self.content
     elif self.content_language == self.MD:
         return markdown(self.content)
Ejemplo n.º 13
0
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))
Ejemplo n.º 14
0
 def get_markdown(self):
     experience_required = self.experience_required
     markdown_text = markdown(experience_required)
     return mark_safe(markdown_text)
Ejemplo n.º 15
0
 def about_markdown(self):
     about = self.about
     return mark_safe(markdown(about))
Ejemplo n.º 16
0
 def get_markdown(self):
     content = self.content
     # Converting content into markdown
     return mark_safe(markdown(content))
Ejemplo n.º 17
0
 def get_markdown_text(self):
     return mark_safe(markdown(self.text))
Ejemplo n.º 18
0
 def get_markdown(self):
     notice_board = self.notice_board
     markdown_text = markdown(notice_board)
     return mark_safe(markdown_text)
Ejemplo n.º 19
0
 def get_markdown(self):
     experience_required = self.experience_required
     markdown_text = markdown(experience_required)
     return mark_safe(markdown_text)
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
 def markdown(self):
     return mark_safe(markdown(self.content))
Ejemplo n.º 22
0
 def get_markdown(self):
     content = self.content
     return  mark_safe(markdown(content))
Ejemplo n.º 23
0
 def get_html(self):
     content = self.body
     html_text = markdown(content)
     return mark_safe(html_text)
Ejemplo n.º 24
0
 def get_draft_statement_html(question):
     if question.draft_statement:
         html = markdown_deux.markdown(question.draft_statement, 'default')
     else:
         html = ''
     return html
Ejemplo n.º 25
0
 def get_markdown(self):
     lecture_note = self.lecture_note
     markdown_text = markdown(lecture_note)
     return mark_safe(markdown_text)
Ejemplo n.º 26
0
 def statement_html(self):
     if self.statement_language == self.MD:
         return markdown(self.statement)
     else:
         return self.statement
Ejemplo n.º 27
0
Archivo: models.py Proyecto: biwoom/obn
 def get_markdown(self):
     text = self.text
     markdown_text = markdown(text)
     return mark_safe(markdown_text)
Ejemplo n.º 28
0
 def get_markdown(self):
     content = self.description
     markdown_text = markdown(content)
     return mark_safe(markdown_text)
Ejemplo n.º 29
0
 def get_markdown_summary(self):
     post_summary = self.post_summary
     markdown_text = markdown(post_summary)
     return mark_safe(markdown_text)
Ejemplo n.º 30
0
 def get_markdown(self):
     content = self.content
     md = markdown(content)
     return mark_safe(md)
Ejemplo n.º 31
0
 def get_markdown(self):
     abstract = self.abstract
     markdown_text = markdown(abstract)
     return mark_safe(markdown_text)
Ejemplo n.º 32
0
 def markdown(self):
     content = self.content
     return mark_safe(markdown(content))
Ejemplo n.º 33
0
    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)
Ejemplo n.º 34
0
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))
Ejemplo n.º 35
0
 def item_description(self, item):
     return markdown(item.text)
Ejemplo n.º 36
0
 def get_markdown(self):
     description = self.description
     markdown_text = markdown(description)
     return mark_safe(markdown_text)
Ejemplo n.º 37
0
 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)
Ejemplo n.º 39
0
 def text_as_html(self):
     return markdown(self.text)
Ejemplo n.º 40
0
 def get_mark_down(self):
     marked_content = markdown(self.content)
     return mark_safe(marked_content)
Ejemplo n.º 41
0
    def get_markdown(self):
        content = self.content

        return mark_safe(markdown_deux.markdown(content))
Ejemplo n.º 42
0
 def get_markdown(self):
     body = self.body
     return mark_safe(markdown(body))
Ejemplo n.º 43
0
 def markdown(self):
     return mark_safe(markdown(self.content))
Ejemplo n.º 44
0
 def get_markdown_bio(self):
     bio = self.bio
     return mark_safe(markdown(bio))
Ejemplo n.º 45
0
 def message_markdown(self):
     message = self.message
     return mark_safe(markdown(message))
Ejemplo n.º 46
0
 def set_text_to_markdown(self):
     self.text = markdown(self.plain_text)
Ejemplo n.º 47
0
 def item_description(self, item):
     return markdown_deux.markdown(item.text, style='post_style')
Ejemplo n.º 48
0
 def questtext_html(self):
     import markdown_deux
     return markdown_deux.markdown(self.questtext)[3:-5]
Ejemplo n.º 49
0
 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
Ejemplo n.º 50
0
 def get_markdown(self): #za markdown teksta, pretvaramo sve ovdje i iz template-a pozivamo
     text = self.text
     return mark_safe(markdown(text))
Ejemplo n.º 51
0
    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
Ejemplo n.º 52
0
 def get_markdown(self):
     return mark_safe(markdown(self.body))
Ejemplo n.º 53
0
 def get_html_description(self, obj):
     return markdown_deux.markdown(obj.description)
Ejemplo n.º 54
0
 def get_markdown(self):
     content = self.content
     return markdown(content)
Ejemplo n.º 55
0
 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)
Ejemplo n.º 57
0
 def get_html(self):
     content = self.content
     return mark_safe(markdown(content))
Ejemplo n.º 58
0
 def get_markdown(self):
     content = self.content
     markdown_text = markdown(content)
     return mark_safe(markdown_text)
Ejemplo n.º 59
0
 def get_markdown(self):
     body = self.body
     markdown_text = markdown(body)
     return mark_safe(markdown_text)