HTML generated with Sphinx removes the word "module" - javascript

A colleague has pointed out to me this peculiar behavior. We use Sphinx to generate the HTML documentation of our project, and whenever we use the word 'module' in our text, this word is removed by the browser.
After some inspection, I have noticed that the word does appear in the source code of the HTML page:
but the rendered result looks like:
where clearly the word 'module' has been removed.
Further inspection on the html source code revealed the following javascript code which seems to be the culprit:
Therefore, I wonder who generates this script? Is it Sphinx or any of its extensions? Is there any workaround to get the word 'module' displayed in the rendered html?
This is the list of Sphinx extensions we have activated:
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
'sphinx.ext.todo',
'sphinx_rtd_theme',
'sphinx.ext.autosectionlabel',
'sphinxcontrib.email',
'sphinxcontrib.bibtex',
'sphinx.ext.graphviz',
'sphinx_git',
]
UPDATE:
I have found the real cause of my problem. For some reason which I ignore, I had a layout.html file in my /source/_templates folder. This file seems to be extending the default one (as in a way explained here), adding the javascript function that removes the word 'module'. Next step will be to find out how did that file get there...

I seem to have come up with a workaround (although not the most satisfying solution)
I thought that this javascript code would work in a single-pass fashion, and therefore, typing 'modulemodule' instead of 'module' would result in the removal of one ocurrence, resulting in a final 'module'. And it has worked!
To make it slightly better, I have created a substitution as .. |module| replace:: modulemodule which I store in another file and include whenever needed. Now, I only need to write my sentence like Hello this is a |module|. (notice the double space between a and |module|)

Related

Why is the code formatting not working on this highlighted generated jekyll page?

In my gh-page, the code formatting tags are properly encoded.
< tag name goes here >
Corresponding <pre> and <code> tags are enclosed.
I believe this is the reason, the preview renders without any issue.
However on the resulting page UI, the code highlighting breaks after # Dependency property system - DPS.
I'm using highlightjs
This seems to be a kind of bug to me.
Any suggestions on this?
Thanks to isagalaev.
It's a bug, but not in highlight.js. Here's an excerpt of the relevant part of page source:
<pre><code>
namespace abcLib
{
public class LatinWords : IMarkupExtension<string>
...
}</code></pre>
There are two problems with it:
You probably wanted displayed as is, so you have to escape it as <string>
It looks like </code></pre> was supposed to actually end this code snippet, so they should not be escaped: </code></pre>
I don't know what kind of software generates this HTML, so I can't give any particular recommendations on how to fix those two problems. But they most certainly have nothing to do with highlighting, it's just HTML.

Jquery image bookmarklet not working in Django

Im working through Django By Example and in one chapter a Jquery bookmarklet is built within a Django app so that a user can easily save jpg images from a website into their user profile area within the Django app.
Im not an experienced JS or Jquery programmer but I did some JS some years back and can read the code however the tutorial does give exact instructions on what to do which I have followed and although I have managed to get the bookmarklet button to appear in my bookmarks bar in Chrome, nothing happens when I click it when browsing a webpage with jpg images.
This is my local Django dashboard where the bookmarklet button is added to the bookmarks bar and this part works fine
and this is what it should look like when clicked on, this is the part where nothing happens for me
these are the relevant js files
https://github.com/davejonesbkk/bookmarks/blob/master/images/templates/bookmarklet_launcher.js
https://github.com/davejonesbkk/bookmarks/blob/master/images/static/js/bookmarklet.js
the only thing I can see that is different with these compared to the files that came with the book is the indentation is a bit off but for some reason the indentation does seem to have changed a bit when I uploaded to Git and they dont look like that locally. Is indentation important in JS?
I followed the same book with the same examples but didn't had any trouble. Make sure your dashboard.html file is referring to the correct javascript file. If nothing works try to add the bookmark manually, you can see how that's done over here http://www.howtogeek.com/189358/beginner-geek-how-to-use-bookmarklets-on-any-device/ it'll sure to work.
And answer to your last question, Indentation is not as important in JavaScript as it's in Python, as python doesn't use any curly braces "{}" or semi-colons ";". But you can write your entire javascript code in a single line and it'll work because your using curly braces everywhere to tell which line of code ends where.
I agree with all the above. In addition, the following:
Error I noticed in the book:
In bookmarklet-launcher.js the js function being called from bookmarklet.js is called myBookmarklet(), however there is no function called this way in bookmarklet.js. So, you may want to use the same name in both js files.
Practically speaking however, the bookmarklet will always work because, not finding a myBookmarklet function in memory, bookmarklet-launcher.js appends the bookmarklet.js script to the body element and, being bookmarklet.js a self-invoking function, its content executed (without the need it to being called). There are some additional interesting technicalities here (the key function in bookmarklet.js is not self invoking but it will anyway be always called because of the script checking whether jQuery is present...) but ok, this is more relevant for those busy with the mentioned book (Django 2 by example).
Check whether bookmarkled, once you click on it, is added to the
current webpage:
2.1. Open devtools (F12 on Chrome) and check e.g. in the html head element whether you find the newly added link element containing the css attribute and/or in the body element whether you find the script element containing the reference to the bookmarklet.js file.
2.2. Alternative: Add an alert message on top of the bookmarklet.js script so that it will be launched if it is correctly loaded. Example:
(function(){
alert('bookmarkled loaded!');
var jquery_version =...
Make sure you're trying to use it on a HTTP site only. Since you're serving from same protocol. HTTPS site would always tell say: There is a problem loadingbyour jquery. That's how I solved mine.
dude.I have solved the problems I met like you.
The most important thing is that noticing the syntax error(without warnings),mainly caused by ignoring blank.
for example, in the line:
jQuery('#bookmarklet .images').append('<img src="'+image_url+'"/>');
between #bookmarklet and .images should lie a blank space,because of jquery syntax rules(meaning to search tag with id of bookmarklet and search tag with class equaling images within result previously).
Another two places worth notice are codes containing #bookmarklet .images a and #bookmarklet #close,requiring blank spaces between filter condition.
That's where I found I made mistaks mainly after studying syntax of jquery.
You'd better compare your codes with codes already loaded up to github by someone to make sure there are no more little errors(such as spelling).

Adding hyperlinks into xml file

I purchased a script online that's no longer supported and I just need one last functionality to finish off my project. One detail the client needs is to have a line of text link to another page in the site.
I do not know a whole lot about xml, but I understand it doesn't support html to include hyperlinks.
This is a quiz where users must answer specific questions in order to move on to the next step. It's fed into a div by a js file, I think, but I don't understand how it works. I'm not going to post any code just yet as I'm just reaching out for some advice right now and if what I want to do is even possible.
Is there some kind of a workaround? I've Googled plenty of sites with code chunks and have done a lot of experimenting, but I mostly just break the page the xml displays on.
Thanks.
Dont use the actual xml syntax of tags like <a></a>. Better replace these with other symbols like [a][/a]. When you output the code, simply replace [ and ] with < and >
You replace code before you put it into a div could look like this:
xmlAsString.replace(/\[/g,"<").replace(/\]/g,">");
edit:
I totally forgot about CDATA.
Forget my previous answer. Just add the <![CDATA[...]]> Tag around the anchor in your XML:
<![CDATA[link]]>

Copy a code snippet in MS Word using JavaScript?

I've come across a Word document that includes sections of example code, all of which being preceded by hyperlinks called "Copy" with the following address format:
javascript:CodeSnippet_CopyCode('CodeSnippetContainerCode_538898d8-038f-4f82-9a2d-a558335289ae');
My question is, what in the world is this trying to do, and why isn't it working?
I'm assuming it should be copying the code snippets, but the result of Ctrl+Clicking the links is a security notice (clicked to allow) and then the IE View Downloads window shows up.
Between my not really knowing javascript and all the alphanumeric garbage confusing my efforts to understand the syntax, I can't make heads or tails of this...
This is the Javascript command that is included in some websites such as MSDN to allow you to copy code snippets from the website to the clipboard with one click.
When the original author copied the code to the word document he must of copied the link the links which include that Javascript command as well by a mistake. This type of link has no use in Microsoft Word and it can be removed.

Django CMS / WYMEditor Stop Stripping of Whitespace

I'm aware of what WYMEditor is all about and that using Paragraphs for spacing is not intended, however the problem here is with the client requiring that we give them this functionality.
I've looked high and low to find where WYMEditor does it's stripping of whitespace and can't seem to find it at all.
It seems that when you press enter it creates a P visually, however when clicking the source it doesn't contain it. Furthermore, manually editing HTML source to contain <p> </p> doesn't work, as WYMEditor strips it out.
Just wondering if anybody has had this issue before and knows how to get rid of this functionality? It's worth noting that I believe the replacement is happening both in the 'text' module of Django-CMS, and also in the Javascript for WYMEditor.
Turns out, the function that does this stripping is very simply named, for some reason I missed it in (multiple!) searches for the word 'empty' in the script file.
It's located in jquery.wymeditor.js, line ~3440 there is the function WYMeditor.XhtmlSaxListener.prototype.removeEmptyTags, simply stop the replacement:
WYMeditor.XhtmlSaxListener.prototype.removeEmptyTags = function(xhtml)
{
return xhtml;// .replace(new RegExp('<('+this.block_tags.join("|").replace(/\|td/,'').replace(/\|th/, '')+')>(<br \/>| | |\\s)*<\/\\1>' ,'g'),'');
};
That obviously stops the stripping of whitespace!

Categories

Resources