• Stars
    star
    118
  • Rank 289,127 (Top 6 %)
  • Language
    Haskell
  • License
    GNU Lesser Genera...
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

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

Repository Details

SmartyPants for Korean language

Seonbi: SmartyPants for Korean language

(TL;DR: See the demo web app.)

Seonbi (선비) is an HTML preprocessor that makes typographic adjustments to an HTML so that the result uses accurate punctuations according to the modern Korean orthography. (It's similar to what SmartyPants does for text written in English.)

It also transforms ko-Kore text (國漢文混用; Korean mixed script) into ko-Hang text (한글전용; Hangul-only script).

Seonbi provides a Haskell library, a CLI, and an HTTP API; any of them can perform the following transformations:

  • All hanja words (e.g., 漢字) into corresponding hangul-only words (e.g., 한자)
  • Straight quotes and apostrophes (" & ') into curly quotes HTML entities (, , , & )
  • Three consecutive periods (... or 。。。) into an ellipsis entity ()
  • Classical (Chinese-style) stops ( & ) into modern (English-style) stops (. & ,)
  • Pairs of less-than and greater-than inequality symbols (< & >) into pairs of proper angle quotes ( & )
  • Pairs of two consecutive inequality symbols (<< & >>) into pairs of proper double angle quotes ( & )
  • A hyphen (-) or hangul vowel eu () surrounded by spaces, or two/three consecutive hyphens (-- or ---) into a proper em dash ()
  • A less-than inequality symbol followed by a hyphen or an equality symbol (<-, <=) into arrows to the left (, )
  • A hyphen or an equality symbol followed by a greater-than inequality symbol (->, =>) into arrows to the right (, )
  • A hyphen or an equality symbol wrapped by inequality symbols (<->, <=>) into bi-directional arrows (, )

Each transformations can be partially turned on and off, and some transformations have many options.

All transformations work with both plain texts and rich text tree. In a similar way to SmartyPants, it does not modify characters within several sensitive HTML elements like <pre>/<code>/<script>/<kbd>. Chinese/Japanese stops or hanzi/kanji characters inside elements with lang="zh"/lang="ja"1 are never transformed.

End-user apps

Technically, Seonbi is basically exposed as a software component, which is also known as API (application programming interface), to be used as a module of other softwares.

However, as these official interfaces are not for humans but machines, it's not easy to use for end-users whom haven't experienced software programming. For such end-users, here's the list of end-user apps:

Installation

Seonbi provides official executable binaries for Linux (x86_64), macOS, and Windows (64-bit). You can download them from the releases page.

If you prefer Scoop on Windows use the Seonbi official bucket:

scoop bucket add seonbi https://github.com/dahlia/seonbi.git
scoop install seonbi

It is also distributed as a Docker image:

$ echo '訓民正音' | docker run -i dahlia/seonbi:latest seonbi
훈민정음

If you'd like to use it on GitHub Actions there is action dahlia/seonbi/setup:

- uses: dahlia/seonbi/setup
- run: seonbi -o output.html input.html

If you want to use it as a Haskell library install the seonbi package using Stack or Cabal.

CLI

The seonbi command basically takes the input HTML as standard input, and then transforms it into the output HTML as standard output:

seonbi < input.html > output.html

You could pass a filename as an argument instead (and it is - by default):

seonbi input.html > output.html

There is -o/--output option as well:

seonbi -o output.html input.html

Although it automatically detects text encoding of the input file, you could explicitly specify -e/--encoding:

seonbi -e euc-kr -o output.html input.html

Although there are several style options, e.g., -q/--quote, -c/--cite, -r/--render-hanja, in most cases, giving -p/--preset is enough:

echo '平壤 冷麵' | seonbi -p ko-kr  # 평양 냉면
echo '平壤 冷麵' | seonbi -p ko-kp  # 평양 랭면

Read -h/--help for details:

seonbi --help

HTTP API

The seonbi-api command starts an HTTP server that takes POST requests with an HTML source with transformation options, and responds with a transformed result HTML. You can decide a hostname and a port number with -H/--host and -p/--port options:

seonbi-api -H 0.0.0.0 -p 3800

The following is an example request:

POST / HTTP/1.1
Content-Type: application/json
Host: localhost:3800

{
  "preset": "ko-kr",
  "contentType": "text/html",
  "sourceHtml": "<p>하늘과 바람과 별과 詩</p>"
}

The HTTP API server would respond like this:

HTTP/1.1 200 OK
Content-Type: application/json
Server: Seonbi/0.3.0

{
  "success": true,
  "contentType": "text/html",
  "resultHtml": "<p>하늘과 바람과 별과 시</p>"
}

If a web app needs to use the HTTP API server, CORS should be configured through --allow-origin/-o option:

seonbi-api -o https://example.com

To learn more about parameters interactively, try the demo web app.

Haskell API

All functions and types lie inside Text.Seonbi module and its submodules. The highest-level API is Text.Seonbi.Facade module.

See also the API docs or Hackage.

Deno API

There is a simple client library for Deno as well. See also the scripts/deno/ directory.

License

Distributed under LGPL 2.1 or later.

Etymology

Seonbi (선비) means a classical scholar during Joseon periods (14c–19c). Today there's a meme that calls a person who feels morally superior or has elitism seonbi in the Korean internet. So seonbi and smarty pants have some things in common.

Footnotes

  1. Technically, only Korean contents and language-unspecified elements are transformed. Elements having lang attribute with language tags referring to any Korean language are treated as Korean contents, e.g., ko, ko-Hang, kor-KP, kor-Kore.

More Repositories

1

awesome-sqlalchemy

A curated list of awesome tools for SQLAlchemy
Python
2,664
star
2

wikidata

Wikidata client library for Python
Python
322
star
3

iterfzf

Pythonic interface to fzf, a CLI fuzzy finder
Python
151
star
4

sqlalchemy-imageattach

SQLAlchemy extension for attaching images to entities.
Python
116
star
5

cjk-compsci-terms

CJK computer science terms comparison / 中日韓電腦科學術語對照 / 日中韓のコンピュータ科学の用語対照 / 한·중·일 전산학 용어 대조
Python
99
star
6

lisphp

Lisphp is a Lisp dialect written in PHP.
PHP
80
star
7

iso4217

ISO 4217 currency data package for Python
Python
59
star
8

muzei-pixiv

Enjoy kawaii artworks of Pixiv through Muzei!
Java
52
star
9

sider

ABANDONED. Sider is a persistent object library based on Redis.
Python
39
star
10

logging-spinner

Display spinners (in CLI) through Python standard logging
Python
34
star
11

nvimrc

My Neovim configuration. Supports macOS and Linux.
Vim Script
33
star
12

sentry-heroku

Run Sentry on Heroku for free
Python
32
star
13

wsgi-oauth2

Simple WSGI middleware for OAuth 2.0
Python
22
star
14

jikji

Small static site generator toolkit
TypeScript
20
star
15

aitertools

Well-tested utility functions dealing with async iterables
TypeScript
17
star
16

github-distutils

This project is abandoned. Don't use this anymore!
Python
15
star
17

json-hash

JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes
TypeScript
14
star
18

blog

Hong Minhee's blog
Python
13
star
19

macos-terminal-profiles

My profiles for macOS Terminal.app
12
star
20

naver-translate

ABANDONED. Haskell interface to Naver Translate
Haskell
11
star
21

homebrew-jetbrains-eap

JetBrains EAP Casks for Homebrew Cask
Ruby
9
star
22

plastic

Plastic is a Python web framework built on top of Werkzeug.
Python
8
star
23

nicovideo-translator

Nico Nico Douga (ニコニコ動画) Comment Translator
Haskell
7
star
24

tofu

A very impractical small programming language.
6
star
25

resume

Hong Minhee's résumé
Makefile
6
star
26

phunctional

Functional programming in PHP 5.2.x
PHP
6
star
27

submark

Extract a part from CommonMark/Markdown docs
Haskell
6
star
28

sphinx-fakeinv

Generate fake Intersphinx inventory
Python
5
star
29

unihan-json

JSON data files parsed from the Unicode Han Database (Unihan)
Python
5
star
30

monthday

Date without year
Python
5
star
31

pghstore

This repository is abandoned and the upstream is moved to @heroku →
Python
5
star
32

dojang

A cross-platform dotfiles manager
Haskell
5
star
33

bencodex-haskell

Bencodex reader/writer for Haskell
Haskell
5
star
34

dc-feed

PHP
4
star
35

iso639-1

Type-safe ISO 639-1 language code (a.k.a. two-letter codes) for TypeScript
TypeScript
4
star
36

actions

Small Useful GitHub Actions
JavaScript
4
star
37

travis-auto-rebuilder

Automatically retry failed builds
Python
4
star
38

web_deno_test

Run your tests on Deno and web browsers at a time
TypeScript
4
star
39

dahlia.github.io

Hong Minhee's website
HTML
3
star
40

bencodex-php

Bencodex reader/writer for PHP
PHP
3
star
41

gitter-slack

One-way relay from Gitter to Slack
Rust
3
star
42

writings

洪民憙雜記
TypeScript
3
star
43

encodingcontext

A bad idea about the default encoding
Python
3
star
44

feed-translator

ABANDONED. Translate syndication feeds.
Haskell
3
star
45

last.fm-memories

Lists music you had listened before from Last.fm (or Libre.fm)
Python
3
star
46

wikipedia-kana-romanizer

Wikipedia kana romanizer
JavaScript
3
star
47

mediawiki-rc-mastodon-bot

Relay RecentChanges from a MediaWiki site to a Mastodon account
TypeScript
3
star
48

checkmate

Generate checklists relevant to a given patch
Haskell
3
star
49

shinjitai-table

The table between shinjitai (新字体) and kyūjitai (舊字體).
Python
3
star
50

markdown-gfm-admonition

An extension of Python Markdown that enables the admonition syntax of GFM
Python
3
star
51

web-lessc

A simple HTTP API of LESS compiler
JavaScript
2
star
52

jsr-badge

A badge generator for JSR (JavaScript Registry)
TypeScript
2
star
53

fedi-badge

A badge generator for ActivityPub-enabled social media platforms, i.e., fediverse
TypeScript
2
star
54

wiki.hongminhee.org

洪兔雜記
TypeScript
2
star
55

naver-premium-contents-feed

네이버 프리미엄 콘텐츠 RSS 피드
TypeScript
1
star
56

jld

JSON-LD CLI tools
TypeScript
1
star
57

narabi

A simple Pythonic asynchronous interface to inter-process pub/sub
Python
1
star
58

python-1.5.2-docker

Run Python 1.5.2 using Docker
1
star
59

misc

Nothing special
1
star
60

html-charset

Determine character encoding of HTML documents/fragments
Haskell
1
star
61

foss-license-texts-esm

F/OSS License Texts as ESM
JavaScript
1
star
62

opensearch-descs

Hong Minhee's Collection of OpenSearch Descriptions
JavaScript
1
star
63

lazylist

Proxy list to a list-returning function
Python
1
star
64

dotfiles

Hong Minhee's dotfiles
Shell
1
star
65

localtunnel

A simple wrapper around the local tunneling services
TypeScript
1
star