// -------------------------------------------------------------------
// markItUp!
// -------------------------------------------------------------------
// Copyright (C) 2008 Jay Salvat
// http://markitup.jaysalvat.com/
// -------------------------------------------------------------------
// MarkDown tags example
// http://en.wikipedia.org/wiki/Markdown
// http://daringfireball.net/projects/markdown/
// -------------------------------------------------------------------
// Feel free to add more tags
// -------------------------------------------------------------------
mySettings = {
	previewParserPath:	'',
	onShiftEnter:		{keepDefault:false, openWith:'\n\n'},
	onTab: { keepDefault: false, openWith: '\t' },
	markupSet: [
		{name:'Premier niveau de titre', key:'1', placeHolder:'Votre titre ici...', closeWith:function(markItUp) { return miu.markdownTitle(markItUp, '='); } },
		{name:'Second niveau de titre', key:'2', placeHolder:'Votre titre ici...', closeWith:function(markItUp) { return miu.markdownTitle(markItUp, '-'); } },
		{name:'Titre 3', key:'3', openWith:'### ', placeHolder:'Votre titre ici...' },
		{name:'Titre 4', key:'4', openWith:'#### ', placeHolder:'Votre titre ici...' },
		{name:'Titre 5', key:'5', openWith:'##### ', placeHolder:'Votre titre ici...' },
		{name:'Titre 6', key:'6', openWith:'###### ', placeHolder:'Votre titre ici...' },
		{separator:'---------------' },		
		{name:'Gras', key:'B', openWith:'**', closeWith: '**', replaceWith: function(markItUp) { return miu.trim(markItUp, '**'); }},
		{name:'Italique', key:'I', openWith:'_', closeWith: '_', replaceWith: function(markItUp) { return miu.trim(markItUp, '_'); }},
		{separator:'---------------' },
		{name:'Liste à puce', openWith:'- ' },
		{name:'Liste numérique', openWith:function(markItUp) {
			return markItUp.line+'. ';
		}},
		{separator:'---------------' },
		{name:'Image', key:'P', replaceWith:'![[![Texte alternatif]!]]([![Url:!:http://]!])'},
		{name:'Lien', key:'L', openWith:'[', closeWith:']([![Url:!:http://]!])', placeHolder:'Le texte de votre lien ici...' },
		{separator:'---------------'},	
		{name:'Quotes', openWith:'\n> ', closeWith: '\n' },
		{name:'Code Block / Code', openWith:'(!(\t|!|`)!)', closeWith:'(!(`)!)'}
	]
}

// mIu nameSpace to avoid conflict.
miu = {
	markdownTitle: function(markItUp, char) {
		heading = '';
		var n = $.trim(markItUp.selection||markItUp.placeHolder).length;
		for(i = 0; i < n; i++) {
			heading += char;
		}
		return '\n'+heading;
	},
	trim: function(markItUp, char) {
		var stringTrim = $.trim(markItUp.selection);

		if (stringTrim.length != markItUp.selection.length){
			markItUp.closeWith = '_ ';			
		}
		
		return stringTrim; 
	}
}