-
-
Save sixtyfive/e8dd69ba02a43be6fded715223086e23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_translit_markup(input) | |
span_open = false | |
output = '' | |
input.each_char do |c| | |
unless c.match /\s/ | |
if c.match /\p{Arabic}/ | |
output += "</span>" if span_open | |
span_open = false | |
else | |
unless span_open | |
output += "<span class='translit'>" | |
span_open = true | |
end | |
end | |
end | |
output += c | |
end | |
return output | |
end | |
# » string = "حروف العربية und dann العربة مرة ثانية und nochmal deutsch وأخيرا العربية" | |
# » puts add_translit_markup(string) | |
# حروف العربية <span class='translit'>und dann </span>العربة مرة ثانية <span class='translit'>und nochmal deutsch </span>وأخيرا العربية | |
# => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment