You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

markdown.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /**
  2. * This file is part of DotClear.
  3. * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All rights reserved.
  4. * This code is released under the GNU General Public License.
  5. *
  6. * Modified by JP LANG for markdown formatting
  7. */
  8. // strong
  9. jsToolBar.prototype.elements.strong = {
  10. type: 'button',
  11. title: 'Strong',
  12. shortcut: 'b',
  13. fn: {
  14. wiki: function() { this.singleTag('**') }
  15. }
  16. }
  17. // em
  18. jsToolBar.prototype.elements.em = {
  19. type: 'button',
  20. title: 'Italic',
  21. shortcut: 'i',
  22. fn: {
  23. wiki: function() { this.singleTag("*") }
  24. }
  25. }
  26. // ins
  27. jsToolBar.prototype.elements.ins = {
  28. type: 'button',
  29. title: 'Underline',
  30. shortcut: 'u',
  31. fn: {
  32. wiki: function() { this.singleTag('_') }
  33. }
  34. }
  35. // del
  36. jsToolBar.prototype.elements.del = {
  37. type: 'button',
  38. title: 'Deleted',
  39. fn: {
  40. wiki: function() { this.singleTag('~~') }
  41. }
  42. }
  43. // code
  44. jsToolBar.prototype.elements.code = {
  45. type: 'button',
  46. title: 'Code',
  47. fn: {
  48. wiki: function() { this.singleTag('`') }
  49. }
  50. }
  51. // spacer
  52. jsToolBar.prototype.elements.space1 = {type: 'space'}
  53. // headings
  54. jsToolBar.prototype.elements.h1 = {
  55. type: 'button',
  56. title: 'Heading 1',
  57. fn: {
  58. wiki: function() {
  59. this.encloseLineSelection('# ', '',function(str) {
  60. str = str.replace(/^#+\s+/, '')
  61. return str;
  62. });
  63. }
  64. }
  65. }
  66. jsToolBar.prototype.elements.h2 = {
  67. type: 'button',
  68. title: 'Heading 2',
  69. fn: {
  70. wiki: function() {
  71. this.encloseLineSelection('## ', '',function(str) {
  72. str = str.replace(/^#+\s+/, '')
  73. return str;
  74. });
  75. }
  76. }
  77. }
  78. jsToolBar.prototype.elements.h3 = {
  79. type: 'button',
  80. title: 'Heading 3',
  81. fn: {
  82. wiki: function() {
  83. this.encloseLineSelection('### ', '',function(str) {
  84. str = str.replace(/^#+\s+/, '')
  85. return str;
  86. });
  87. }
  88. }
  89. }
  90. // spacer
  91. jsToolBar.prototype.elements.space2 = {type: 'space'}
  92. // ul
  93. jsToolBar.prototype.elements.ul = {
  94. type: 'button',
  95. title: 'Unordered list',
  96. fn: {
  97. wiki: function() {
  98. this.encloseLineSelection('','',function(str) {
  99. str = str.replace(/\r/g,'');
  100. return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
  101. });
  102. }
  103. }
  104. }
  105. // ol
  106. jsToolBar.prototype.elements.ol = {
  107. type: 'button',
  108. title: 'Ordered list',
  109. fn: {
  110. wiki: function() {
  111. this.encloseLineSelection('','',function(str) {
  112. str = str.replace(/\r/g,'');
  113. return str.replace(/(\n|^)[*-]?\s*/g,"$11. ");
  114. });
  115. }
  116. }
  117. }
  118. // spacer
  119. jsToolBar.prototype.elements.space3 = {type: 'space'}
  120. // bq
  121. jsToolBar.prototype.elements.bq = {
  122. type: 'button',
  123. title: 'Quote',
  124. fn: {
  125. wiki: function() {
  126. this.encloseLineSelection('','',function(str) {
  127. str = str.replace(/\r/g,'');
  128. return str.replace(/(\n|^)( *)([^\n]*)/g,"$1> $2$3");
  129. });
  130. }
  131. }
  132. }
  133. // unbq
  134. jsToolBar.prototype.elements.unbq = {
  135. type: 'button',
  136. title: 'Unquote',
  137. fn: {
  138. wiki: function() {
  139. this.encloseLineSelection('','',function(str) {
  140. str = str.replace(/\r/g,'');
  141. return str.replace(/(\n|^) *(> ?)?( *)([^\n]*)/g,"$1$3$4");
  142. });
  143. }
  144. }
  145. }
  146. // table
  147. jsToolBar.prototype.elements.table = {
  148. type: 'button',
  149. title: 'Table',
  150. fn: {
  151. wiki: function() {
  152. var This = this;
  153. this.tableMenu(function(cols, rowCount){
  154. This.encloseLineSelection(
  155. '|'+cols.join(' |')+' |\n' + // header
  156. Array(cols.length+1).join('|--')+'|\n' + // second line
  157. Array(rowCount+1).join(Array(cols.length+1).join('| ')+'|\n') // cells
  158. );
  159. });
  160. }
  161. }
  162. }
  163. // pre
  164. jsToolBar.prototype.elements.pre = {
  165. type: 'button',
  166. title: 'Preformatted text',
  167. fn: {
  168. wiki: function() { this.encloseLineSelection('```\n', '\n```') }
  169. }
  170. }
  171. // Code highlighting
  172. jsToolBar.prototype.elements.precode = {
  173. type: 'button',
  174. title: 'Highlighted code',
  175. fn: {
  176. wiki: function() {
  177. var This = this;
  178. this.precodeMenu(function(lang){
  179. This.encloseLineSelection('``` ' + lang + '\n', '\n```\n');
  180. });
  181. }
  182. }
  183. }
  184. // spacer
  185. jsToolBar.prototype.elements.space4 = {type: 'space'}
  186. // wiki page
  187. jsToolBar.prototype.elements.link = {
  188. type: 'button',
  189. title: 'Wiki link',
  190. fn: {
  191. wiki: function() { this.encloseSelection("[[", "]]") }
  192. }
  193. }
  194. // image
  195. jsToolBar.prototype.elements.img = {
  196. type: 'button',
  197. title: 'Image',
  198. fn: {
  199. wiki: function() { this.encloseSelection("![](", ")") }
  200. }
  201. }
  202. // spacer
  203. jsToolBar.prototype.elements.space5 = {type: 'space'}
  204. // help
  205. jsToolBar.prototype.elements.help = {
  206. type: 'button',
  207. title: 'Help',
  208. fn: {
  209. wiki: function() { window.open(this.help_link, '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes') }
  210. }
  211. }