Skip to content

Commit

Permalink
Merge pull request #112 from pieterdeschepper/master
Browse files Browse the repository at this point in the history
make sure a custom seperator can also be used instead of wrapping in <span> tags
  • Loading branch information
tushuhei authored Jan 21, 2020
2 parents 0155184 + 1f46714 commit 87d9b81
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 14 additions & 5 deletions budou/budou.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""Budou: an automatic organizer tool for beautiful line breaking in CJK
Usage:
budou [--segmenter=<seg>] [--language=<lang>] [--classname=<class>] [--inlinestyle] [--wbr] [<source>]
budou [--segmenter=<seg>] [--language=<lang>] [--separator=<separator>] [--classname=<class>] [--inlinestyle] [--wbr] [<source>]
budou -h | --help
budou -v | --version
Expand All @@ -31,6 +31,9 @@
--language=<language> Language the source in.
--separator=<separator> Custom separator instead of SPAN tags, when used
classname and inlinestyle are ignored
--classname=<classname> Class name for output SPAN tags. Use
comma-separated value to specify multiple classes.
Expand Down Expand Up @@ -74,10 +77,16 @@ def main():
inlinestyle=args['--inlinestyle'],
wbr=args['--wbr'],
)
html_code = result['html_code']
if not isinstance(html_code, str):
html_code = html_code.encode('utf-8')
print(html_code)

if args['--separator']:
output = result['chunks'].separator_serialize(args['--separator'])
else:
output = result['html_code']

if not isinstance(output, str):
output = output.encode('utf-8')
print(output)

sys.exit()

def parse(source, segmenter='nlapi', language=None, max_length=None,
Expand Down
11 changes: 11 additions & 0 deletions budou/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,14 @@ def wbr_serialize(self):
))
return result

def separator_serialize(self, separator):
"""Returns concatenated chunks with a custom separator in between.
Returns:
The organized string with custom separator (str)
"""
result = []
for chunk in self:
result.append(chunk.word)
return separator.join(result)

0 comments on commit 87d9b81

Please sign in to comment.