comparison src/formats/bbcode.js @ 25:80bf0adc9efd

remove format oo
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 09 Aug 2022 23:15:58 -0600
parents 80a86fb8f2b7
children 160be99e1517
comparison
equal deleted inserted replaced
24:80a86fb8f2b7 25:80bf0adc9efd
1022 * @param {Object} options 1022 * @param {Object} options
1023 * @class BBCodeParser 1023 * @class BBCodeParser
1024 * @name BBCodeParser 1024 * @name BBCodeParser
1025 * @since v1.4.0 1025 * @since v1.4.0
1026 */ 1026 */
1027 function BBCodeParser(options) { 1027 function newBBCodeParser(options) {
1028 var base = this; 1028 var base = {};
1029 1029
1030 base.opts = extend({}, BBCodeParser.defaults, options); 1030 base.opts = extend({}, BBCodeParser.defaults, options);
1031 1031
1032 /** 1032 /**
1033 * Takes a BBCode string and splits it into open, 1033 * Takes a BBCode string and splits it into open,
2063 * @private 2063 * @private
2064 */ 2064 */
2065 function lower(str) { 2065 function lower(str) {
2066 return str.toLowerCase(); 2066 return str.toLowerCase();
2067 } 2067 }
2068
2069 return base;
2068 }; 2070 };
2071
2072 var BBCodeParser = {};
2069 2073
2070 /** 2074 /**
2071 * Quote type 2075 * Quote type
2072 * @type {Object} 2076 * @type {Object}
2073 * @class QuoteType 2077 * @class QuoteType
2211 /** 2215 /**
2212 * SCEditor BBCode format 2216 * SCEditor BBCode format
2213 * @since 2.0.0 2217 * @since 2.0.0
2214 */ 2218 */
2215 function bbcodeFormat() { 2219 function bbcodeFormat() {
2216 var base = this; 2220 var base = {};
2217 2221
2218 base.stripQuotes = _stripQuotes; 2222 base.stripQuotes = _stripQuotes;
2219 2223
2220 /** 2224 /**
2221 * cache of all the tags pointing to their bbcodes to enable 2225 * cache of all the tags pointing to their bbcodes to enable
2520 * @param {boolean} asFragment 2524 * @param {boolean} asFragment
2521 * @param {string} source 2525 * @param {string} source
2522 * @param {boolean} [legacyAsFragment] Used by fromBBCode() method 2526 * @param {boolean} [legacyAsFragment] Used by fromBBCode() method
2523 */ 2527 */
2524 function toHtml(asFragment, source, legacyAsFragment) { 2528 function toHtml(asFragment, source, legacyAsFragment) {
2525 var parser = new BBCodeParser(base.opts.parserOptions); 2529 var parser = newBBCodeParser(base.opts.parserOptions);
2526 var html = parser.toHTML( 2530 var html = parser.toHTML(
2527 base.opts.bbcodeTrim ? source.trim() : source 2531 base.opts.bbcodeTrim ? source.trim() : source
2528 ); 2532 );
2529 2533
2530 return (asFragment || legacyAsFragment) ? 2534 return (asFragment || legacyAsFragment) ?
2545 context = context || document; 2549 context = context || document;
2546 2550
2547 var bbcode, elements; 2551 var bbcode, elements;
2548 var containerParent = context.createElement('div'); 2552 var containerParent = context.createElement('div');
2549 var container = context.createElement('div'); 2553 var container = context.createElement('div');
2550 var parser = new BBCodeParser(base.opts.parserOptions); 2554 var parser = newBBCodeParser(base.opts.parserOptions);
2551 2555
2552 container.innerHTML = html; 2556 container.innerHTML = html;
2553 css(containerParent, 'visibility', 'hidden'); 2557 css(containerParent, 'visibility', 'hidden');
2554 containerParent.appendChild(container); 2558 containerParent.appendChild(container);
2555 context.body.appendChild(containerParent); 2559 context.body.appendChild(containerParent);
2592 2596
2593 base.toHtml = toHtml.bind(null, false); 2597 base.toHtml = toHtml.bind(null, false);
2594 base.fragmentToHtml = toHtml.bind(null, true); 2598 base.fragmentToHtml = toHtml.bind(null, true);
2595 base.toSource = toSource.bind(null, false); 2599 base.toSource = toSource.bind(null, false);
2596 base.fragmentToSource = toSource.bind(null, true); 2600 base.fragmentToSource = toSource.bind(null, true);
2601
2602 return base;
2597 }; 2603 };
2598 2604
2599 /** 2605 /**
2600 * Gets a BBCode 2606 * Gets a BBCode
2601 * 2607 *