Adding markdown highlighted fenced block to django app with markdonx - python

I have been looking through the documentation but I can’t seem to get this to work. I wish to publish posts from a “creation page”. I want to use the editor markdownx. I got it to work, however there is no “fenced code support”. I tried to add the following line of code to my settings.py
MARKDOWNX_MARKDOWN_EXTENSIONS = ['fenced_code']
but it breaks the code, in fact I get the following error (when I try to create a post):
SyntaxError at /markdownx/markdownify/
if I erase the extensions list, it works fine.
I would like also to use the codehilite extension by adding it to the list like this
MARKDOWNX_MARKDOWN_EXTENSIONS = ['fenced_code' ,'codehilite']
but it does not work. I have installed pigments but the documentation does not seem to help. Could someone help me add this extensions correctly, getting highlighted code blocks to work. Thank you very much.

Related

Downloading file names with commas in them using Selenium?

So I'm doing a very simple click on link to download file in selenium. It looks something like this:
driver.find_element_by_xpath('element_xpath{0}'.format(i)).click()
Which works just fine. My problem is sometimes chrome throws a ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION.
I googled that to find this question and basically chrome throws that error when there is a comma in the file name and I have verified that this is exactly what is happening in my case as well. Now I realize I might be able to fix this with perhaps the requests library using the same suggestions as the ones in the question above; namely wrapping the file name in quotes or replace the comma with another character.
But my question is, is there any way to handle this issue in selenium? Chrome throws the same error when I manually try to download the file, IE works fine. Switching the selenium driver to IE is something I would like to avoid because it creates a whole lot of other problems.
Any help is appreciated. Thanks.

click package tokens in Python

I am working on a command line interface by using the click package in Python. I got struck at getting token as an argument in sub-command. For more details I am attaching an image on how i want the function like in this
As specified in the image I got stuck at that point, so please help me on this issue.
there you dont need any token interface it just a string name
#click.argument('tokens',nargs=-1)
when we use this way we get the output as you mentioned above.

How can I send a picture from my computer to my Discord Bot w/ Python

This is my first time posting a help request/question on this website, I've seen that the community is helpful.
I'm a newbie into Python scripting. I currently got a music player's bot template, so I could start learning messing up with the notepad++, and python.
I've seen how you can post the picture, by doing client.send_file(channel,Picture).
I tried just put in picture the file's location(picture), and it said that it wasn't defined.
I tried also let picture, and try create something defining Picture.
def Pic1 'C:\Users\Norberto\Documents\NMusicBot\Pictures\MyPic1.jpg'
It gives me a Syntax error.
SyntaxError: invalid syntax.
Maybe this is simple to solve, but I can't figure out how to fix this!
Regards,
Norby.
I finally fixed it.
The location of the file usually is something like "C:\Users\Something", while writting the location in the script, you need to add the '\' twice, something like: "C:\Users\Something".
For send it, it's just Client.send_file(location).
You can also create a 'shortcut' for it, by doing "Pic1 = C:\Users\Something" and then, "Client.send_file(Pic1).

Integrate pylint with github review comments

I am trying to make a script that runs pylint on the files present in the pull request and creates inline comments for the linting errors.
I got a hang on how to use PyGithub. The problem is that in order to comment on a pull-request you will have to know the commit that modified the file and the line number from the patch. Full documentation on the review comments API is found here.
Pylint returns the line in the resulted file. I need to get from foo/bar.py:30 to the commit that modified line 30 in foo/bar.py and to get the actual position in the diff for that file.
Is there something that already can do this or do I have to manually search for ## lines in every commit involved in a pull request?
What you are asking for is exactly what the blame feature does.
The only API I could find was this restfulgit.
Based on blind text search this here looks like the function that implements getting blame info, if you understand how it uses the underlying git api then you can just copy that part instead of using the restfulgit

Apache File Does Not Exist workaround

I have an app that calls upon the extension found here. I have the .py file in my /var/www folder so that it can be imported in my python code.
So, I keep getting this error:
File does not exist: /var/www/flask_util.js
in my apache error logs. It looks like, because of the name or something, it wants to find a javascript file. But, it's in python. Here's the line of code in python that import it:
from flask_util_js import FlaskUtilJs
I've tried just changing the name of the file to flask_util.js, but again, nothing. Not entirely sure what is going on here, but I am sure that I have a file in /var/www that it should be reading.
EDIT
I think, actually that the import error is coming from importing it into my HTML when I do this:
{{flask_util_js.js}}
So, what I tried was copy out the JS code from the python and create a new file with it in the correct path. When I did that, I still got the same error on the webpage, however the apache logs don't say anything (which is weird right?). So, it still doesn't work, and I don't know why
So, it's ugly but what I ended up doing was copying over the generated JS file that I could find on my server (didn't actually exist as a document in my repository). Then, apache could find it.
This part is for anyone who is actually using flask_util_js:
However, it wasn't reading in the correct Javascript for the url_mapping so I had to go in a hard-code the correct URLs. Not very scalable, but oh well.

Categories