Ver código fonte

feat(Converter.options): add getOption(), setOption() and getOptions() to Converter object

Provides a way to get and set options directly in a Converter object
Estevão Soares dos Santos 10 anos atrás
pai
commit
db6f79b08d
5 arquivos alterados com 71 adições e 7 exclusões
  1. 40 5
      dist/showdown.js
  2. 0 0
      dist/showdown.js.map
  3. 1 1
      dist/showdown.min.js
  4. 0 0
      dist/showdown.min.js.map
  5. 30 1
      src/showdown.js

+ 40 - 5
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 26-05-2015 */
+;/*! showdown 27-05-2015 */
 (function(){
 /**
  * Created by Tivie on 06-01-2015.
@@ -282,8 +282,37 @@ showdown.Converter = function (converterOptions) {
     return text;
   }
 
+  /**
+   * Set an option of this Converter instance
+   * @param {string} key
+   * @param {string} value
+   */
+  function setOption (key, value) {
+    options[key] = value;
+  }
+
+  /**
+   * Get the option of this Converter instance
+   * @param {string} key
+   * @returns {*}
+   */
+  function getOption(key) {
+    return options[key];
+  }
+
+  /**
+   * Get the options of this Converter instance
+   * @returns {{}}
+   */
+  function getOptions() {
+    return options;
+  }
+
   return {
-    makeHtml: makeHtml
+    makeHtml: makeHtml,
+    setOption: setOption,
+    getOption: getOption,
+    getOptions: getOptions
   };
 };
 
@@ -654,15 +683,21 @@ showdown.subParser('codeBlocks', function (text, options, globals) {
 
   var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g;
   text = text.replace(pattern, function (wholeMatch, m1, m2) {
-    var codeblock = m1, nextChar = m2;
+    var codeblock = m1,
+        nextChar = m2,
+        end = '\n';
 
     codeblock = showdown.subParser('outdent')(codeblock);
     codeblock = showdown.subParser('encodeCode')(codeblock);
     codeblock = showdown.subParser('detab')(codeblock);
     codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
-    codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
+    codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
+
+    if (options.omitExtraWLInCodeBlocks) {
+      end = '';
+    }
 
-    codeblock = '<pre><code>' + codeblock + '\n</code></pre>';
+    codeblock = '<pre><code>' + codeblock + end + '</code></pre>';
 
     return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
   });

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/showdown.js.map


Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 1
dist/showdown.min.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
dist/showdown.min.js.map


+ 30 - 1
src/showdown.js

@@ -280,7 +280,36 @@ showdown.Converter = function (converterOptions) {
     return text;
   }
 
+  /**
+   * Set an option of this Converter instance
+   * @param {string} key
+   * @param {string} value
+   */
+  function setOption (key, value) {
+    options[key] = value;
+  }
+
+  /**
+   * Get the option of this Converter instance
+   * @param {string} key
+   * @returns {*}
+   */
+  function getOption(key) {
+    return options[key];
+  }
+
+  /**
+   * Get the options of this Converter instance
+   * @returns {{}}
+   */
+  function getOptions() {
+    return options;
+  }
+
   return {
-    makeHtml: makeHtml
+    makeHtml: makeHtml,
+    setOption: setOption,
+    getOption: getOption,
+    getOptions: getOptions
   };
 };

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff