How to use ~~satya~~ (strike) in pagedown js? - javascript

I'm using like below code
$('#convert').click(function(){
var message = $('#textarea').val();
var converter = new Markdown.Converter();
var output = converter.makeHtml(message);
console.log(output);
$('#show').html(output);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Converter.js"></script>
<textarea rows="10" cols="20" id="textarea"></textarea><br>
<input type="button" name="" value="submit" id="convert">
<div id="show"></div>
But ~~satya~~ was not working
How to make strike through work.

Markdown does not include support for strike-through in its syntax. Some implementations have added support as a non-standard addon, but the syntax varies across those (few) implementations. Without checking their docs, I do not know if pagedown offers such support, but I would assume not. In fact that would be my assumption for any Markdown implementation.
That said, the rules state:
Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. ...
For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags.
Therefore, the following Markdown:
<del>satya</del>
will result in the following rendered document:
satya

Related

Is <!-- a valid comment delimiter in JavaScript

Is <!-- a valid comment delimiter in JavaScript?
var foo = 'foo'; <!-- Is this a valid single-line comment?
Yes, it apparently is.
This syntax was included to cater for browsers that do not support JavaScript, to avoid them rendering the code inside <script> tags. This was more important in the early days of the Web, when a large proportion of browsers did not support JavaScript.
Both <!-- and --> delimit single line comments.
<!-- this is treated as a single line comment
--> and this is treated as a single line comment
So you can write your script tags using the following syntax:
<script>
<!--
console.log('this is my code')
-->
</script>
Note that the Wikipedia page on JavaScript syntax does not mention this.
Yes it is - but its rare to see these days. Typically we see C single line and C++ multi-line style commenting used.
One-line comments with the HTML comment-opening sequence. Note that
the JavaScript interpreter ignores the closing characters of HTML
comments.
source : http://www.javascripter.net/faq/comments.htm
To give a bit of context, way back when Javascript and the <script> tag were new things, there was the danger that if you put a <script> element full of script on your page, some browsers that didn't know what it was would just show its contents on the page.
The solution was to define the Javascript language so that <!-- and --> are treated as single-line comments (the latter only when it occurs at the beginning of a line with the optional inclusion of whitespace and/or multiline JS comments). This way, the HTML renderer would see all of the script as a comment, and the JS interpreter would simply ignore these lines and process the rest.
So you could do this (and presumably still can):
<script type="text/javascript"><!--
document.write("<blink>HELP!!!! I'm using 1990's Javascript!!!</blink>")
--></script>

Unable to change color of keywords within a text area

I am attempting to write a program that can detect if you inserted a JavaScript keyword, and if you have, it will change the color of it so it will stand out(It will eventually submit the code and I will use it for offline debugging on a chromebook). However, it seems that I cannot change the color of the text within the textfield when it matches a keyword. jsFiddle Example
Here is the code:
CSS:
#JScodeinputbox{font-family:Arial;}
#JScodeoutputbox{}
.JSfunctions{color:blue;}
HTML:
<body>
<textarea id="JScodeinputbox" wrap="logical" rows="30" cols="70" onkeyup="checkHighlight();"></textarea>
<canvas>
</canvas>
</body>
</html>
JavaScript:
var codeInput = document.getElementsByTagName("textarea");
var keywords = new Array("var", "if");
function checkHighlight(){
var codeInput1 = codeInput[0].value;
if(codeInput1 === keywords[0]){
keywords[0].indexOf(codeInput1).className = "JSfunctions";
}
}
If anyone know how to resolve this issue or simpler alternatives(preferrably not involving JQuery, PHP, etc.) it would be much appreciated.
PS: I know it is not about it being onkeyup, I have that for a reason. It also works when I run other methods, so I don't think it's formatting, either(but it could be).
You can use JQuery Highlight Textarea plugin with this code (sample from site)
<textarea cols="50" rows="5">...</textarea>
<script>
$('textarea').highlightTextarea({
words: ['Lorem ipsum', 'vulputate']
});
</script>
and problem solved

Make Vim correctly highlight script type="text/html"

How can I get Vim to correctly syntax-highlight in a situation such as this (used, e.g. with Knockout templates):
<script type="text/html" id="my-template">
<!-- This should be rendered as HTML -->
<div>Some template</div>
</script>
<script>
//This should be rendered as Javascript
var x = function() { return 3; }
</script>
The solution given here involves editing Vim's internal syntax file, which seems wrong, and it specifically looks for "text/javascript" which is no longer needed in <script> tags.
I assume the solution is some sort of syntax plugin I can keep in my .vim directory but am not familiar enough with Vim's syntax internals to figure it out.
(Note that this question and answer don't apply as I'm not using Ruby on Rails.)
Maybe this will help you: https://coderwall.com/p/vgk5-q/make-vim-play-nice-with-html-templates-inside-script-tags.
In case the link above is broken one day - put the following code into ~/.vim/after/syntax/html.vim:
unlet b:current_syntax
syn include #HTML $VIMRUNTIME/syntax/html.vim
syn region htmlTemplate start=+<script [^>]*type *=[^>]*text/template[^>]*>+
\ end=+</script>+me=s-1 keepend
\ contains=#HTML,htmlScriptTag,#htmlPreproc
Somebody should write a plugin for that! ;)
First copy the vim's internal html syntax file to $HOME/.vim/syntax/html.vim so that you only change the behaviour for yourself not globally.
Then find the line starting syn region javaScript and replace it with two lines
syn region script_notype start=+<script>+ keepend end=+</script>+me=s-1 contains=#htmlJavaScript,htmlCssStyleComment,htmlScriptTag,#htmlPreproc
syn region script_jstype start=+<script[^>]*type="text/javascript"[^>]*>+ keepend end=+</script>+me=s-1 contains=#htmlJavaScript,htmlCssStyleComment,htmlScriptTag,#htmlPreproc
The first line is for plain <script> tab, the second for <script type="text/javascript">.
However, this won't cover a situation with <script> tag without type attribute having other attributes. This case should get javascript syntax but won't. I guess this is a minor problem.

Display raw HTML markup from CKEditor in Angular template

I use CKEditor in my AngularJS Application. When I try to display the text that I saved from the TextEditor, it doesn't take the style. For Example if I want to display a sentence it appears as:
<p>How old are you</p>
instead of :
How old are you
I tried using ng-bind:
<div ng-bind="Item.Header"></div>
and the regular binding method:
<h3>{{Item.Header}}</h3>
But both methods didn't work. Is there a solution for this issue?
You should use "ngBindHtmlUnsafe". Since this command doesn't sanitize the expression, but you should only use it if you trust the source.
So the html will be written as follows:
<div ng-bind-html-unsafe="Item.Header"></div>

Javascript inline output

In javascript suppose you have this piece of code:
<div>
<script type="text/javascript">var output = 'abcdefg';</script>
</div>
Is there any way to simply "echo" (using PHP terminology) the contents of output into #test? That is, to output a string inline, assuming you have no standard way of traversing or selecting from the DOM?
document.write("..."); does write the contents of output, but in doing so, it replaces the entire document with the output.
The solution I'm looking for should act the same way a PHP echo would: write the output into the document inline.
You'd have to use document.write [docs]:
<div id="test">
<script type="text/javascript">document.write('abcdefg');</script>
</div>
DEMO
With the caveat that it does not work in XHTML documents. See the documentation for more details.
"Kosher" code aside, yes.
document.write()
In standards-based browsers:
document.getElementByID("test").textContent = output;
For broader support, you could use text in jQuery (or the equivalent method if your library of choice):
$('#test').text(output);
If your code is in the div, then document.write('abcdefg') is the proper choice for inserting something inline at the point of execution.
Or, if your code is not inside the div, you can do this:
<div id="test">
</div>
<script type="text/javascript">
var output = 'abcdefg';
document.getElementById("test").innerHTML = output;
</script>
You will have to make sure that your code runs AFTER the page is loaded and the div is present.
You could write something like:
<div id="test">
<script>
document.getElementById('test').innerHTML = "stuff";
//this line only changes content in the div with id="test", not the whole dom
</script>
</div>
But you should avoid putting a script inside a div because it may be overwritten.
I know this is an old question but if anybody is still looking then here is a handy function that does the job.
function echo(text)
{
document.body.appendChild(document.createElement("div")).appendChild(document.createTextNode(text));
}
console.log()
http://getfirebug.com/logging
also supported in chrome and ie 9.. watch out for backwards compatibly it will get you ie8 and down i think...

Categories

Resources