FSX / misaka

A Python binding for Hoedown.
http://misaka.61924.nl
MIT License
420 stars 65 forks source link

Table can't work in Django project #62

Closed ghost closed 7 years ago

ghost commented 7 years ago

I can‘t use the markdown syntax to insert a table, I input this:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |

then I get this: mdtable

It should be like this:

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

How can I get the normal table?

FSX commented 7 years ago

Can you be more specific? Do you get the right HTML output?

ghost commented 7 years ago

Yeah, I got the right HTML output, but in my page can't show the table, just like above, the table have no border, here is my Django model code:

class Article(models.Model):
    title = models.CharField('Title', max_length=300)
    content = models.TextField()
    content_html = models.TextField(null=True)
    last_edit = models.DateTimeField('Last Edit', auto_now=True)
    timestamp = models.DateTimeField('Create Time', default=datetime.datetime.now)
    tags = models.ManyToManyField(Tag, blank=True)
    excerpt_img_url = models.URLField(max_length=500, null=True)
    excerpt_content = models.TextField(blank=True)

    @staticmethod
    def content_changed(sender, instance, **kwargs):
        renderer = HighlighterRenderer()
        markdown = misaka.Markdown(renderer, extensions=('tables', 
            'fenced-code', 'footnotes', 'autolink', 
            'strikethrough', 'underline', 'highlight', 
            'quote', 'superscript', 'math'))
        instance.content_html = markdown(instance.content)
        soup = BeautifulSoup(instance.content_html, 'html.parser')
        if soup.find('img') is not None:
            instance.excerpt_img_url = soup.find('img')['src']
        instance.excerpt_content = bleach.clean(instance.content_html, 
            tags=['a', 'b'], strip=True)

    def __str__(self):
        return self.title

pre_save.connect(Article.content_changed, sender=Article)
FSX commented 7 years ago

Ok, looks correct. Did you also check the CSS?

ghost commented 7 years ago

I have no CSS style about the table.

FSX commented 7 years ago

Try to add it. Maybe it works.

ghost commented 7 years ago

It work after add the CSS style for it. Why the library can't do that?

FSX commented 7 years ago

That's not Misaka's job. I would have to inline CSS, which is wrong and causes conflicts with the CSS of the user/developer.