Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.parseContent() bug fix #103

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bower_components
.DS_Store
node_modules/*
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-markdown",
"version": "2.6.0",
"version": "2.7.0",
"main": ["./js/bootstrap-markdown.js", "./css/bootstrap-markdown.min.css"],
"dependencies": {
"bootstrap": "~3.1.1"
Expand Down
3 changes: 1 addition & 2 deletions css/bootstrap-markdown.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 51 additions & 63 deletions js/bootstrap-markdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ===================================================
* bootstrap-markdown.js v2.6.0
* bootstrap-markdown.js v2.7.0
* http://github.com/toopay/bootstrap-markdown
* ===================================================
* Copyright 2013-2014 Taufan Aditya
Expand Down Expand Up @@ -83,7 +83,7 @@

for (z=0;z<buttons.length;z++) {
var button = buttons[z],
buttonToggle = '',
buttonContainer, buttonIconContainer,
buttonHandler = ns+'-'+button.name,
buttonIcon = this.__getIcon(button.icon),
btnText = button.btnText ? button.btnText : '',
Expand All @@ -92,43 +92,41 @@
hotkey = typeof button.hotkey !== 'undefined' ? button.hotkey : '',
hotkeyCaption = typeof jQuery.hotkeys !== 'undefined' && hotkey !== '' ? ' ('+hotkey+')' : ''

if (button.toggle == true) {
buttonToggle = ' data-toggle="button"'
// Construct the button object
buttonContainer = $('<button></button>');
buttonContainer.text(' ' + this.__localize(btnText)).addClass('btn-default btn-sm').addClass(btnClass);
if(btnClass.match(/btn\-(primary|success|info|warning|danger|link)/)){
buttonContainer.removeClass('btn-default');
}
buttonContainer.attr({
'type': 'button',
'title': this.__localize(button.title) + hotkeyCaption,
'tabindex': tabIndex,
'data-provider': ns,
'data-handler': buttonHandler,
'data-hotkey': hotkey
});
if (button.toggle == true){
buttonContainer.attr('data-toggle', 'button');
}
buttonIconContainer = $('<span/>');
buttonIconContainer.addClass(buttonIcon);
buttonIconContainer.prependTo(buttonContainer);

// Attach the button object
btnGroupContainer.append('<button type="button" class="'
+btnClass
+' btn-default btn-sm" title="'
+this.__localize(button.title)
+hotkeyCaption
+'" tabindex="'
+tabIndex
+'" data-provider="'
+ns
+'" data-handler="'
+buttonHandler
+'" data-hotkey="'
+hotkey
+'"'
+buttonToggle
+'><span class="'
+buttonIcon
+'"></span> '
+this.__localize(btnText)
+'</button>')
btnGroupContainer.append(buttonContainer);

// Register handler and callback
handler.push(buttonHandler)
callback.push(button.callback)
handler.push(buttonHandler);
callback.push(button.callback);
}

// Attach the button group into container dom
container.append(btnGroupContainer)
container.append(btnGroupContainer);
}
}

return container
return container;
}
, __setListener: function() {
// Set size and resizable Properties
Expand Down Expand Up @@ -407,19 +405,13 @@
if (options.fullscreen.enable && options.fullscreen !== false) {
this.$editor.append('\
<div class="md-fullscreen-controls">\
<a href="#" class="switch-theme" title="Switch themes"><span class="'+this.__getIcon(options.fullscreen.icons.switchTheme)+'"></span></a>\
<a href="#" class="exit-fullscreen" title="Exit fullscreen"><span class="'+this.__getIcon(options.fullscreen.icons.fullscreenOff)+'"></span></a>\
</div>')

this.$editor.on('click', '.exit-fullscreen', function(e) {
e.preventDefault()
instance.setFullscreen(false)
})

this.$editor.on('click', '.switch-theme', function(e) {
e.preventDefault()
instance.$editor.toggleClass('theme-dark')
})
}

// hide hidden buttons from options
Expand All @@ -434,23 +426,17 @@
return this
}

, parseContent: function() {
var content,
callbackContent = this.$options.onPreview(this) // Try to get the content from callback
, parseContent: function(val) {
var content

if (typeof callbackContent == 'string') {
// Set the content based by callback content
content = callbackContent
// parse with supported markdown parser
var val = val || this.$textarea.val();
if(typeof markdown == 'object') {
content = markdown.toHTML(val);
}else if(typeof marked == 'function') {
content = marked(val);
} else {
// Set the content
var val = this.$textarea.val();
if(typeof markdown == 'object') {
content = markdown.toHTML(val);
}else if(typeof marked == 'function') {
content = marked(val);
} else {
content = val;
}
content = val;
}

return content;
Expand All @@ -461,14 +447,17 @@
container = this.$textarea,
afterContainer = container.next(),
replacementContainer = $('<div/>',{'class':'md-preview','data-provider':'markdown-preview'}),
content
content,
callbackContent

// Give flag that tell the editor enter preview mode
this.$isPreview = true
// Disable all buttons
this.disableButtons('all').enableButtons('cmdPreview')

content = this.parseContent()
callbackContent = options.onPreview(this) // Try to get the content from callback
// Set the content based from the callback content if string otherwise parse value from textarea
content = typeof callbackContent == 'string' ? callbackContent : this.parseContent();

// Build preview element
replacementContainer.html(content)
Expand Down Expand Up @@ -946,13 +935,13 @@
}

// transform selection and set the cursor into chunked text
if (content.substr(selected.start-1,1) == '*'
&& content.substr(selected.end,1) == '*' ) {
if (content.substr(selected.start-1,1) == '_'
&& content.substr(selected.end,1) == '_' ) {
e.setSelection(selected.start-1,selected.end+1)
e.replaceSelection(chunk)
cursor = selected.start-1
} else {
e.replaceSelection('*'+chunk+'*')
e.replaceSelection('_'+chunk+'_')
cursor = selected.start+1
}

Expand Down Expand Up @@ -1014,9 +1003,11 @@

link = prompt(e.__localize('Insert Hyperlink'),'http://')

if (link != null && link != '' && link != 'http://') {
if (link != null && link != '' && link != 'http://' && link.substr(0,4) == 'http') {
var sanitizedLink = $('<div>'+link+'</div>').text()

// transform selection and set the cursor into chunked text
e.replaceSelection('['+chunk+']('+link+')')
e.replaceSelection('['+chunk+']('+sanitizedLink+')')
cursor = selected.start+1

// Set the cursor
Expand All @@ -1041,9 +1032,11 @@

link = prompt(e.__localize('Insert Image Hyperlink'),'http://')

if (link != null) {
if (link != null && link != '' && link != 'http://' && link.substr(0,4) == 'http') {
var sanitizedLink = $('<div>'+link+'</div>').text()

// transform selection and set the cursor into chunked text
e.replaceSelection('!['+chunk+']('+link+' "'+e.__localize('enter image title here')+'")')
e.replaceSelection('!['+chunk+']('+sanitizedLink+' "'+e.__localize('enter image title here')+'")')
cursor = selected.start+2

// Set the next tab
Expand Down Expand Up @@ -1269,11 +1262,6 @@
fa: 'fa fa-compress',
glyph: 'glyphicon glyphicon-fullscreen',
'fa-3': 'icon-resize-small'
},
switchTheme: {
fa: 'fa fa-adjust',
glyph: 'glyphicon glyphicon-adjust',
'fa-3': 'icon-adjust'
}
}
},
Expand Down
32 changes: 0 additions & 32 deletions less/bootstrap-markdown.less
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,6 @@
background: #fff !important;
border: 0 !important;

&.theme-dark {
background: #1d1f21 !important;

.md-fullscreen-controls a {
color: #a4b1b1;
&:hover {
color: #dbe0e0;
text-shadow: 0 0 10px #000;
}
}

.md-preview,
.md-input,
.md-input:hover,
.md-input:active,
.md-input:focus {
color: #dbe0e0;
background: #1d1f21 !important;

}

.btn {
&:hover,
&:focus,
&.active,
&:active {
color: #dbe0e0;
text-shadow: 0 0 10px #000;
}
}
}

.md-footer {
display: none;
}
Expand Down
31 changes: 31 additions & 0 deletions locale/bootstrap-markdown.tr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Turkish translation for bootstrap-markdown
* Serkan Algur <[email protected]>
*/
(function ($) {
$.fn.markdown.messages.tr = {
'Bold': "Kalın",
'Italic': "İtalik",
'Heading': "Başlık",
'URL/Link': "Link ekle",
'Image': "Resim ekle",
'List': "Liste Oluşturun",
'Preview': "Önizleme",
'strong text': "kalın yazı",
'emphasized text': "italik yazı",
'heading text': "Başlık Yazısı",
'enter link description here': "Link açıklamasını buraya girin",
'Insert Hyperlink': "İnternet adresi girin",
'enter image description here': "resim açıklamasını buraya ekleyin",
'Insert Image Hyperlink': "Resim linkini ekleyin",
'enter image title here': "resim başlığını buraya ekleyin",
'list text here': "liste yazısı",
'Save' : "Kaydet",
'Ordered List' : "Numaralı Liste",
'Unordered List' : "Madde imli liste",
'Quote' : "Alıntı",
'quote here' : "alıntıyı buraya ekleyin",
'Code' : "Kod",
'code text here' : "kodu buraya ekleyin"
};
}(jQuery));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bootstrap-markdown",
"filename": "js/bootstrap-markdown.js",
"version": "2.6.0",
"version": "2.7.0",
"description": "A bootstrap plugin for markdown editing",
"homepage": "https://github.com/toopay/bootstrap-markdown",
"keywords": [
Expand Down