Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <h3>日本語の括弧類を自動補完する</h3> <p>テキストエリアに「 ” 【 などの前括弧類を単体で入力すると、後ろ括弧を自動補完してカーソルを間に置きます</p> <textarea name="" id="text-area" cols="30" rows="10"></textarea>

              
            
!

CSS

              
                
              
            
!

JS

              
                const input_element = document.getElementById("text-area");

// 入力終了時に内容をチェックして置き換える

input_element.addEventListener("compositionend", function (e) {
  const data = e.data;
  switch (data) {
    case "「":
      complete_quote(input_element, "」");
      break;
    case "”":
      replace_quote(input_element, "“”");
      break;
    case "{":
      complete_quote(input_element, "}");
      break;
    case "『":
      complete_quote(input_element, "』");
      break;
    case "’":
      replace_quote(input_element, "‘’");
      break;
    case "【":
      replace_quote(input_element, "】");
      break;
    case "[":
      replace_quote(input_element, "]");
      break;
    case "(":
      replace_quote(input_element, ")");
      break;
    default:
      break;
  }
});

//後ろに補完する関数
function complete_quote(element, charactor) {
  const content = element.value;
  const len = content.length;
  const pos = element.selectionStart;
  element.value = content.substr(0, pos) + charactor + content.substr(pos, len);
  element.setSelectionRange(pos, pos);
}

//そっくり入れ替える関数
function replace_quote(element, charactor) {
  const content = element.value;
  const len = content.length;
  const pos = element.selectionStart;
  element.value =
    content.substr(0, pos - 1) + charactor + content.substr(pos, len);
  element.setSelectionRange(pos, pos);
}

              
            
!
999px

Console