Membuat Tools Parse & Unparse di Blog
Sebagai penulis dan pengelola blog sudah seharusnya kita mengerti proses parse kode dan unparse kembali kode iklan maupun kode HTML sebelum digunakan. Hal tersebut, untuk memastikan tata letak iklan artikel tetap teratur. Tanpa menggunakan tool parse dan unparse, artikel dapat menjadi berantakan dan sulit dibaca.
Selain itu, blog dengan niche teknologi biasanya menggunakan alat ini untuk melampirkan teks skrip pada postingan karena kode tidak akan terbaca jika tidak melakukan parse terlebih dahulu.
Umumnya ada lima jenis karakter yang akan berubah setelah diurai, apa saja?
Symbol | Entity Name | Number Code |
---|---|---|
& | & | & |
< | < | < |
> | > | > |
' | ' | ' |
" | " | " |
Bayangin seberapa lama jika menulisnya secara manual? Daripada jari tangan kram mending pakai tools aja. Meski terbilang lebih mudah, namun kamu masi repot kesana-sini jika menggunakan alat yang bukan milik kita sendiri.
Sesuai judul postingan ini, saya akan membagikan cara membuat tool parse dan unparse sendiri untuk menambah fitur navigasi blog agar para pengunjung semakin tertarik.
Klik button demo diatas untuk melihat tampilan detailnya. Jika Anda tertarik membuatnya, silahkan ikuti langkah-langkah berikut ini.
Cara Membuat Tool Parse & Unparse
Buka dashboard blogger > halaman > buat halaman baru lalu salin semua kode dibawah ini dan pastekan dalam tampilan html.
<style type="text/css">
.parseUnparse{align-items:center;display:flex;justify-content:center}
.ctd-bt{margin: 0.5rem 0 1rem;width: -webkit-fill-available;justify-content:space-between;}
.ctd-bt,.ctd-bt-kiri,.ctd-bt-kanan{display:inline-flex;}
.ctd-pu{border-radius:0 0 5px 5px;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;text-align:center}
.ctd-puA{width:-webkit-fill-available;height:200px;padding:1rem;border:0;box-shadow:inset 0 0 5px 1px rgba(0,0,0,.05);border-radius:.5rem;resize:none;color:gray;background:#fafafa;}
.ctd-btP,.ctd-btU,.ctd-btR,.ctd-btC{color:#fff!important;font-weight:700;background:#00BFFF;padding:0.7rem;border-radius:.25rem;border:none;outline:0;box-shadow:0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);transition:all .4s ease-in-out;text-transform:uppercase;margin:0 .25rem;cursor: pointer;}
.ctd-btP span, .ctd-btU span, .ctd-btR span, .ctd-btC span{align-self:center}
</style>
<div class="parseUnparse">
<div class="ctd-pu">
<textarea class="ctd-puA" id="ctd-boxPU" placeholder="<!- Input kode yang akan di-Parse atau di-Unparse ->"></textarea>
<div class="ctd-bt">
<div class="ctd-bt-kiri">
<div class="ctd-btP" id="ctdP-HTML" onclick="convert();" type="button"><span>Parse</span></div>
<div class="ctd-btU" id="ctdU-HTML" onclick="convert();" type="button"><span>Unparse</span></div>
</div>
<div class="ctd-bt-kanan">
<div class="ctd-btR" onclick="document.getElementById('ctd-boxPU').value = '', document.getElementById('ctd-boxO').value = ''" type="button"><svg preserveaspectratio="xMidYMid meet" style="height: 20px; vertical-align: -0.125rem; width: 20px;" viewbox="0 0 24 24"><path d="M2.586 15.408l4.299 4.299a.996.996 0 0 0 .707.293h12.001v-2h-6.958l7.222-7.222c.78-.779.78-2.049 0-2.828L14.906 3a2.003 2.003 0 0 0-2.828 0l-4.75 4.749l-4.754 4.843a2.007 2.007 0 0 0 .012 2.816zM13.492 4.414l4.95 4.95l-2.586 2.586L10.906 7l2.586-2.586zM8.749 9.156l.743-.742l4.95 4.95l-4.557 4.557a1.026 1.026 0 0 0-.069.079h-1.81l-4.005-4.007l4.748-4.837z" fill="currentColor"></path></svg></div>
<div class="ctd-btC" onclick="cpO()" type="button"><svg preserveaspectratio="xMidYMid meet" style="height: 20px; vertical-align: -0.125rem; width: 20px;" viewbox="0 0 24 24"><path d="M20 2H10c-1.103 0-2 .897-2 2v4H4c-1.103 0-2 .897-2 2v10c0 1.103.897 2 2 2h10c1.103 0 2-.897 2-2v-4h4c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zM4 20V10h10l.002 10H4zm16-6h-4v-4c0-1.103-.897-2-2-2h-4V4h10v10z" fill="currentColor"></path></svg></div>
</div>
</div>
<textarea class="ctd-puA" id="ctd-boxO" placeholder="<!- Output kode... ->" readonly=""></textarea>
</div>
</div>
<script type="text/javascript">
function encodeString(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/¡/g,"¡").replace(/¢/g,"¢").replace(/£/g,"£").replace(/¤/g,"¤").replace(/¥/g,"¥").replace(/¦/g,"¦").replace(/§/g,"§").replace(/¨/g,"¨").replace(/©/g,"©").replace(/ª/g,"ª").replace(/«/g,"«").replace(/¬/g,"¬").replace(/®/g,"®").replace(/¯/g,"¯").replace(/°/g,"°").replace(/±/g,"±").replace(/²/g,"²").replace(/³/g,"³").replace(/´/g,"´").replace(/µ/g,"µ").replace(/¶/g,"¶").replace(/·/g,"·").replace(/¸/g,"¸").replace(/¹/g,"¹").replace(/º/g,"º").replace(/»/g,"»").replace(/¼/g,"¼").replace(/½/g,"½").replace(/¾/g,"¾").replace(/¿/g,"¿").replace(/×/g,"×").replace(/÷/g,"÷").replace(/À/g,"À").replace(/Á/g,"Á").replace(/Â/g,"Â").replace(/Ã/g,"Ã").replace(/Ä/g,"Ä").replace(/Å/g,"Å").replace(/Æ/g,"Æ").replace(/Ç/g,"Ç").replace(/È/g,"È").replace(/É/g,"É").replace(/Ê/g,"Ê").replace(/Ë/g,"Ë").replace(/Ì/g,"Ì").replace(/Í/g,"Í").replace(/Î/g,"Î").replace(/Ï/g,"Ï").replace(/Ð/g,"Ð").replace(/Ñ/g,"Ñ").replace(/Ò/g,"Ò").replace(/Ó/g,"Ó").replace(/Ô/g,"Ô").replace(/Õ/g,"Õ").replace(/Ö/g,"Ö").replace(/Ø/g,"Ø").replace(/Ù/g,"Ù").replace(/Ú/g,"Ú").replace(/Û/g,"Û").replace(/Ü/g,"Ü").replace(/Ý/g,"Ý").replace(/Þ/g,"Þ").replace(/ß/g,"ß").replace(/à/g,"à").replace(/á/g,"á").replace(/â/g,"â").replace(/ã/g,"ã").replace(/ä/g,"ä").replace(/å/g,"å").replace(/æ/g,"æ").replace(/ç/g,"ç").replace(/è/g,"è").replace(/é/g,"é").replace(/ê/g,"ê").replace(/ë/g,"ë").replace(/ì/g,"ì").replace(/í/g,"í").replace(/î/g,"î").replace(/ï/g,"ï").replace(/ð/g,"ð").replace(/ñ/g,"ñ").replace(/ò/g,"ò").replace(/ó/g,"ó").replace(/ô/g,"ô").replace(/õ/g,"õ").replace(/ö/g,"ö").replace(/ø/g,"ø").replace(/ù/g,"ù").replace(/ú/g,"ú").replace(/û/g,"û").replace(/ü/g,"ü").replace(/ý/g,"ý").replace(/þ/g,"þ").replace(/ÿ/g,"ÿ")}function decodeString(e){return e.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/¡/g,"¡").replace(/¢/g,"¢").replace(/£/g,"£").replace(/¤/g,"¤").replace(/¥/g,"¥").replace(/¦/g,"¦").replace(/§/g,"§").replace(/¨/g,"¨").replace(/©/g,"©").replace(/ª/g,"ª").replace(/«/g,"«").replace(/¬/g,"¬").replace(/®/g,"®").replace(/¯/g,"¯").replace(/°/g,"°").replace(/±/g,"±").replace(/²/g,"²").replace(/³/g,"³").replace(/´/g,"´").replace(/µ/g,"µ").replace(/¶/g,"¶").replace(/·/g,"·").replace(/¸/g,"¸").replace(/¹/g,"¹").replace(/º/g,"º").replace(/»/g,"»").replace(/¼/g,"¼").replace(/½/g,"½").replace(/¾/g,"¾").replace(/¿/g,"¿").replace(/×/g,"×").replace(/÷/g,"÷").replace(/À/g,"À").replace(/Á/g,"Á").replace(/Â/g,"Â").replace(/Ã/g,"Ã").replace(/Ä/g,"Ä").replace(/Å/g,"Å").replace(/Æ/g,"Æ").replace(/Ç/g,"Ç").replace(/È/g,"È").replace(/É/g,"É").replace(/Ê/g,"Ê").replace(/Ë/g,"Ë").replace(/Ì/g,"Ì").replace(/Í/g,"Í").replace(/Î/g,"Î").replace(/Ï/g,"Ï").replace(/Ð/g,"Ð").replace(/Ñ/g,"Ñ").replace(/Ò/g,"Ò").replace(/Ó/g,"Ó").replace(/Ô/g,"Ô").replace(/Õ/g,"Õ").replace(/Ö/g,"Ö").replace(/Ø/g,"Ø").replace(/Ù/g,"Ù").replace(/Ú/g,"Ú").replace(/Û/g,"Û").replace(/Ü/g,"Ü").replace(/Ý/g,"Ý").replace(/Þ/g,"Þ").replace(/ß/g,"ß").replace(/à/g,"à").replace(/á/g,"á").replace(/â/g,"â").replace(/ã/g,"ã").replace(/ä/g,"ä").replace(/å/g,"å").replace(/æ/g,"æ").replace(/ç/g,"ç").replace(/è/g,"è").replace(/é/g,"é").replace(/ê/g,"ê").replace(/ë/g,"ë").replace(/ì/g,"ì").replace(/í/g,"í").replace(/î/g,"î").replace(/ï/g,"ï").replace(/ð/g,"ð").replace(/ñ/g,"ñ").replace(/ò/g,"ò").replace(/ó/g,"ó").replace(/ô/g,"ô").replace(/õ/g,"õ").replace(/ö/g,"ö").replace(/ø/g,"ø").replace(/ù/g,"ù").replace(/ú/g,"ú").replace(/û/g,"û").replace(/ü/g,"ü").replace(/ý/g,"ý").replace(/þ/g,"þ").replace(/ÿ/g,"ÿ").replace(/&/g,"&")}function cpO(){var e=document.getElementById("ctd-boxO");e.select(),e.setSelectionRange(0,99999),document.execCommand("copy")}var encode=document.getElementById("ctdP-HTML"),decode=document.getElementById("ctdU-HTML"),input=document.getElementById("ctd-boxPU"),output=document.getElementById("ctd-boxO");encode.addEventListener("click",function(){output.value=encodeString(input.value)}),decode.addEventListener("click",function(){output.value=decodeString(input.value)});
</script>
Jika sudah, silahkan beri judul sesuka kalian lalu publikasikan. Perlu diingat jangan melakukan sembarang perubahan pada script karena bisa terjadi error dan tool tidak berfungsi.
Mungkin sekian pembahasan kali ini, jika ada yang ingin ditanyakan jangan ragu untuk menuliskannya pada kolom komentar. Baca juga artikel lainnya untuk mendapatkan tips seputar blogging.
Post a Comment