• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    JavaScript
  • Created over 12 years ago
  • Updated over 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Better CJK text wrapping

Macho.js - Better CJK text wrapping V0.31

Text wrapping in Chinese or other CJK languages are not as easy as in latin based languages. For example, you may have seen this in a block of text or h1, h2 title:

不 costdown 才會不浪費,才能得到好東
西。

This is quite ugly. It should be re-wrapped to this:

不 costdown 才會不浪費,才能得到
好東西。

In order to do this, we can use <span style="display: inline-block;"> to tag the last three Chinese characters to achieve the goal. This is exactly what Macho.js brings to you, in flavor of jQuery's way.

Macho.js is a jQuery plugin. The interface is simple:

$('p').macho();

Then Macho.js will scan through all the tags you passed to it and do the wrapping.

Wrap rules and examples

The following examples will only wrap when the width is too small to hold the entire strings.

Last Chinese characters will be grouped in 3 (can be customized in option)

寫起來以後自己參考。
-->
寫起來以後自
己參考。      

Long English word will be wrapped, no need to wrap Chinese with it

我喜歡使用photoshop.
-->
我喜歡使用
photoshop.    

Short English word will be treated as Chinese characters

這個plugin真的是太棒了ya!
-->
這個plugin真的是太
棒了ya!

Emotion symbols will be wrapped as whole

這亂七八糟◢▆▅▄▃崩╰(〒皿〒)╯潰▃▄▅▇◣
-->
這亂七八糟
◢▆▅▄▃崩╰(〒皿〒)╯潰▃▄▅▇◣

Usage and API

/* include macho.js in your html header */

$('p').macho();    // Wrapped text default grouped to 3 CJK characters

$('p').macho({
  'length':5,      // Wrapped text grouped to 5 CJK characters
  'inline': false  // Generate <span class="macho"> instead of
});                // <span class="macho" style="display: inline-block;">

Installation and compatibilities

Simply include macho.js into your html file. Remember to set your html encoding to utf8.

Bugs and todos

  • Custom span and class name?

  • If there is other tags like <strong> <em>, macho.js won't process them

Author

Felix Ren-Chyan Chern 陳仁乾(idryman)

License

BSD license

More Repositories

1

opic

Fast serialization framework for C
C
225
star
2

toml-mode.el

Emacs Mojor mode for editing TOML files
Emacs Lisp
49
star
3

FCAnimationFactory

An objective-c library for generating `CAKeyFrameAnimation` with custom timing functions including cubic, quadratic, or even bouncing functions.
Objective-C
42
star
4

hash_bench

Popular hash table implementation benchmarks
M4
27
star
5

atomic_patterns

Common atomic patterns
C
19
star
6

autoconf-tutorials

Tutorials on autoconf
C
17
star
7

Hadoop-CombineFileInputFormat

Example implementation of hadoop CombineFileInputFormat
Java
14
star
8

org-math

math learning notes in orgmode
Emacs Lisp
13
star
9

smart-window.el

A emacs package improves Emacs window system with window moving commands (not moving focus between windows) and window splitting commands that takes addtional options to edit a file or a buffer.
Emacs Lisp
13
star
10

UIWebTouch

A demo iPad app that can handle touch event in UIWebView
JavaScript
5
star
11

dryman.github.com

Blogging as a hacker, using Octopress
HTML
5
star
12

node-jquery-mobile

A simple mobile interface for notification message
JavaScript
4
star
13

Taiwan-Typhoon-iOS

Sample code for showing PTA data on iOS
Objective-C
4
star
14

HashMergeJoin

Explore hash join algorithms
C++
3
star
15

hadoop-fieldformat

Structured input, output, and writable classes for map-reduce
Java
3
star
16

CWB-API

Reverse engineering CWB API
Perl
3
star
17

QuickDict

A cocoa menu app which you can search system dictionary immediately
Objective-C
2
star
18

lldb-block-helper

lldb block helper written in python
Python
2
star
19

hadoop-book

hadoop 中文教學
2
star
20

CangJieX

Yet another cangjie input method for osx
Objective-C
2
star
21

felix-emacs-config

Felix's minimal emacs config
Emacs Lisp
2
star
22

homework-image-clustering

image clustering using k-means algorithm
C
2
star
23

Hadoop-TextWithPath

Obtain path information in Text object.
Java
1
star
24

edamamecached

A concurrent alternative to memcached
C
1
star
25

NPB-CG-benchmark

Benchmark apple gcd and OpenMP on conjugate gradient algorithm
C
1
star
26

IISApp

My IIS project
JavaScript
1
star
27

Pendulum-

The simulator of double pendulums gives an idea of a chaotic system
Objective-C
1
star
28

hive-probabilistic-utils

Probabilistic data structures and algorithms for hive
Java
1
star
29

note-mojolicious

Notes on Mojolicous
1
star
30

File-Monitor-Lite

observe file changes, creation, deletion using regexp
Perl
1
star
31

SWCApp

JavaScript
1
star
32

Perl-Lingua-ZH-MMSEG

Mandarin Chinese phrase segmentation (perl implementation of MMSEG)
Perl
1
star