neurobin / mdx_wikilink_plus

A wikilink extension for Python Markdown
Other
16 stars 4 forks source link

Render Images #7

Closed flywire closed 3 years ago

flywire commented 3 years ago

See #6

This code works but it has issues: 1. Only output alt tag from label (pipe) 2. Clear end_url for images because it is not valid 3. Define image_class Config param

Tests at: https://github.com/neurobin/mdx_wikilink_plus/issues/6#issuecomment-740998217

What do you think?

neurobin commented 3 years ago

default class for image (the image_class param) should be wikilink-image or wikilink-img or any known convention. It should be different than link (wikilink).

I see point 2 is still marked as an issue but there is a commit for it (Clear end_url for images). Does it not work as expected?

flywire commented 3 years ago

I see point 2 is still marked as an issue

Yes, I understand that query is not valid on an image and should be cleared. urlo.query = '' is invalid.

Also, checkurl does not fix the test that renders as <p><img class="wikilink-image" src="https://www.example.png/" /></p>

(btw I don't understand the syntax for url = self.config['build_url'][0](urlo, base_url, end_url, url_whitespace, url_case))


Feel free to jump in when you are ready!


More:

1. default image class as you say

  1. refactoring: change isimage to image as a class and any other tidy up - I don't know OOP so you might do the refactoring 3. incorporate tests 4. readme
  2. release including https://pypi.org/project/mdx-wikilink-plus/
neurobin commented 3 years ago

I understand that query is not valid on an image and should be cleared. urlo.query = '' is invalid.

If query is given on the wikilink image path, then it can remain, I don't think it will be a problem. When someone uses this, he will most certainly not use query on image wikilink, if he does, then he will get the query as well. So, we can keep the query.

neurobin commented 3 years ago
[[/path/to/file name.png/?a=b&b=c]]
[[https://www.example.png/?]]
[[https://www.example.jpg/?a=b&b=c]]

These are not valid, so we don't need to cater for them.

rather, there should be a test for [[https://www.example.jpg?a=b&b=c]]

flywire commented 3 years ago

[[https://www.python.org/static/community_logos/python-powered-h-50x65.png|alt= Python powered logo]] renders in a GitHub wiki page as [without link below]:

Python powered logo Click to open wiki page

there should be a test for [[https://www.example.jpg?a=b&b=c]]

I'm not familiar with that implementation. Can you reply with a live code example and add it to the wiki page above?

neurobin commented 3 years ago

Can you reply with a live code example

The examples are in test.py file.

neurobin commented 3 years ago

You can copy def test_with_meta(self) method and write a similar test only changing the input text and output.

neurobin commented 3 years ago

Like this:


    def test_with_meta(self):
        output = """
<p><a class="wikilink" href="/static/wikilink">Wikilink</a>    <code>[[wikilink]]</code></p>
<p><a class="wikilink" href="/static/wikilink">Wikilink</a>    <code>[[Wikilink]]</code></p>
<p><a class="wikilink" href="/static/path/to/file_name">File name</a></p>
<p><a class="wikilink" href="/static/path/to/file_name">File name</a></p>
<p><a class="wikilink" href="/static/path/to/file-name">File name</a></p>
<p><a class="wikilink" href="/static/path/to/file_name/?a=b&amp;b=c">File name</a></p>
<p><a class="wikilink" href="/static/path/to/file_name.html">File name</a></p>
<p><a class="wikilink" href="/static/path/to/file_name.html?a=b&amp;b=c">File name</a></p>
<p><a class="wikilink" href="https://www.example.com/">www.example.com</a></p>
<p><a class="wikilink" href="https://www.example.com/?a=b&amp;b=c">www.example.com</a></p>
<p><a class="wikilink" href="https://www.example.com/example-tutorial">Example tutorial</a></p>
<p><a class="wikilink" href="https://www.example.com/example-tutorial">Example Tutorial</a></p>
        """.strip()
        md2 = markdown.Markdown(extensions=[WikiLinkPlusExtension(), MetaExtension()]) 
        html = md2.convert(meta_text+"\n\n"+text)
        # ~ print(html)
        self.assertEqual(html, output)

    def test_with_image(self):
        text = 'something'
        meta_text = 'see example above'
        output = 'something'
        md2 = markdown.Markdown(extensions=[WikiLinkPlusExtension(), MetaExtension()]) 
        html = md2.convert(meta_text+"\n\n"+text)
        # ~ print(html)
        self.assertEqual(html, output)
neurobin commented 3 years ago

Once you include all the possible wikiimage syntax in the test and the test passes, you can increase the version number to 1.4.0

flywire commented 3 years ago

The examples are in test.py file.

I'm sceptical that a query works on an image which is why I requested you demonstrate it in the wiki.

Hmm, Seems you haven't been reading the extended description under , particularly 75a5b79. The extra code is messy so I'd still recommend some OOP refactoring before release.

I'm not clear what the ~ is in the test code. The default config html is given first but when printing is enabled it prints last. I referenced this file in the readme so it would be good if the coded and printed order were the same.

neurobin commented 3 years ago

I'm not clear what the ~ is in the test code

It's one of my editors that is the culprit, it adds # ~ when commented and removes them when uncommented :smile:

The default config html is given first but when printing is enabled it prints last

I am not clear what you are referring to here, but if you feel like changing any order to make it good, feel free to do so.

The extra code is messy so I'd still recommend some OOP refactoring before release.

I shall see what can be done. I should be able to release a new version within a week.

flywire commented 3 years ago

I am not clear what you are referring to here, but if you feel like changing any order to make it good, feel free to do so.

I don't understand why it happens.

  1. enable print in test.py
  2. python test.py >test.out
  3. fc test.py test.out

html block for test_without_config prints last. It is unexpected/confusing if users study test.py examples.

neurobin commented 3 years ago

I see. I have added unittest.TestLoader.sortTestMethodsUsing = None to test.py to prevent unittest to sort the methods. It should keep the order as is.