If I have a google doc with styling (bold, underline, etc), is there a way to parse the formatting with Javascript? I am trying to make an extremely simple WYSWIG -> HTML formatter, and easily was able to substitute whitespace with HTML, but am having a harder time with formatting.
TL/DR: If I copy and paste from a Google Doc to a textarea, can I use Javascript to see what the formatting was?
Instead of using a textbox, which will remove all formatting, you can use HTML5's contenteditable property.
<div id="editable" contenteditable="true">
edit me
</div>
If you paste something into that box, it will preserve formatting. Now you can use jQuery's .html() to get the HTML of the container.
$("#editable").html()
Demo
Related
How to make a word underline in Markdown?
For example: bold = **bold** or __bold__, italic = *Italic* or _Italic_.
I have tried with 2 and 3 underscores, but it is not working. Also tried by taking the reference of markdown-it.js.
In Jupyter notebook, you can use the following to get underscored text
<u>underscored text </u>
since markdown is a markup language and In fact you can use HTML/CSS inside it, the easiest way I've found so far is:
text here <span style="text-decoration: underline">underlined text</span> other text
Note: you can still use markdown syntax inside the <span> tag.
you can just use HTML markups in mark down.
if you want to underline, italic or strong, use follows,
<u> this is underlined </u>
<i> this is italic </i>
<strong> this is strong </strong>
etc..
Using a plugin (markdown-it-ins)
You can use ++Underlined Text++ to make text underlined in markdown-it.js. Bear in mind that this is not standard markdown and might not work elsewhere. Here's a demonstration of this working in the markdown-it website.
This syntactic extension (inserted text) is added by a plugincalled markdown-it-ins. It's enabled by default in the demo page, but you might need to install and enable it manually for your own page.
Using HTML tags inside markdown
If you want this to work for any markdown parser, you should try using the <u> HTML tag, as most parsers will actually parse HTML inside markdown (this might cause a few unwanted side-effects). markdown-it supports it, if you enable the related option. Here's an example of this in action.
Just to complement on the answers, if you happen to be using Atom for the markdown, ++this++ won't work (unless perhaps if you install any package for that), but <u>this</u> will.
I have:
output:
pdf_document:
latex_engine: xelatex
keep_tex: true
in-line, outside of chunk:
\underline{Text to Underline}
and it works just fine!
I was actually looking for a workaround and though the use of a <u> HTML tag can be regularly interpreted by a Markdown parser, I changed my point of view and understood that I could do without it.
After all, Markdown is all about simplifying the documentation and levelling it out so that every document could be equally read.
i.e. if I want to use Markdown I'll stick to its principles.
By the way, this answer has been formatted with the help of Markdown itself ;-)
I'm trying to have a textarea input field just like when you post a new StackOverflow question. You can have line spaces, you can bold text, you can insert link etc.
However, when you push some kind of button, all of that gets translated into a long HTML string (e.g., spaces become <p> or <br>, bold becomes <strong>, link becomes <a>). Is there a way to do this with some kind of JS plug in?
What you describe is a What You See Is What You Get (WYSIWYG) editor.
Google "WYSIWYG editor library"
Examples:
https://prosemirror.net/
https://www.tinymce.com/
This question has been answered here Rendering HTML inside textarea
What you need is WYSIWYG (What you see is what you get) editor.
There are a lot of them.
You can check out these:
Ckeditor The best web editor for everyone
TinyMCE Full featured web editing
They are very easy to use.
If I have understood what you are asking, you will need to learn regular expressions. Everything is the context is based on text replacement.
Example: because textarea does not display hyperlinks, buttons, i can do somethings like in stackoverflow.
For hyperlink, i can write something link [# http://facebook.com] or [link]http://facebook.com [link];
later, I extract the http://facebook.com and wrap it between <a></a> elements.
What everybody above said is true, you want to be looking at a WISYWG editor.
If by chance you are using Bootstrap, you may want to look at Summernote.
I have no affiliation with them, but I used it for one of my projects and was very pleased.
I am building an app where I would like users to be able to review an existing string in a <p></p> element, mouseover on the text to edit it, and see the edited version when they mouseout.
Right now I am doing that in Javascript replacing the <p> with <textarea>. I populate the <textarea> by setting its innerHTML to that of the <p> element. That works fine except that the text appear as HTML rather than as formatted text.
So for example a user might have entered something like:
"An old silent pond...
A frog jumps into the pond,
splash! Silence again."
Then when the time comes to edit the text, it would appear as:
"An old silent pond...<br>A frog jumps into the pond,<br>splash! Silence again."
Is there a way to make sure that what is displayed for editing is interpreted HTML / formatted text rather than raw HTML? I do need the formatting to be interpreted - I don't want to just strip out the HTML tags.
PS: I assume that textarea is the right way to create a window to edit some text, but I'm not married to it.
It sounds like you want to be able to edit the text while seeing and retaining the formatting? This is not something that can be done in a plain <textarea> -- you may want to look at wysiwyg editors such as TinyMCE or CKEditor
Another possibility is the HTML5 contenteditable attribute, and a javascript polyfill to support pre-HTML5 browsers.
See Storing the Changes for a basic suggestion for saving the changes made in a contenteditable section, or search the web for save contenteditable changes for many articles on the subject.
Also, Using the HTML5 attribute "contenteditable" to create a WYSIWYG walks through building up a simplistic editor (Now with Plain Ugly Buttons!)
If available, set textContent instead of innerHTML.
textarea.textContent = p.innerHTML;
If you need to support IE8, use innerText if textContent is not there.
http://jsfiddle.net/yUMtj/
EDIT: As #RobG indicates, use .value instead of .textContent for even better compatibility.
The content of a textarea element isn't parsed as HTML. There are a number of HTML based editors available, Google is your friend.
A textarea element's content is its value. The HTML specification does not define innerHTML, textContent or innerText properties for textarea elements so you should use the value property to access the value.
Can I get an explanation on how to make a wysiwyg editor using a textarea? All I need it to be able to do is parse basic html tags like bold, italics, underline, etc. It doesn't need to have any buttons that inserts it, I just want to have a default text inside the textarea tags that parse the html.
Example:
<textarea cols="20" rows="20" name="ok">
<b>wat</b>
</textarea>
This will print out <b>wat</b> instead of wat inside the textarea.
Edit: jQuery is preferred
Look into the contenteditable attribute. It's supported in many modern browsers. Just add it to an element and edit away...
document.getElementById('something').contentEditable = true;
Of course it doesn't work on textareas. You'd need to swap the textarea out with a div and make that editable. You'd also need to make sure the textarea has the contents (e.g. innerHTML) of the div as its value when the form is submitted.
A textarea cannot parse HTML -- period. (Anyone can feel free to correct me on this)
The WYSIWYG editors that you see are not in a textarea, at least not in the same way. I suggest using a prebuilt editor such as TinyMCE or FCK Editor.
A textarea will not parse HTML, but by using a WYSIWYG plugin, an editor will replace the textarea and give the user the ability to view and modify the content. With some editors, such as TinyMCE, you are able to set it to Simple mode, and allow only the basics of formatting (bold, italic, underline, bullets, etc) like you are interested in. This helps keeps the editor from being cluttered with unnecessary tools.
I suggest checking out TinyMCE or CKEditor
Is there any JS function that can change the color of certain text in a textarea?
For example, blar blar {blar} blar, {blar}, including { }, will be in blue. Other words will be in blank. In other words, all I need is a function that can change color of all text in { }.
I've done some studies and it seems that most people say it can't be done. But I'm seeing rich text editors or those wysiwyg editors having the ability to bold or underline words. There must be a way to do it.
Any suggestion is welcome.
No one mentioned contentEditable?
Just make a contentEditable div and use javascript to style it.
I reccommend you to look into the Dojo Toolkit's.
It has a Editor widget.
Other resources:
Some contentEditable problems in IE.
How to use contentEditable with jQuery or without it.
wysiwig-editors are using iframes instead of textareas. Textareas are very little customizable, since what you're after is changing part of the content. You can't add tags inside a textarea, which makes it impossible to only change part of the text.
If you look at the editor here in SO, you write normal text inside a textarea, and it is then transformed in the box below it, so you'll see the asterix inside the textbox, but in the box below, it'll transform special characters by regexing them with tags.
If you're using firebug, you can start writing inside the editor, while looking at the HTML in the preview-box.
you can't use a textarea to do that, per se.
But, javascript is your friend. Perhaps you should take a look at the code of a few rich text editors.
You could start with lwrte, since it says its "lightweight". Also, its written in jquery so it will be pretty easy to undertand. (and I'm a jquery fanboy).
Hope that helps,
jrh
I Think You will need to use execCommand method of javascript it controls many thing such this stuff of changing specifc textcolor
Regards
But some Jquery WYSIWYG editors do this ! How is that possible ? See this editor lwrte