HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
section(v-scope="")
//span 🏗
//span ⚠️🚧
//div {{JSON.stringify(store)}}
div.toolbtn
label
input(type="checkbox",v-model="store.open_cheatsheet")
span 📒
label
input(type="checkbox",v-model="store.open_table")
span 📝
div.cs(v-if="store.open_cheatsheet")
span(v-for="(v,k) in store.gs")
span {{k+"\u20de"}} {{v}}
span(v-for="(v,k) in store.ds")
span {{k+"\u20dd"}} {{v}}
span(v-for="(v,k) in store.nn")
span {{k+"\u20e4"}} {{v}}
span(v-for="(v,k) in store.kmj")
span {{"ゃ\u20d8"}} {{v}}
div.tbl(v-if="store.open_table")
div.ps
span(v-scope="preset_btn({label:'♥️',key:'zk'})")
span(v-scope="preset_btn({label:'🐾',key:'nk'})")
span(v-scope="preset_btn({label:'🐱',key:'ny'})")
span(v-scope="preset_btn({label:'🐶',key:'wf'})")
span(v-scope="preset_btn({label:'👓',key:'df'})")
ul: li(v-for="g_key in keys.g")
label
span {{g_key}}
input(v-model="store.gs[g_key]",
@change="udt_zk();zkbg()")
ul: li(v-scope="{n_key: keys.nn[0]}")
label {{n_key}}
input(v-model="store.nn[n_key]",
@change="udt_zk();zkbg()")
ul: li(v-for="d_key in keys.d")
label {{d_key}}
input(v-model="store.ds[d_key]",
@change="udt_zk();zkbg()")
ul: li(v-scope="{k_key: keys.kmj[0]}")
label {{k_key}}
input(v-model="store.kmj[k_key]",
@change="udt_zk();zkbg()")
div(v-scope="{o_k:keys.okb[0]}")
label: input(type="checkbox",v-model="store.conv_opts.kmmv",@change="udt_zk();zkbg()")
label
span {{o_k}}
input(v-model="store.okb[o_k]",:disabled="!store.conv_opts.kmmv",@change="udt_zk();zkbg()")
div.xb: label
input(type="checkbox", v-model="store.open_xsbr")
span 🪄
div.xb(v-if="store.open_xsbr",v-scope={from:"♥️",to:"♡"})
button(@click="[from,to] = [to,from]") ↔️
input(v-model="from")
span →
input(v-model="to")
button(@click="xsbr(from,to);udt_zk();zkbg()") 🪄
div
div: label
input(type="checkbox",
v-model="store.conv_opts.hn2zn",
@change="udt_zk")
span カナ→カナ→💌
div: textarea.kn(
v-model="store.ta.kn",
@input="udt_zk",
:placeholder="store.sample")
div.zkb(v-if="store.open_zkb")
span(v-for="kc in store.zkbks",
:key="s2cp_(kc)")
span(v-scope="zkbk({label:kc,text:kc})")
button(@click="bszk();udt_kn()") ◀️
button(@click="store.ta.zk='';udt_kn()") ⏮
div.zkb
label
input(type="checkbox", v-model="store.open_zkb")
span ⌨️
div: textarea.zk(
v-model="store.ta.zk",
@input="udt_kn",
:placeholder="kn2zk(store.sample)")
div: span 💌→
label
input(type="radio",value="hr",
v-model="store.conv_opts.hrkt",
@change="udt_kn")
span あ⃞
label
input(type="radio",value="kn",
v-model="store.conv_opts.hrkt",
@change="udt_kn")
span ㋐
template(id="preset")
button(@click="fill();udt_zk();zkbg()")
span {{label}}
template(id="zkbk")
button(@click="put();udt_kn()")
span {{label}}
<script type="text/plain" v-scope="" @vue:mounted="reg($el,'zk','init')">
|【行】
| あ ざーこ
| か ざぁこ
| さ ざこぉ
| た ざーこー
| な ざぁこー
| は ざこぉー
| ま ざぁーこ
| や ざーこぉ
| ら ざこー
| わ ざこ
| ん ざこち〇ぽ♥️
| が 雑ぁ魚
| ざ 雑魚ぉ
| だ 雑ー魚ー
| ば 雑魚ぉー
| ぱ ざっこ
|【段】
| あ ♥️
| い っ♥️
| う …♥️
| え っ♥️♥️
| お ♥️♥️
| 小文字化 !
| この前に ♥️
</script>
<script type="text/plain" v-scope="" @vue:mounted="reg($el,'nk')">
|【行】
| あ ねーこ
| か にぇこ
| さ ねこぉ
| た ねーこー
| な にぇこー
| は ねこぉー
| ま にぇーこ
| や ねーこぉ
| ら ねこー
| わ ねこ
| ん ねこし〇ぽ♥️
| が ニェコ
| ざ ネコォ
| だ ネーコー
| ば ネコォー
| ぱ ねっこ
|【段】
| あ ♥️
| い っ♥️
| う …♥️
| え っ♥️♥️
| お ♥️♥️
| 小文字化 !
| この前に ♥️
</script>
<script type="text/plain" v-scope="" @vue:mounted="reg($el,'ny')">
|【行】
| あ にゃーお
| か にゃぁお
| さ にゃおぉ
| た にゃーおー
| な にゃぁおー
| は にゃおぉー
| ま にゃぁーお
| や にゃーおぉ
| ら にゃおー
| わ にゃお
| ん にゃおち〇ーる♡
| が んみゃぁお
| ざ んみゃおぉ
| だ んみゃーおー
| ば んみゃおぉー
| ぱ にゃっお
|【段】
| あ ♡
| い っ♡
| う …♡
| え っ♡♡
| お ♡♡
| 小文字化 !
| この前に ♡
</script>
<script type="text/plain" v-scope="" @vue:mounted="reg($el,'wf')">
|【行】
| あ わっふ
| か わぁふ
| さ わふぅ
| た わっふー
| な わぁふー
| は わふぅー
| ま わぁーふ
| や わっふぅ
| ら わふー
| わ わふ
| ん わっふっふー‼️
| が わぁふわふ
| ざ わふわふぅ
| だ わっふわーふ
| ば わふわふぅー
| ぱ わふふ
|【段】
| あ !
| い っ!
| う …♡
| え っ‼️
| お ♪
| 小文字化 ッ
| この前に
</script>
<script type="text/plain" v-scope="" @vue:mounted="reg($el,'df')">
|【行】
| あ デュフ
| か ドゥフ
| さ ブフォ
| た デュフフ
| な ドゥフフ
| は ブホ
| ま ドゥフフフ
| や デュフフフ
| ら ブフー
| わ ブフ
| ん フォカヌポゥwww
| が ドゥブフ
| ざ ドブフォ
| だ ドゥブフフ
| ば ドブフォホ
| ぱ ブッホ
|【段】
| あ w
| い ッw
| う ホww
| え ッww
| お ww
| 小文字化 コポォ
| この前に w
</script>
@import "https://unpkg.com/normalize.css@8.0.1/normalize.css";
body, textarea {
font-size: small;
font-family: sans-serif;
background-color: lavenderblush;
}
input:not([type]), textarea {
background-color: snow;
border-color: lavender;
}
label {background-color: lavender;}
li {
list-style-type: none;
}
ul {
padding-left: 1em;
}
div {
margin: 0.5em;
}
textarea {
width: 95%;
}
button {
margin: 0.1em;
padding: 0.2em 0.5em;
background-color: mistyrose;
border-color: salmon;
}
.toolbtn {text-align: right;}
.cs {opacity: 0.6; background-color: lavender;}
.ps {text-align: center;}
.xb {text-align: right;}
.zkb {text-align: right;}
textarea.kn {
height: 10vh;
}
textarea.zk {height: 40vh;}
const keys = {
g: "あかさたなはまやらわがざだばぱ".split``,
d: "あいうえお".split``,
nn: ["ん"],
kmj: ["小文字化"],
okb: ["この前に"] // 🆕
}//for <label> & srctxts
const {kn2abMap,ab2kkMap,kk2abMap,ab2knMap,hrktMp} = aMap(keys)
const [gs, ds, nn, kmj, okb] = ["g", "d", "nn", "kmj", "okb"].map((x) =>
Object.fromEntries(keys[x].map((k) => [k, ""]))
);
const midasi = [{ g: "【行】"}, {d: "【段】" }]
.reduce((a,c,i)=>{
const k = Object.keys(c)[0]
return {...a,[k]:{txt:c[k]}}
},{})
const {vsm,emm,zwj} = xxm()
const { createApp, reactive } = PetiteVue;
const store = reactive({
gs,ds,nn,kmj,okb,
open_cheatsheet:false,
open_table:false,open_zkb:false,open_xsbr:false,
conv_opts:{
hn2zn: true,
hrkt: "hr",
kmmv: true
},
srctxts:{zk:""},
ta:{kn:"",zk:""},zkbks:[],
sample: "こんにちは"
});
createApp({ store }).mount();
function preset_btn(props) {
const { label, key } = props;
return {
$template: "#preset",
label, key,
fill() {fill_table(key);zkbg()}
};
}
function fill_table(key) {
set_table(store.srctxts[key])
}
function set_table(srctxt) {
const ls = srctxt.split(/[\n\r]+/);
const dstart = ls.findIndex(l => l.match(midasi.d.txt));
const gstart = ls.findIndex(l => l.match(midasi.g.txt));
ls.forEach((l, li) => {
if (l.indexOf`\t` > 0) {
const [k, v] = l.split`\t`;
//if (keys.nn[0]==k || keys.kmj[0]==k) {
if (["nn","kmj","okb"].some(n=>keys[n][0]==k)){
store[["nn","kmj","okb"].find(n=>keys[n][0]==k)][k] = v;
} else {
store[(
(gstart<dstart&&gstart<li&&li<dstart)||
(dstart<gstart&&gstart<li)?"g":"d"
)+"s"][k] = v;
}
}
});
}
function s2cp_(str) {
let r="";for(const s of str){r+=s.codePointAt(0)+"_"}
return r
}
function xsbr(f,t) { // “batch/bulk” replace
//const {gs,ds,nn,kmj} = store
["gs","ds","nn","kmj","okb"].forEach(x=>{
for (let [k,v] of Object.entries(store[x])) {
store[x][k] = v.replaceAll(f,t)
}
})
}
function aMap(keys) {
const mapsrctxt = `
あア→.a;いイ→.i;うウ→.u;えエ→.e;おオ→.o;
かカ→ka;きキ→ki;くク→ku;けケ→ke;こコ→ko;
さサ→sa;しシ→si;すス→su;せセ→se;そソ→so;
たタ→ta;ちチ→ti;つツ→tu;てテ→te;とト→to;
なナ→na;にニ→ni;ぬヌ→nu;ねネ→ne;のノ→no;
はハ→ha;ひヒ→hi;ふフ→hu;へヘ→he;ほホ→ho;
まマ→ma;みミ→mi;むム→mu;めメ→me;もモ→mo;
やヤ→ya;ゆユ→yu;よヨ→yo;
らラ→ra;りリ→ri;るル→ru;れレ→re;ろロ→ro;
わワ→wa;ゐヰ→wi;ゑヱ→we;をヲ→wo;
んン→q;
がガ→ga;ぎギ→gi;ぐグ→gu;げゲ→ge;ごゴ→go;
ざザ→za;じジ→zi;ずズ→zu;ぜゼ→ze;ぞゾ→zo;
だダ→da;ぢヂ→di;づヅ→du;でデ→de;どド→do;
ばバ→ba;びビ→bi;ぶブ→bu;べベ→be;ぼボ→bo;
ぱパ→pa;ぴピ→pi;ぷプ→pu;ぺペ→pe;ぽポ→po;
ぁァ→.!a;ぃィ→.!i;ぅゥ→.!u;ぇェ→.!e;ぉォ→.!o;
ゃャ→y!a;ゅュ→y!u;ょョ→y!o;
っッ→t!u;
`.trim()
const kn2abMap = new Map(), hrktMp=new Map()
mapsrctxt.split(/;\s?/)
.map(v=>v.split`→`)
.forEach(([ks,v])=>{
const x = ks.split``, y=[true,false]
x.forEach(k=>{kn2abMap.set(k,v)})
y.forEach(i=>hrktMp.set(x[i?0:1],x[i?1:0]))
})
const ab2kkMap = new Map();
["g:.kstnhmyrwgzdbp","d:aiueo","nn:q","kmj:!"]
.map(v=>v.split`:`)
.forEach(([k,s])=>{s.split``.forEach((v,idx)=>{
ab2kkMap.set(v,[
k+(k=="g"||k=="d"?"s":""),
keys[k][idx]
])
})})
const n_=new Map();ab2kkMap.forEach((v,k)=>{n_.set(v.join`,`,k)});const kk2abMap = n_;
const o_=new Map();kn2abMap.forEach((v,k)=>{if(/[ぁ-ん]/.test(k))o_.set(v,k)});const ab2knMap = o_;
return {kn2abMap,ab2kkMap,kk2abMap,ab2knMap,hrktMp}
}
function kn2zk(
text,st,
k2aM=kn2abMap,a2kM=ab2kkMap
){
st=st?st:store;
const {conv_opts} = st
const {hn2zn,kmmv} = conv_opts
const srctext0 = hn2zn?hntxt2zntxt(text):text
const srctext = nobasi2vowel(srctext0)
const replacer = moji => {
const ab = k2aM.get(moji)
const tbj = ab ? ab.split``
.map(a=>a2kM.get(a))
.map(kk=>st[kk[0]][kk[1]])
:null
return !tbj?moji:kmmv&&ab[1]=="!"?
kzrp_kmmv(tbj):
tbj.join``
}
return srctext.replace(/[ァ-ンぁ-ん]/g,replacer)
}
function kzrp_kmmv(tbj){
const [gy,kj,dn] = tbj
const okb_s = store.okb[keys.okb[0]]
const dkjn = dn.replace(okb_s,kj+okb_s)
return dkjn.match(okb_s)?gy+dkjn:gy+kj+dn
}
function hntxt2zntxt(hntxt) {
return hntxt.replace(/[。-゚]+/g,m=>m.normalize("NFKC")).toString()
}
function nobasi2vowel(text,k2aM=kn2abMap) {
k2aM=k2aM?k2aM:kn2abMap
return text.replace(
/([ァ-ンぁ-ん])(ー+)/g,(_,kn,nbs)=>{
const ab = k2aM.get(kn)
const b = ab?ab.slice(-1)[0]:null
const tbl = {a:"あ",i:"い",u:"う",e:"え",o:"お"}
const result = b?tbl[b]?tbl[b]:kn:ー
return [kn,nbs.replace(/./g,result)].join``}
).toString()
}
function zk2kn(
text_in,st,
kkab=kk2abMap,abkn=ab2knMap
){
st=st?st:store;
const {conv_opts,gs,ds,nn,kmj,okb} = st
const {hrkt,kmmv} = conv_opts
const zkkk = new Map() // nonce Map()
//regexp
const [pg,pd,pn,pk] = [{gs},{ds},{nn},{kmj}]
.map(o0=>{
const [k,o] = Object.entries(o0)[0]
return Object.entries(o).map(([l,z])=>{
zkkk.set(z,[k,l].join`,`)
return escstr(z)
})
})
//(kmmv? undo komoji-move)
const dkjn2zkM = !kmmv?null:d2z_gen(ds,kmj,okb)
const text = !kmmv?text_in:nomrepwitMap(text_in,dkjn2zkM)
//([nn]|[pg][kmj]?[pd])
const restr = `
(${pn[0]})|(?!${pd.join`|`})((${pg.join`|`})(${pk[0]})?(${pd.join`|`}))(?!${pd.join`|`})
`.trim()
const re = new RegExp(restr,"g")
//replacer
return text.replace(re,(_m,mn,__,mg,mk,md)=>{
//console.log({mn,mg,mk,md})
const abcd = [mn,mg,mk,md].filter(_=>_).map(m=>
kkab.get(zkkk.get(m))
).join``
const hrgn = abkn.get(abcd)
const knkn = hrkt=="hr"?hrgn:hrktMp.get(hrgn)
return knkn?knkn:_m
})
}
function escstr(str) { if(!str) return null
const sp = /[\[\\\^\$\.\|\?\*\+\(\)]/g
return str.replace(sp,"\\$&").toString()
}// for RegExp
function d2z_gen(ds_,kmj_,okb_) {
const o_s = okb_[keys.okb[0]]
const k_s = kmj_[keys.kmj[0]]
const dkjn2zkM = new Map()
Object.values(ds_).forEach(zd=>{
dkjn2zkM.set(zd.replace(o_s,k_s+o_s),k_s+zd)
})
return dkjn2zkM
}
function nomrepwitMap(text,_Map) {
const re0 = [..._Map.keys()].join`|`
return text.replace(
new RegExp(`(${re0})`,"g"),
match=>_Map.get(match)
)
}
//for key<button>s
function xxm() {
const vsm = /[\u{fe00}-\u{fe0f}\u{e0100}-\u{e01ef}]/u
const emm = /[\u{1f3fb}-\u{1f3ff}\u{200d}]/u
const zwj = "\u{200d}"
// flags not supported
return {vsm,emm,zwj}
}
function ss(str) {
let r = [], pre_z=false
for (const c of str) {
r.push(
(vsm.test(c)||emm.test(c)||pre_z)&&r[0]?
r.pop().concat(c):
c)
pre_z = zwj==c
}
return r
}
function zkbg() {
let pre_z = false, last = ""
const {gs,ds,nn,kmj} = store
const charS = new Set()
for (const o of [gs,ds,nn,kmj]) {
for (const v of Object.values(o)) {
for (const c of v) {
if (vsm.test(c)||emm.test(c)||pre_z) {
charS.delete(last);
charS.add(last+c);last=last+c
}else{charS.add(c);last=c}
pre_z = zwj==c
}}}
store.zkbks.splice(0)
charS.forEach(c=>{store.zkbks.push(c)})
}
function zkbk(props) {
const { label, text } = props;
return {
$template: "#zkbk",
label, text,
put() {store.ta.zk+=text}
}
}
function bszk() { //"backspace"
const tarr = [...store.ta.zk]
const popt = tarr.pop()
if(vsm.test(popt)||emm.test(popt)||tarr.slice(-1)[0]==zwj){tarr.pop()}
store.ta.zk = tarr.join``
}
function udt_zk() {store.ta.zk=kn2zk(store.ta.kn)}
function udt_kn() {store.ta.kn=zk2kn(store.ta.zk)}
//init
function reg(elm,key,init_with=false) {
const srctxt = elm.text
store.srctxts[key] = srctxt
if(init_with){
fill_table(key)
zkbg()
}
}
Also see: Tab Triggers