If we insert code in asp.net forums we have to put any additional tags in code for displaying??because so many sides my code is not coming in questions but if we are going to edit question the code is coming
Look in the forum help ... most forums allow some type of inline code to be defined in blocks, such as the 'Code Sample' pre tags here in SO:
void main()
{
printf("Hello World\n");
return;
}
If you're specifically talking about Microsoft's ASP.NET forum, click the code button (looks like this: alt text http://forums.asp.net/tiny_mce/jscripts/tiny_mce/plugins/sourcecode/images/code.gif) and paste your code into the window that pops up. The site will do all the HTML tag translation for you.
Related
I'm using the Easy Admin Bundle for a mini Symfony app.
The bundle comes with the trix editor for the text_editor field input.
The editor is pretty cool and offers a code feature that encapsulates the paragraph in <pre> tags. The issue is I'm using highlightjs on frontend to make my code sections pretty. Now highlightjs requires code be encapsulated in <pre><code> ...code here... </code></pre> tags which is a bummer.
Is there any way to control in which tags are code sections encapsulated with the trix editor. In my specific case from <pre> to <pre><code>?
I had the exact same problem, and unfortunately I couldn't figure out how to update the Trix source code to add the code element in the pre element and also add the class. I asked the question here, and I'm going to open an issue to see if the nice folks over at Trix would consider adding this functionality.
So, I put together a little hack that will transform the pre elements when I display them to the user. Here is what the code looks like:
const applyFormattingToPreBlocks = function () {
const preElements = this.showPostBody.querySelector('.trix-content').querySelectorAll('pre');
preElements.forEach(function(preElement) {
const regex = /(?!lang\-\\w\*)lang-\w*\W*/gm;
const codeElement = document.createElement('code');
if (preElement.childNodes.length > 1) {
console.error('<pre> element contained nested inline elements (probably styling) and could not be processed. Please remove them and try again.')
}
let preElementTextNode = preElement.removeChild(preElement.firstChild);
let language = preElementTextNode.textContent.match(regex);
if (language) {
language = language[0].toString().trim();
preElementTextNode.textContent = preElementTextNode.textContent.replace(language, '');
codeElement.classList.add(language, 'line-numbers');
}
codeElement.append(preElementTextNode)
preElement.append(codeElement)
})
};
I also wrote up a blog post that goes into more detail about what this code is doing. I using Rails 6 and the post has an example of what the formatting looks like. Let me know if you have questions.
sorry for the title, but it is hard to describe my problem/ question in a short sentence or title.
So here is my story:
I am writing a WP plugin, which replaces the original [gallery] shortcode. For having a correct "preview" in visual editor (TinyMCE), I also slightly modified (by replacing it) the wpview plugin. But just small changes, like removing the 'Remove' button from the inline toolbar.
All works pretty well so far. One can switch between HTML and Visual mode. The [gallery] shortcode is replaced with the HTML output in Visual mode.
The only thing/ problem is, that if one selects a gallery view and drags it around, it becomes the (original) element (with the [gallery] shortcode).
I have really no idea why and where this happens!?
So my first question is, if anyone has an idea?
Searching for a solution/ workaround for this issue, I would also like to know, if there is an event fired, when a drag & drop action ends in WP TinyMCE?
I realized, that for a drag & drop action TinyMCE appends a element with class attribute "mce-drag-container". Maybe I have to monitor the iframe document for the existence of this element (to call a function when it is removed)?
Any ideas, tips or hints for this?
The last option I could think of would be to make the wp gallery views non-draggable.
Unfortunately I could not find any information on how to do it. If it is possible in the end?
So if anyone has a clue ...?
Any help is very much appreciated.
Many thanks in advance.
Greetings
Gunther
Have you tried listening for a general content change and checking if it's a dragged image?
All TinyMCE editor events can be found in the docs: https://www.tinymce.com/docs/advanced/events/
OK, after some further investigation I found the function that caused my "problem".
It is the following (in wpview:
// Make sure views are copied as their text.
editor.on( 'drop objectselected', function( event ) {
if ( isView( event.targetClone ) ) {
event.targetClone = editor.getDoc().createTextNode(
window.decodeURIComponent( editor.dom.getAttrib( event.targetClone, 'data-wpview-text' ) )
);
}
} );
In my case this is an "unwanted behaviour", as I wanted the view to stay intact/ as is.
So the solution (in my case) is just to delete/ do not use this event/ function.
I want to open a link in a new window using reStucturedText. Is this possible?
This opens link in the same window:
You can `check your location here. <http://geoiptool.com>`_
To open a page in a new window or tag you can add the attribute target="_blank" to your hyperlink although I'm not sure how you can add attributes to inline hyperlinks in reStructuredText. However, from the Docutils FAQ, is nested inline markup possible, you can use the raw directive to include raw HTML into your document, for example
You can |location_link|.
.. |location_link| raw:: html
check your location here
Update to address comments
I've had the question "why does reStructuredText not have [insert some awesome feature]".
In this case, "why does reStructuredText not have a way to specify how links are opened" — I think reStructuredText doesn't have an easy way of doing this since the behaviour of how clicking a link works isn't really it's responsibility. reStructuredText transforms markup — how that markup is ultimately displayed is not up to reStructuredText, but whatever browser or viewer the user chooses to use.
In the case of opening a link in a web browser, good useability practice dictates that you should not force a user to open a link in a new tab (which is what adding target="_blank" is doing). Rather, you should leave the choice of how to open the link up to the user. If a user wants to open a link in a new tab, then they can use their middle mouse button (or whatever their favourite shortcut key is).
So I think that it is perfectly acceptable that reStructureText does not have an easy target="_blank" feature. The fact that it is possible is nice for people who really want to do this is good, and the fact that it is a bit of pain to do so is good for discouraging this practice.
If you don't want to modify the theme, you can do what Ivonet did but with a custom.js file in the _static/js folder, then adding it to the conf.py like this:
html_js_files = [
'js/custom.js'
]
Leave out the html tags in _static/js/custom.js if you do this:
$(document).ready(function () {
$('a[href^="http://"], a[href^="https://"]').not('a[class*=internal]').attr('target', '_blank');
});
This will also work if you'd like a shorter version.
$(document).ready(function () {
$('a.external').attr('target', '_blank');
});
I agree completely with the accepted answer, especially with the part where reStructuredText is not responsible for how a link behaves.
I still want it though so it should be solved in the theme. As I want all my external links to open in a new tab it becomes very cumbersome to do it as described above.
In my case I use a third party theme (sphinx_rtd_theme) and I put the following script near the end of the layout.html:
<script type="text/javascript">
<!-- Adds target=_blank to external links -->
$(document).ready(function () {
$('a[href^="http://"], a[href^="https://"]').not('a[class*=internal]').attr('target', '_blank');
});
</script>
It seems to do the job just fine.
Hope it helps.
I recommend that you should use JavaScript to set target="_blank" for each external links.
See https://github.com/sphinx-doc/sphinx/issues/1634
I need to format text in posts using WordPress to look like a code. Like here in stackoverflow we use { } to separate the code from the text. I need to do the same when I write my blogs in Wordpress
Example ....
code will look like that !
Do you like the one used here: http://inturnets.com/2012/06/a-nice-tackling-with-jquery-and-css.html ?
It's the syntaxhighlighter wp plugin, http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/ , a very customisable one and finally you are using simple tags like [html] html code [/html] or [css] css code [/css]
Good luck! :)
Wordpress has a preformatted paragraph style that works OK without any plugins. Just select the text and then select the Preformatted style on the left side of the formatting bar:
I had installed a plugin, but then found this simpler and it works fine for my purposes.
This might be helpful to you
http://textformat.in/
Please do vote if it worth
I am trying to load html file in CKEditor in asp.net but for some reason I don't know how to put the html code from the code behind file.
CKEditor1.FilebrowserBrowseUrl = url;
CKEditor1.BasePath = url;
CKEditor1.Text = content;
none of that helped
Any advice? Thanks in advance, Laziale
I'm not sure which version you are using, but let's suppose that it's 3.x. I was playing around with the control and didn't find any possible way of doing this from code behind. However, I managed to make it work like this:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "fckInitialization", #"
window.onload = function () {
var oEditor = CKEDITOR.instances['" + txtPost.ClientID + #"'];
oEditor.insertHtml('<strong>This is a bold text.</strong>');
};
", true);
I tried it in IE 8 and the last version of Mozilla (I think it was 9) and it worked. I also tried the same thing, but instead of window.onload I used the jQuery $(document).ready() and it worked only in IE. The reason is that you have to wait for everything to load in order to use the functions from the CKEditor API. I played with Firebug and the insertHTML worked.
If you are using 2.x, you can see somewhere in Google the same approach, but with a different API. I just can't find the link right now.
Another problem will be here, as you may figure out, that if you want to initialize a long text, you will have to write everything in a script, which is not really nice.
Maybe a possible solution for you will be to convert the HTML to BBCode first and then just set the Text property. This, of course, depends on the way you use the control, because BBCode does not contain all possible tags, but you can always modify the bbcode plugin of CKEditor to meet your needs. And I tested it and it works.
PS. Probably you can do it with the JavaScript method and an AJAX call.
Hope this helps!
Assuming ckeditor is being initialized from a textarea field, you can simply populate the body of the textarea.