MediaWiki breaks when I put C++ code in preformatted text - mediawiki

I want to use MediaWiki to document a C++ coding project. I am dropping code snippets into a preformatted text block. The problem is, when I include a line of code like:
if(x == y)
it breaks the page.
I'm assuming the parser thinks is markup opening heading with no matching close.
Is there a way to mark the == so that it isn't taken as markup. Haven't been able to find a reference.

Activate SyntaxHighlight in your LocalSettings.php with wfLoadExtension( 'SyntaxHighlight_GeSHi' );. make sure /path/to/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize has execution permissions and wrap your code snippets with <syntaxhighlight lang="C++">...</syntaxhighlight>,
OR
wrap your snippets with <pre>...</pre>,
OR
indent every line of your snippets with at least one space.

Related

Is it possible to add a real link in a code highlight block in Jekyll?

I would like to do something like this:
```swift
let someVar = "foo"
```
in Jekyll, and have it show up as a highlighted block of Swift code, where someVar can be clicked and go to #. Currently the tag is printed and visible instead. I know it's not exactly what the syntax highlighting feature in Jekyll is for, but is it possible in any way to add links to highlighted code blocks, without manually highlighting myself? Is there perhaps some other GitHub Pages-compatible plugin that could do this?
Looking at the code, there doesn't seem to be any way to escape code formatting inside a Jekyll Rouge highlight Liquid block to either to go back out to markdown parsing, or to insert raw HTML.
Another approach would be to use JavaScript to parse the content of your HTML and substitute in a link whenever you see the corresponding tag.
More info: Replace words in the body text

Strange symbol shows up on website (L SEP)?

I noticed on my website, http://www.cscc.org.sg/, there's this odd symbol that shows up.
It says L SEP. In the HTML Code, it display the same thing.
Can someone shows me how to remove them?
That character is U+2028 or HTML entity code 
 which is a kind of newline character. It's not actually supposed to be displayed. I'm guessing that either your server side scripts failed to translate it into a new line or you are using a font that displays it.
But, since we know the HTML and UNICODE vales for the character, we can add a few lines of jQuery that should get rid of the character. Right now, I'm just replacing it with an empty space in the code below. Just add this:
$(document).ready(function() {
$("body").children().each(function() {
$(this).html($(this).html().replace(/
/g," "));
});
});
This should work, though please note that I have not tested this and may not work as none of my browsers will display the character.
But if it doesn't, you can always try pasting your text block onto http://www.nousphere.net/cleanspecial.php which will remove any special characters.
Some fonts render LS as L SEP. Such a glyph is designed for unformatted presentations of the character, such as when viewing the raw characters of a file in a binary editor. In a formatted presentation, actual line spacing should be displayed instead of the glyph.
The problem is that neither the web server nor web browser are interpreting the LS as a newline. The web server could detect the LS and replace it with <br>. Such a feature would fit well with a web server that dynamically generates HTML anyway, but would add overhead and complexity to a web server that serves file contents without modification.
If a LS makes its way to the web browser, the web browser doesn't interpret it as formatting. Page formatting is based only on HTML tags. For example, LF and CR just affect formatting of the HTML source code, not the web page's formatting (except in <pre> sections). The browser could in principle interpret LS and PS (paragraph separator) as <br> and <p>, but the HTML standard doesn't tell browsers to do that. (It seems to me like it would be a good addition.)
To replace the raw LS character with the line separation that the content creator likely intended, you'll need to replace the LS characters with HTML markup such as <br>.
This is the solution for the 'strange symbol' issue.
$(document).ready(function () {
$("body").children().each(function() {
document.body.innerHTML = document.body.innerHTML.replace(/\u2028/g, ' ');
});
})
The jquery/js solutions here work to remove the character, but it broke my Revolution Slider. I ended up doing a search replace for the character on the wp_posts tabel with Better Search Replace plugin: https://wordpress.org/plugins/better-search-replace/
When you copy paste the character from a page to the plugin box, it is invisible, but it does work. Before doing DB replaces, always have a database (or full) backup ready! And be sure to uncheck the bottom checkbox to not do a dry run with the plugin.

HTML - insert user-created HTML into a HTML page: escaping and discarding format

I have an HTML page which needs to display some HTML generated by the user on the Administration area (like a blog, for instance). The problem is that the user sometimes needs to copy-paste tables and other "garbage" content from Word/Excel to the WYSIWYG editor (that has the proper "paste from Word" function). This causes the resulting HTML code to be very dirty.
It wouldn't be a problem unless some of these pages are shown totally wrong: other divs AFTER user's HTML code are not in their supposed position, floats are not respected... etc...
I tried putting a div:
<div style="clear: both;"></div>
without success. I even tried with iFrames, but iFrames accept only external webpages (if applicable...).
The question is: is there any tag or method to put a part of an HTML code inside a webpage discarding all formatting AFTER this code?
Thank you.
To my knowledge, you simply want to end all divs. HTML is a very simple code, with very simple options. Your example doesn't work because HTML isn't that advances. You can either start a function <...> or end a function .
Ideally what you want is a piece of code that puts their work in a separate frame entirely, so as soon as the page passes their code, it goes back to the correct formatting.
Or, you could be really sloppy and put one hundred 's in, just in case.

How to display source code with indent in a web page? HTML? CSS?

I want to show some source code with the WebBrowser control on a winform. And I want to decorate the source code with HTML tags, such as color, font, and size. But I found it difficult to display the indent properly.
To be precise, my source code are held in String[], and each String holds the proper indent (space or tab) already. But it seems these kinds of indent are just ignored by the WebBrowser control.
Could someone tell me how to?
I like to paste my code in a Gist and then display it that way. Github will recognize the code and format it accordingly.
If you're going to be doing it often you could try markdown.
Or use a one-off formatter like Syntax Highlighter.
The <pre> element (using <code> elements with appropriate class names to mark up the parts you want to syntax highlight)
<pre><code class="javascript"><code class="keyword">function</code> <code class="name">foo</code>()…
You might want to look into this JavaScript library to highlight and format your code. http://code.google.com/p/syntaxhighlighter/
Or you can check out a service like this - http://pygments.appspot.com/ or this - http://hilite.me/

<p> tag getting added to inline macro

I am using umbraco 4.7. I have created a razor macro to insert telephone number in my rich text editor. Whenever i add the macro in the RTE, <p> tags are added around the macro automatically. I tried removing the extra <p> tags by editing the html but as soon as I click on save, the <p> tags are added again. I tried installing this package
but it didn't solve my problem. I have tried setting the <TidyEditorContent>False</TidyEditorContent> and checking the forced_root_block : 'p' but none of these could solve the problem.
Any pointers to solve this issue?
This is a common issue, and the RTE causes a number of headaches for maintaining the integrity of your web page. The whole "should we include paragraph tags or not?" question is a difficult one, as it is fine to remove them when only inserting a single paragraph of text, but what if the content editor decides to add more, and you are stripping out the first and last P tags?
Bearing in mind that the CSS for a site will always need to support whatever you choose, the best option is to edit the configuration file to make TinyMCE omit the P tags. To do this, you need to edit the /config/tinyMceConfig.config file. This has two interesting sections at the bottom. contains allowed HTML tags, and the of course contains the opposite.
If you look in the valid elements list of comma separated values, you should see a value #p[id|style|dir|class|align]. Taking note of EXACTLY how this is formatted, you should be able to move it into the invalid elements section. Put it after the default font tag, with a comma preceding it of course.
Restart IIS and try entering your content in the RTE. When you publish, then view the output, you should see that the string in the RTE has had the paragraph tags stripped.
One final option is to strip the paragraph tags from the output. There are many new ways of doing this, but for your Razor version I would use something like:
#Html.Raw(umbraco.library.RemoveFirstParagraphTag(value.ToString()))
This idea is covered in another StackOverflow article.
Good luck, and please let us know if you have any success.
use this jquery .....
$('p').each(function() {
var $this = $(this);
if($this.html().replace(/\s| /g, '').length == 0)
$this.remove();
});