How to get markitup editor, using markdown set, to send markdown instead of html - ruby-on-rails

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.

Related

ruby on rails: text filed formatting

I tried to copy and past from Word document to text field using Ruby on Rails.
But all formatting( spaces, bold and other) are disappeared on text filed.
I've just got the simple lines of text without any formatting.
I've read that need to use Simple format tool... but I want that a user be able just to copy and past a text to text field without doing any adjustments.
I mean, I want make all adjustment in advance and the user could just copy and past the text and got all formatting, the same as in Word doc.
The link to file with text field as below.
https://gist.github.com/tatyana12/2f9d39c2f6e4f8fabea5e70e11eaf310
Also I have Application.html.erb file:
https://gist.github.com/tatyana12/15c27d542091b04f3c3adfdfd252b7f4
How to initialize editor if I don't have id = "edit" right now?
How to put some code extra style to this file?
Have a go at wrapping your field in your show.html.erb or wherever you want to display it with simple_format, for example:
<%= simple_format(#object.description) %>
See http://apidock.com/rails/ActionView/Helpers/TextHelper/simple_format for more info.
I've solved this problem by implementing SKEditor.
There is a lot of tutorial how to implement this editor.
I (as a lot of other users) have problem that my text wasn't formatted because this editor is not compatible with turbo links.
So, I disable turbo links in some files, and as result I have the text formatted.

Generate Text (.txt) file for Data displayed in GSP

I have a Grails app developed in 2.3.6
There's a GSP file with HTML and CSS elements in it, and that displays data in multiple tables with headers.
I want this data to be saved into a text file and save it. So basically what i want to do is, there will be a Export button in this GSP page, and when user clicks on it, it will download the text file with all the data from that GSP.
What i tried so far?
def textFile = {
response.setHeader('Content-Disposition', 'Attachment;Filename="textFile.txt"')
render view: 'textFile', contentType: 'text/plain'
}
The problem with above is, it saves not just data, but also HTML & CSS elements.
I don't want any HTML or CSS in the text file. Only data from GSP is needed.
Is there a simple way of doing it.
the answer is simple - you need another view withouth the html and css parts.
The rest of your code looks good. But Grails itself does not convert your view, it just sends the content type to the browser and the browser tries to diesplay the data according to the content type.
If you don't want to write a new view (in most cases, writing the new view is dead simple), you could write your own converter (something which strips the HTML and CSS from your file) by creating an afterView-Filter: http://grails.github.io/grails-doc/2.4.0/guide/single.html#filters
Hope that helps

render html in a rich text box in active reports software

I have a string with basic html markup which I want to put into a rich textbox
string ab = #"<b> a b </b>"
I want it to render as it would appear in a browser ie:
a b
how can I do this in active reports 7? According to http://www.datadynamics.com/forums/77664/ShowPost.aspx, a richtextbox supports these tags. Do I have to specify a property to allow it to render html? How should I approach this?
Thanks,
Sam
More information (Update 8/11):
I'm binding the data from a database field - an oracle nclob. The field repeats within the detail section (with different information each time).
If I bind the field directly to a textbox or label it renders the string, but doesnt encode the html
<b> a b </b>
but it encode the string.
Solution Summary
Solution (as suggested by #activescott)
Bind rtx directly to the datafield
'Reformat' the text into html in
the script
public void detail_Format()
{
rtxBox.Html = rtxBox.Text;
}
result: renders the html field with some degree of html formatting
notes:
binding directly in the script doesnt work,
ie. rtxBox.Html = pt.Fields["CONT_ID"].ToString(); yields some wierd meta data string
the Datafield only binding approach doesn't work
(it will yield it as text)
there are some extra spacing that occurs with p tags. It may be worth regexing them out or somehow providing some formatting control.
The actual property you are looking for is the Html Property. You can also load a file into that control using the step-by-step walkthrough here.
I am assuming you are using Section Reports and not Page Reports.
To use HTML from the database in a bound report, you should be able to use the DataField property of the RichTextBox control (set it to the name of the corresponding Data field at design time). However, I noticed this "Render HTML tags in DB in ActiveReport pdf or HTML" article which kind of implies that doesn't work since it loads the HTML from a database programatically. One of the two should work.

How do I exclude tags from being parsed in TinyMCE WYSIWYG?

I am using TinyMCE WYSIWYG editor to create posts in my custom forum. I am using the bbCode plugin. I want to add a quote post feature. I need to add [quote id=123]Some Original Message[/quote] to the editor without it being parsed.
I tried putting that string inside the textarea tags, but it just shows up as "Some Original Message".

multi line tag in grails or html

With a grails app and from a local database, I'm returning some text in a xml format.
I can return it well formed in a <textarea></textarea> tag with the correct indenting (tabulation, line return,...etc.)
I want to go a bit further. In the text I'm returning, there are some <img/> tags and I'd like to replace those tag by the real images themselves.
I searched around and found no solution as of now. I understood that you can't add an image to a textarea (other then in a background), and if I choose a div tag, I won't have the indenting anymore (and therefore, harder to read)
I was wondering if using a <g:textField/> or an other tag from the grails library will do the trick. And if so, How can I append them to a page using jquery.
For example, how to append a <g:textField/> in jquery. It doesn't interpret it and I get this error
SyntaxError: missing ) after argument list [Break On This Error]...+doc).append("<input type="text" id="FTMAP_"+nb_sec+"" ...
And in my javascript file, I have
$("#FTM_"+doc).append("<g:textField id='FTMAP_"+nb_sec+"' ... />
Any possible solutions ?
EDIT
I did forget to mention that my final intentions are to be able to modify the text (tags included) and to have a nice and neat indentation so that it is the easiest possible for the end user.
You are asking a few different questions:
1. Can I use a single HTML tag to include images inside pre-formatted text.
No. You will have to parse the text and translate it into styled text yourself.
2. Is there a tag in the grails standard tags to accomplish this for me?
No.
3. How can I add grails tags from my javascript code.
Grails tags are processed on the server-side, and javascript is processed on the client. This means you cannot directly add grails tags via javascript.
There are a couple methods that can accomplish the same result, however:
You can set a javascript variable to the rendered content of a grails tag. This solution is good for data that is known at the time of the initial request.
var tagOutput = "${g.textField(/* etc */)}";
You can make an ajax request for the content to be added. Then your server-side grails code can render the tags you need. This is better for realtime data, or data that will be updated more than once on a single rendered page.

Resources