When I use Openlayers 3 I get data from PostGIS database and form it to GeoJSON and pass it on a vector layer.
So then I can do event.selected[0].get('description') to get the text that describes the selected feature and put it in a div.
I want to ask, if I save formatted HTML in the database like <b>Title</b><br>blah blah <br><li>.....</li> and use it to make GeoJSON, when I put it to a div will it appear as formatted or as text with the tags?
Will appear like
Title
blah blah
List 1
List 2
or like
<b>Title</b><br>blah blah <br><ul><li>List 1</li><li>List 2</li></ul> ?
Thanks
If you div.innerHTML = event.selected[0].get('description'); then description will be rendered as HTML.
Related
I have data written in QuillJS Editor, when I store that data it stores the data along with the HTML tags in my database.
For Example if I right this in the editor
This is an example.
It is stored as
<p>This is an example.</p>
Now when I'm trying to display these data in my Angular front-end HTML file it shows the HTML tags along with the data enclosed between them.
<p>This is an example.</p>
How will I only show the text enclosed in the tags and not the HTML tags?
To Display data in HTML that was entered by a user using QuillJs, you have to use QuillJs editor in read mode to display that data.
<quill-editor [(ngModel)]="yourNgModel" [readOnly]="isReadOnly" [modules]="{toolbar: false}">
</quill-editor>
I have used MarkiItUp to build a jquery editor. Now when user type content in textarea with html code, like this:
A new <strong>true</strong> question
When record was saved, it save A new <strong>true</strong> question. And when it display on page, it also display like content was saved, is A new <strong>true</strong> question . But i want the content display on web like this:
A new true question
How can i do that?
To display it, use html_safe. This way your string would be rendered as HTML.
Refer to this question for more info.
Ruby on Rails: how to render a string as HTML?
I'm using rails and have a markItUp editor in place, using the Markdown custom set. The only thing I can't figure out is how to get it to submit raw Markdown instead of converted html. I plan on storing both formats, but I haven't found anything capable of parsing html back to markdown. I've customized the markdown set set.js as we didn't want the entire set of formatting options. Here:
myMarkdownSettings = {
previewParserPath: '',
onShiftEnter: {keepDefault:false, openWith:'\n\n'},
markupSet: [
{name:'Bold', key:'B', openWith:'**', closeWith:'**'},
{name:'Italic', key:'I', openWith:'_', closeWith:'_'},
{name:'Bulleted List', openWith:'- ' },
{name:'Link', key:'L', openWith:'[', closeWith:']([![Url:!:http://]!] "[![Title]!]")', placeHolder:'Your text to link here...' }
]
}
And here's the onready code for the page where the markitup elements appear:
$.editable.addInputType('markitup', {
element : $.editable.types.textarea.element,
plugin : function(myMarkdownSettings, original) {
$('textarea', this).markItUp(myMarkdownSettings);
}
});
$('.editable').editable({type : 'markitup'});
This works, but it submits as html. I was trying to use wmd as there's an option for output which maintains the markdown text as is, but haven't been able to get that to fly. Thanks.
Assuming the textarea contains markdown formatted text, you should be able to grab the contents before form submit with $('.editable').text(), and store it in another hidden field, but you'd have to ensure that you get to the contents before markitup transforms them.
If you really just want to store markdown, you'd be better not to use markitup, and just leave it as simple markdown in a text view, then translate it yourself to html for display with one of the libraries available like rdiscount etc.
I have with RedCloth saved plain text in a form and converted it to HTML. For example, writing this in my form, and saving it, would make it display the exact same way I wrote it :
This sentence
gets inserted into it
proper html syntax
to preserve line breakage.
With this code :
def parse_code
self.text = RedCloth.new(text).to_html
end
And then I can redisplay it with this :
= raw post.text
But when I want to edit it, it it returns to me as :
<p>This sentence</p>
<p>gets inserted into it</p>
<p>proper html syntax</p>
<p>to preserve line breakage</p>
How can I make it, so that when I edit it, it looks the same way it did before I went and saved it ?
Thanks!
I would leave the textile code stored in textile and do the conversion to HTML only in the view:
= raw RedCloth.new(#post.text).to_html
Converting between textile and HTML does not feel to be a good practice. Your parse_code method seem that it caused your text to be converted to HTML.. and than stored to the Db.
However if you want to convert HTML to textile, maybe clothred is for you or read this blog.
Edit: Shoot! I misunderstood the question!
You'd assign that text area's value back to textile using ClothRed:
ClothRed.new(html).to_textile
Sorry!
If I understood you right, you are storing the HTML output in the database. Instead of doing that, store the raw Textile contents and then convert them to HTML when showing it to the user.
i have text like this
div bla-bla end div
i need to get only 'bla-bla' without div, because of i need to call substring in controller only to text bla-bla not to div tags. is it possible
p.s. how to input tags here?
If you have jquery you can access inner html by calling ( for example ):
$("#idofthediv").html()
to set the conntent of the div:
$("#idofthediv").html('some html')
document.findElementById(..).innerText;
Take a look at using a Regular Expression.
There is a sample of what you want to do at Regular Expression Examples. It's the first sample in the section titled "Grabbing HTML Tags" near the top of the page.