So i want to display well formatted code with syntax coloring as we see in stackoverflow, in my blog. While I paste my code in ckeditor under the code section, it is pretty good and well formatted. Like in the picture below.
I want something like that to appear on my website. But when I save it and view it on my website, I get formatted but not syntax colored code. Like the picture below.
Am I doing anything wrong here. Please help
You want code/syntax highlighting. There is a ckeditor plugin for that or you can use a Pygments, python syntax highlighter. Here is a short tutorial how to create django filter with Pygments
Related
I have some interactive graphs made with plotly and would like to embed them on my "webpage" that I created using GitHub pages. I tried something like {%include myfig.html%} but it tells me that the file is not found in the _include file. However, I cannot take hands on this file...
Any simple way to embed a plotly interactive graph on markdown using github pages ? I've looked for it on the net but could not find anything that helps me.
The answer was actually quite simple : Just use the commande: {% include_relative myfile.html} instead of {% include myfile.html %}
I have troubles with creating screenshots using imgkit. I can easily make a screenshot full site, but I don't know how to screenshot only specific div block in html. I'm totally noob in html, I don't think it is good idea to learn it for one python script...
For example, make a screenshot only for this google block
I am a beginner at coding and I am trying to use a blog to keep a record of notes on learning.
I am using jupyter notebook for python, but can't find any solution for a simple way to copy a snippet of html code into the blog. I can only do it now by saving examples/notes as an image
Is there a simple way to do it , such as in this?
There are a few ways to do this, but I'm not sure that any of them are as quick/simple as you're imagining. A lot of this also depends on what blogging platform you use. For example, the second example you posted looks more like raw code that has been copy/pasted and then formatted by their blogging platform
Here's a few things you can try, but none of them offer direct "export cell" functionality. They also assume you only want a static notebook for display:
Export to HTML
Go to File > Download as > HTML
This will give you a HTML page with all of your cells nicely rendered. Its not that trivial to extract specific cells to post on a blog, but if you just want to display your entire notebook you have everything as a HTML that you can upload to wherever your blog is.
It will look exactly like your full notebook:
Export basic HTML template
You can use nbconvert to give you a basic HTML rendering of your notebook. Open a terminal, go to the directory where your notebook is located and type:
jupyter nbconvert name_of_notebook.ipynb --template basic
That will give you a html page without all of the flashy styling. This makes it much easier for you just copy/paste the specific cell you want (as HTML) into your blog. Your blog would then need some styling/syntax highlighting to make it look pretty
This will look like a simple rendering of your notebook:
As an aside, the first option (exporting the full HTML page) also uses nbconvert behind the scenes, just without the --template basic argument
Export to markdown
Go to File > Download as > Markdown
If your blogging platform supports markdown, you can export your notebook as a markdown file without all of the styling and copy/paste the cell you want into your blog post. Again, you'd need a way to style it on your blog
This will give you basic markdown code you can copy/paste anywhere:
```python
a = 2
b = 5
print(a+b)
```
7
Upload to nbviewer
http://nbviewer.jupyter.org/
If you have your notebook uploaded as a github gist, or in a github repo, or any other direct location on the web, you can use nbviewer to render it as a nice webpage, but you cant extract elements to place in your blog so not sure how useful this is for your purposes
Styling HTML/markdown on Wordpress
If you're using wordpress as your blogging platform there are a few useful plugins that will make the process a bit easier:
If you've exported a markdown file, you can use a plugin like Jetpack, which enables support for markdown in a blog post/page
If you've copy/pasted your code into a blog post (either by copying the HTML, markdown, or raw code) you can style it using a syntax highlighter like Crayon
If you really want your code to look like a jupyter notebook cell, you can use a plugin like Simple Custom CSS to set up custom styling, but this takes quite a bit of work. There are a few sites showing how to set up CSS to look like a notebook cell (e.g. http://www.mianchen.com/wordpress-blogging-with-jupyter-notebook-in-five-simple-steps/)
If you have your notebook uploaded as a github gist, you can use oEmbed Gist to embed your notebook code into your post
For my own blog I've found the simplest solution to just copy/paste the raw code directly into my blog post, and then use plugins on the blogging platform (Wordpress in my case) to style the block of code
I have a problem getting javascript content into HTML to use it for scripting. I used multiple methods as phantomjs or python QT library and they all get most of the content in nicely but the problem is that there are javascript buttons inside the page like this:
Pls see screenshot here
Now when I load this page from a script these buttons won't default to any value so I am getting back 0 for all SELL/NEUTRAL/BUY values below. Is there a way to set these values when you load the page from a script?
Example page with all the values is: https://www.tradingview.com/symbols/NEBLBTC/technicals/
Any help would be greatly appreciated.
If you are trying to achieve this with scrapy or with derivation of cURL or urrlib I am afraid that you can't do this. Python has another external packages such selenium that allow you to interact with the javascript of the page, but the problem with selenium is too slow, if you want something similar to scrapy you could check how the site works (as i can see it works through ajax or websockets) and fetch the info that you want through urllib, like you would do with an API.
Please let me know if you understand me or i misunderstood your question
I used seleneum which was perfect for this job, it is indeed slow but fits my purpose. I also used the seleneum firefox plugin to generate the python script as it was very challenging to find where exactly in the code as the button I had to press.
I'm having trouble getting my mpld3 plot to show up in my Wordpress page. I make my plot, then use mpld3.save_html() to get an html file that contains my figure. However, when I paste this code into my Wordpress page (using the Text editor, not the visual editor) nothing happens. I paste both the script and div tags. I know my javascript is working because I can write alert('Hello'); inside script tags, which works fine. I've also tried installing the "Insert Javascript & CSS" plugin, which also did not work.
Is there some way to embed these graphs into Wordpress, and if not, how does one embed interactive charts in a Wordpress post?
I suspect that the d3.js and mpld3.js were not found, which would explain why you don't see the chart.
There is a d3_url and mpld3_url that you may want to provide and set to the url of a CDN where the files are available for example See https://mpld3.github.io/modules/API.html#mpld3.fig_to_html
Even after setting that properly you may have problems as this is not the recommended way to use javascript within wordpress. You can also try an embed with stricter separation from wordpress: see http://www.datamaplab.com/posts/embedding-javascript-visualization-wordpress/ for reference.