Skip to content

Instantly share code, notes, and snippets.

@eimg
Created June 15, 2012 10:50
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save eimg/2935830 to your computer and use it in GitHub Desktop.
Save eimg/2935830 to your computer and use it in GitHub Desktop.
Inserting ZWSP between every syllables for better text wrapping for Myanmar text.
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Break Wrap</title>
<style>
body {
background: #efefdd;
}
ul {
font: 15px/30px Myanmar3,TharLon,Yunghkio;
width: 360px;
margin: 20px auto;
padding: 25px 25px 25px 40px;
border: 4px solid #ddd;
border-radius: 5px;
background: #FFF;
}
</style>
<script>
window.onload = function() {
li = document.getElementsByTagName("li");
for(var i=0; i < li.length; i++) {
li[i].innerHTML = insert_zwsp( li[i].innerHTML );
}
};
function insert_zwsp(str) {
var consonants = [
"က","ခ","ဂ","ဃ","င",
"စ","ဆ","ဇ","ဈ","ည",
"ဍ","ဌ","ဋ","ဎ","ဏ",
"တ", "ထ","ဒ","ဓ","န",
"ပ","ဖ","ဗ","ဘ","မ",
"ယ","ရ","လ","ဝ","သ",
"ဟ","ဠ","အ",
"ဿ","ဦ","ဥ" ,"ဩ","ဣ"
];
var len = str.length;
var new_str = "";
for(var i=0; i<len; i++) {
chr = str.substr(i, 1);
if(inArray(chr,consonants)) {
if(str.substr(i + 1, 1) != "်" &&
(str.substr(i + 1, 1) != "့" && str.substr(i + 2, 1) != "်")) {
new_str += "\u200B"; //ZWSP
}
}
new_str += chr;
}
return new_str;
}
function inArray(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
if(haystack[i] == needle) return true;
}
return false;
}
</script>
</head>
<body>
<ul>
<li>မြန်မာစာရေးရာတွင်စကားစုတစ်ခုနှင့်တစ်ခုကြားတွင်စပေ့များထည့်ရန်မလိုပေ။</li>
<li>ထို့ကြောင့်မြန်မာစာစကားစုပိုင်းဖြတ်ပုံကိုနားမလည်သည့်ကွန်ပျူတာနည်းပညာများသည်၊</li>
<li>မြန်မာစာစကားစုများကိုအဆင်ပြေချောမွေ့စွာညှိနှိုင်းစီစဉ်းပေးခြင်းများပြုလုပ်နိုင်လိမ့်မည်မဟုတ်ပါ။</li>
<li>ထို့ကြောင့်ရေးသားသူများကရေးသားစဉ်တွင်မကြာမကြာစပေ့များကိုလိုအပ်သလိုထည့်ပေးရန်အထူးသဖြင့်လိုအပ်မည်ဖြစ်သည်။ဤစမ်းသပ်မှု့သည်စကားစုဖြတ်ထုံးမလိုအပ်ပဲအိပ်ချ်တီအမ်အယ်လ်စာမျက်မှာပေါ်တွင်စာများကိုအလိုအလျှောက်စီစဉ်ပေးနိုင်မည့်စခရစ်ဖြစ်ပါသည်။</li>
</ul>
</body>
</html>
@waimyokyaw
Copy link

Thank you bro.

@AungWinnHtut
Copy link

ေက်းဇူးတင္ပါတယ္ ခင္ဗ်ာ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment