Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <textarea id=input>
  [size=5][b]Bugged:[/b] cannot handle tags inside tags of the same type. (like quotes in quotes).[/size]
  [url=https://example.com]example[/url]
  [url]https://example.com[/url]
  [img]http://i.cubeupload.com/DvzRx5.jpg[/img]
  [img=http://i.cubeupload.com/DvzRx5.jpg]
  [url=https://www.tbs.co.jp/clannad/][img=http://i.cubeupload.com/DvzRx5.jpg][/url]
  [b]Test[/b] [i]Test[/i]
  [spoiler]Test[/spoiler]
  [spoiler=Baka to]Test[/spoiler]
  There are songs of love, but not for me.
  [size=1]Zero ga kako de[/size]
  [size=7]Ichi ga mirai[/size]
  Ikite yukou!
</textarea>
<pre id=rawoutput></pre>
<div id=formattedoutput></div>
              
            
!

CSS

              
                textarea,
pre:first-of-type {
  width: 100%;
  min-height: 7em;
  white-space: pre-wrap;
  border-bottom: 1px dotted #248;
}
              
            
!

JS

              
                window.renderBBCode = (function () {

var states = [
  /\[/,     // 0 outside tag
  /[=[\]]/, // 1 inside tag
  /\]/      // 2 parsing attribute
  // state 3 is finding closing tag
];

var tagList = ['*', 'img', 'url', 'color', 'size', 'font', 'quote', 'spoiler', 'hr', 'b', 'i', 'u', 's'];
var whitelist = {
  'img': /^https?:\/\//, 'url': /^(https?|ftps?|ircs?):\/\//, 'color': /[A-Za-z]+|#(?:[0-9a-f]{3}){1,2}/, 'font': '[1-7]'
};
var tagInfo = [
  ['li'],
  ['img', 'src', {style: 'max-width:500px;', alt: '', border: 0}],
  ['a', 'href', {rel: 'noreferrer', target: '_blank'}],
  ['font', 'color'],
  ['font', 'size'],
  ['font', 'face'],
  function (arg, content) {
    var el = document.createDocumentFragment();
    
    var tmp = document.createElement('p');
    tmp.className = 'sub';
    tmp.innerHTML = '<b></b>';
    tmp.firstChild.textContent = arg ? arg + ' escreveu:' : 'Citação:';
    el.appendChild(tmp);
    
    tmp = document.createElement('table');
    tmp.className = 'main';
    tmp.setAttribute('border', 1);
    tmp.setAttribute('cellspacing', 0);
    tmp.setAttribute('cellpadding', 10);
    tmp.innerHTML = '<tr><td style="border: 1px black dotted"></td></tr>';
    tmp.firstChild.firstChild.appendChild(parse(content));
    
    el.appendChild(tmp);
    
    return el;
  },
  function (arg, content) {
    var el = document.createElement('div');
    el.textContent = (arg || 'Spoiler') + ' ';
    var toggleImg = document.createElement('img');
    
    toggleImg.src = 'images/plus.gif';
    toggleImg.title = 'Spoiler';
    toggleImg.alt = '';
    el.appendChild(toggleImg);
    
    var spoilerDiv = document.createElement('div');
    spoilerDiv.appendChild(parse(content));
    spoilerDiv.style.display = 'none';
    el.appendChild(spoilerDiv);
    
    return el;
  }
];

function parse(text) {
  var oldp = 0;
  var newp = 0;
  var state = 0;
  var result = document.createDocumentFragment();
  var tagArr = [];
  var attributeArr = [];
  
  function addTextNode(text) {
    text.split('\n').forEach(function (content, n, arr) {
      result.appendChild(
        document.createTextNode(content)
      );
      
      if (n !== arr.length - 1) {
        result.appendChild(document.createElement('br'));
      }
    });
  }
  
  do {
    newp = text
      .substr(oldp)
      .search(states[state]);
    
    var foundTag = newp !== -1;
    if (foundTag) {
      newp += oldp;
    } else {
      newp = text.length;
    }
    
    var content;
    var tag;
    var closingTag;
    var closingAttr;
    var hasAttributes;
    var tagIndex = -1;
    var foundChar;
    
    switch (state) {
      case 0:
        content = text.substring(oldp, newp);
        
        if (content) {
          addTextNode(content);
        }
        if (foundTag) {
          state = 1;
        }
        break;
        
      case 1:
        tag = text.substring(oldp, newp);
        tagArr.push(tag);
        
        foundChar = text.charAt(newp);
        
        if (foundChar === '[') {
          addTextNode('[');
          break;
        }
        
        hasAttributes = foundChar === '=';
        
        if (!hasAttributes) {
          attributeArr.push('');
          
          if (tag === '*' || tag === 'hr') {
            text = text.substr(0, newp + 1) + '[/' + tag + ']' +
              text.substr(newp + 1);
          }
        }
        state = 3 - hasAttributes;
        break;
        
      case 2:
        attributeArr.push(
          text.substring(oldp, newp));
        
        state = 3;
        break;
    }
    
    oldp = newp + 1;
    
    if (state === 3) {
      closingTag = tagArr.pop();
      closingAttr = attributeArr.pop();
      
      var endedStartTag = text.indexOf(']', newp);
      newp = closingTag === 'img' && closingAttr ? endedStartTag : text.indexOf('[/' + closingTag + ']', oldp);
      
      var openedTag;
      if (newp === -1) {
        newp = text.length;
        openedTag = true;
      } else {
        tagIndex = tagList.indexOf(closingTag);
      }
      
      content = text.substring(oldp, newp);
      
      if (tagIndex === -1) {
        addTextNode('[' + closingTag + (closingAttr ? ('=' + closingAttr) : '') + (endedStartTag === -1 ? '' : ']'));
        if (content) {
          result.appendChild(parse(content));
        }
        if (!openedTag) {
          addTextNode('[/' + closingTag + ']');
        }
      } else if (typeof tagInfo[tagIndex] === 'function'){
        result.appendChild(tagInfo[tagIndex](closingAttr, content));
      } else {
        var info = tagInfo[tagIndex] || [];
        var el = document.createElement(
          info[0] || closingTag
        );
        
        var attributes = info[2];
        if (attributes) {
          for (var i in attributes) {
            if (attributes.hasOwnProperty(i)) {
              el.setAttribute(i, attributes[i]);
            }
          }
        }
        
        var whitelistConfig = whitelist[closingTag];
        var attribute;
        
        if (closingTag === 'img') {
          attribute = closingAttr || content;
          
          if (!whitelistConfig || whitelistConfig.test(attribute)) {
            el.setAttribute(info[1], attribute);
          } else {
            el = document.createTextNode('');
          }
        } else if (closingTag === 'url') {
          attribute = closingAttr || content;
          
          if (!whitelistConfig || whitelistConfig.test(attribute)) {
            el.setAttribute(info[1], attribute);
            el.appendChild(parse(content));
          } else {
            el = document.createTextNode('');
          }
        } else if (info[1]) {
          el.setAttribute(info[1], closingAttr);
          el.appendChild(parse(content));
        } else {
          el.appendChild(parse(content));
        }
        result.appendChild(el);
      }
      
      oldp = endedStartTag === -1 || openedTag ? text.length : text.indexOf(']', newp) + 1;
      state = 0;
    }
  } while (oldp < text.length);
  
  switch (state) {
    case 1:
      addTextNode('[');
      break;
    case 2:
      addTextNode('[' + tagArr.pop());
      break;
    case 3:
      addTextNode('[' + tagArr.pop() + '=' + attributeArr.pop());
      break;
  }
  
  return result;
}

return parse;

}());

if (typeof input !== 'undefined') {
  function render () {
    var result = renderBBCode(input.value.trim());
    formattedoutput.innerHTML = '';
    formattedoutput.appendChild(result);
    rawoutput.textContent = formattedoutput.innerHTML;
  }
  render();
  input.oninput = render;
}
              
            
!
999px

Console