formats.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. /**
  6. * Default formats.
  7. */
  8. var Formats = {
  9. /**
  10. * Bold text.
  11. *
  12. * @example
  13. * editor.format('bold');
  14. * assert(textarea.value == '**Hello World**')
  15. */
  16. bold: {
  17. prefix: '**',
  18. suffix: '**'
  19. },
  20. /**
  21. * Italic text.
  22. *
  23. * @example
  24. * editor.format('italic');
  25. * assert(textarea.value == '_Hello World_')
  26. */
  27. italic: {
  28. prefix: '_',
  29. suffix: '_'
  30. },
  31. /**
  32. * Strikethrough text.
  33. *
  34. * @example
  35. * editor.format('strikethrough');
  36. * assert(textarea.value == '~~Hello World~~')
  37. */
  38. strikethrough: {
  39. prefix: '~~',
  40. suffix: '~~'
  41. },
  42. /**
  43. * Insert link.
  44. *
  45. * @example
  46. * editor.format('link', '/example');
  47. * assert(textarea.value == '[Hello World](/example)')
  48. */
  49. link: {
  50. prefix: {
  51. value: '[',
  52. pattern: '\\[',
  53. antipattern: '\\!\\['
  54. },
  55. suffix: {
  56. value: function value(text, n, url) {
  57. return '](' + url + ')';
  58. },
  59. pattern: '\\]\\([^()]*?\\)'
  60. }
  61. },
  62. /**
  63. * Insert image.
  64. *
  65. * @example
  66. * editor.format('image', '/example.png');
  67. * assert(textarea.value == '![Hello World](/example.png)')
  68. */
  69. image: {
  70. prefix: '![',
  71. suffix: {
  72. value: function value(text, n, url) {
  73. return '](' + url + ')';
  74. },
  75. pattern: '\\]\\([^()]*?\\)'
  76. }
  77. },
  78. /**
  79. * Header 1.
  80. *
  81. * @example
  82. * editor.format('header1');
  83. * assert(textarea.value == '# Hello World')
  84. */
  85. header1: {
  86. prefix: {
  87. value: '# ',
  88. pattern: '# ',
  89. antipattern: '[#]{2,} '
  90. }
  91. },
  92. /**
  93. * Header 2.
  94. *
  95. * @example
  96. * editor.format('header2');
  97. * assert(textarea.value == '## Hello World')
  98. */
  99. header2: {
  100. prefix: {
  101. value: '## ',
  102. pattern: '## ',
  103. antipattern: '[#]{3,} '
  104. }
  105. },
  106. /**
  107. * Header 3.
  108. *
  109. * @example
  110. * editor.format('header3');
  111. * assert(textarea.value == '### Hello World')
  112. */
  113. header3: {
  114. prefix: {
  115. value: '### ',
  116. pattern: '### ',
  117. antipattern: '[#]{4,} '
  118. }
  119. },
  120. /**
  121. * Header 4.
  122. *
  123. * @example
  124. * editor.format('header4');
  125. * assert(textarea.value == '#### Hello World')
  126. */
  127. header4: {
  128. prefix: {
  129. value: '#### ',
  130. pattern: '#### ',
  131. antipattern: '[#]{5,} '
  132. }
  133. },
  134. /**
  135. * Header 5.
  136. *
  137. * @example
  138. * editor.format('header5');
  139. * assert(textarea.value == '##### Hello World')
  140. */
  141. header5: {
  142. prefix: {
  143. value: '##### ',
  144. pattern: '##### ',
  145. antipattern: '[#]{6,} '
  146. }
  147. },
  148. /**
  149. * Header 6.
  150. *
  151. * @example
  152. * editor.format('header6');
  153. * assert(textarea.value == '###### Hello World')
  154. */
  155. header6: {
  156. prefix: {
  157. value: '###### ',
  158. pattern: '###### ',
  159. antipattern: '[#]{7,} '
  160. }
  161. },
  162. /**
  163. * Insert code block.
  164. *
  165. * @example
  166. * editor.format('code');
  167. * assert(textarea.value == '```\nHello World\n```')
  168. */
  169. code: {
  170. block: true,
  171. prefix: '```\n',
  172. suffix: '\n```'
  173. },
  174. /**
  175. * Ordered list.
  176. *
  177. * @example
  178. * editor.format('orderedList');
  179. * assert(textarea.value == '1. Hello World')
  180. */
  181. orderedList: {
  182. block: true,
  183. multiline: true,
  184. prefix: {
  185. value: function value(line, n) {
  186. return n + '. ';
  187. },
  188. pattern: '[0-9]+\\. '
  189. }
  190. },
  191. /**
  192. * Unordered list.
  193. *
  194. * @example
  195. * editor.format('unorderedList');
  196. * assert(textarea.value == '- Hello World')
  197. */
  198. unorderedList: {
  199. block: true,
  200. multiline: true,
  201. prefix: '- '
  202. },
  203. /**
  204. * Task list.
  205. *
  206. * @example
  207. * editor.format('taskList');
  208. * assert(textarea.value == '- [ ] Hello World')
  209. */
  210. taskList: {
  211. block: true,
  212. multiline: true,
  213. prefix: {
  214. value: '- [ ] ',
  215. pattern: '- \\[[x ]{1}\\] '
  216. }
  217. },
  218. /**
  219. * Blockquote.
  220. *
  221. * @example
  222. * editor.format('blockquote');
  223. * assert(textarea.value == '> Hello World')
  224. */
  225. blockquote: {
  226. block: true,
  227. multiline: true,
  228. prefix: '> '
  229. }
  230. };
  231. exports.default = Formats;