テキストエリアにコードを書くためのHTMLエンティティ化ブックマークレット CodeWrite

コメントにコードを書けるようにしろ、との意見があった。まったくもって正統な要求である。
というわけで何とかしようと思ったけど、Wordpressよくわからんのであきらめて、代わりにブックマークレット作っておいた。
HTMLエンティティ化したい部分を選択して実行すれば変換してくれる。textareaの中に対してしか作用しないけど。
Wordpressのjavascriptをだいぶパクっています。

これで我慢してください。

以上

コスミー について

昔(?)はゲーム作ってました。 今もなんか作ろうとしています。
カテゴリー: Javascript パーマリンク

テキストエリアにコードを書くためのHTMLエンティティ化ブックマークレット CodeWrite への5件のフィードバック

  1. コスミー のコメント:

    テスト
    function enentity(content) {
       return content.replace(/&/g,’&amp;’).replace(/\"/g,’&quot;’).replace(/</g, ‘&lt;’).replace(/>/g, ‘&gt;’).replace(‘/ /g’,’&nbsp;’);
    }

    function codewrite() {
       var myFields = document.getElementsByTagName("TEXTAREA");
       var myField;
       
       for (var i = 0; i < myFields.length; i++) {
          myField = myFields[i];
          if (document.selection) {
             myField.focus();
              sel = document.selection.createRange();
             if (sel.text.length > 0) {
                sel.text = enentity(sel.text);
             } else {
                continue;
             }
             
             myField.focus();
          }
          else if (myField.selectionStart || myField.selectionStart == ‘0’) {
             var startPos = myField.selectionStart;
             var endPos = myField.selectionEnd;
             var cursorPos = endPos;
             var scrollTop = myField.scrollTop;

             if (startPos != endPos) {
                var before = myField.value.substring(startPos, endPos);
                var after = enentity(before);
                myField.value = myField.value.substring(0, startPos)
                              + after
                              + myField.value.substring(endPos, myField.value.length);
                cursorPos += after.length – before.length;
             } else {
                continue;
             }
             
             myField.focus();
             myField.selectionStart = cursorPos;
             myField.selectionEnd = cursorPos;
             myField.scrollTop = scrollTop;
          }
       }
    }

  2. o-taki のコメント:

    function test() {
      for ( i=0 ;i<100; i++ ) {
        printf("hello world!\n");
      }
    }

  3. 匿名 のコメント:

    Add Your Comment

  4. trachycarpus fortunei のコメント:

    @Anupam154713020 Despo looking for sx on twitter. What a sorry existence..!!

    Don’t exert too much…. Fortune lines on your palm might
    get erased..

  5. fortunei palm のコメント:

    The sight of palm trees, in any work of oil painting art, speaks to
    our unconscious. Therefore, I hope to hook you into the subject,
    by telling to you, about the symbolism, of the palm tree, and the way you should use it, in your customized oil painting composition. If your soil will
    not be very nutrient, it can be strengthened
    with organic or inorganic fertilizers. Also the provision of fertilizers, each organic and inorganic, is necessary.
    It isn’t obligatory to do this, but the reward is much greater.
    It takes a long two years time. These two information together make coconut oil one of
    the healthiest oils to your coronary heart. This swap will
    benefit your heart and your entire body. Put Your Heart On Vacation! I believe
    that historically (at the very least in Hawaii) Tiki Statues were carved out of
    the trunks of palm trees indigenous to a given space (they used what was around).

コメントを残す

メールアドレスが公開されることはありません。