• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    Haskell
  • License
    GNU Lesser Genera...
  • Created over 5 years ago
  • Updated 2 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

fedify

ActivityPub server framework in TypeScript
TypeScript
512
star
3

logtape

Simple logging library with zero dependencies for Deno, Node.js, Bun, browsers, and edge functions
TypeScript
501
star
4

wikidata

Wikidata client library for Python
Python
333
star
5

hollo

Federated single-user microblogging software
TypeScript
194
star
6

iterfzf

Pythonic interface to fzf, a CLI fuzzy finder
Python
161
star
7

cjk-compsci-terms

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

sqlalchemy-imageattach

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

lisphp

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

iso4217

ISO 4217 currency data package for Python
Python
59
star
11

muzei-pixiv

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

fedi-badge

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

sider

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

logging-spinner

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

nvimrc

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

sentry-heroku

Run Sentry on Heroku for free
Python
32
star
17

deno-task-hooks

A simple way to run Deno tasks as Git hooks
TypeScript
25
star
18

homebrew-jetbrains-eap

JetBrains EAP Casks for Homebrew Cask
Ruby
23
star
19

wsgi-oauth2

Simple WSGI middleware for OAuth 2.0
Python
22
star
20

jikji

Small static site generator toolkit
TypeScript
21
star
21

aitertools

Well-tested utility functions dealing with async iterables
TypeScript
18
star
22

github-distutils

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

json-hash

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

blog

Hong Minhee's blog
Python
13
star
25

logtape-otel

LogTape OpenTelemetry Sink
TypeScript
12
star
26

macos-terminal-profiles

My profiles for macOS Terminal.app
12
star
27

naver-translate

ABANDONED. Haskell interface to Naver Translate
Haskell
11
star
28

microblog

A simple federated microblog example using Fedify for educational purpose
TypeScript
10
star
29

plastic

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

unihan-json

JSON data files parsed from the Unicode Han Database (Unihan)
Python
7
star
31

nicovideo-translator

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

dojang

A cross-platform dotfiles manager
Haskell
7
star
33

markdown-gfm-admonition

An extension of Python Markdown that enables the admonition syntax of GFM
Python
7
star
34

markdown-it-mention

A markdown-it plugin that parses and renders Mastodon-style @mentions
TypeScript
7
star
35

tofu

A very impractical small programming language.
6
star
36

resume

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

phunctional

Functional programming in PHP 5.2.x
PHP
6
star
38

submark

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

fedify-h3

Integrate Fedify with h3
TypeScript
6
star
40

fedikit

A prototype of Fedify written in Python (codenamed FediKit)
Python
5
star
41

iso639-1

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

sphinx-fakeinv

Generate fake Intersphinx inventory
Python
5
star
43

monthday

Date without year
Python
5
star
44

pghstore

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

actions

Small Useful GitHub Actions
JavaScript
5
star
46

bencodex-haskell

Bencodex reader/writer for Haskell
Haskell
5
star
47

fedify-microblog-tutorial-ja

『自分だけのフェディバースのマイクロブログを作ろう!』のAsciiDocのソースコード
Shell
5
star
48

x-forwarded-fetch

A middleware for fetch() behind a reverse proxy with X-Forwarded-* headers
TypeScript
5
star
49

dc-feed

PHP
4
star
50

mediawiki-rc-mastodon-bot

Relay RecentChanges from a MediaWiki site to a Mastodon account
TypeScript
4
star
51

shinjitai-table

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

travis-auto-rebuilder

Automatically retry failed builds
Python
4
star
53

web_deno_test

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

fedify-redis

Redis drivers for Fedify
TypeScript
4
star
55

fedify-amqp

AMQP/RabbitMQ driver for Fedify
TypeScript
3
star
56

dahlia.github.io

Hong Minhee's website
HTML
3
star
57

bencodex-php

Bencodex reader/writer for PHP
PHP
3
star
58

gitter-slack

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

writings

洪民憙雜記
TypeScript
3
star
60

encodingcontext

A bad idea about the default encoding
Python
3
star
61

feed-translator

ABANDONED. Translate syndication feeds.
Haskell
3
star
62

wikipedia-kana-romanizer

Wikipedia kana romanizer
JavaScript
3
star
63

last.fm-memories

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

checkmate

Generate checklists relevant to a given patch
Haskell
3
star
65

jsr-badge

A badge generator for JSR (JavaScript Registry)
TypeScript
3
star
66

fedify-express

Integrate Fedify with Express
TypeScript
2
star
67

markdown-it-jsr-ref

A markdown-it plugin that turns backtick-enclosed symbols into links to JSR API references
TypeScript
2
star
68

narabi

A simple Pythonic asynchronous interface to inter-process pub/sub
Python
2
star
69

web-lessc

A simple HTTP API of LESS compiler
JavaScript
2
star
70

localtunnel

A simple wrapper around the local tunneling services
TypeScript
2
star
71

wiki.hongminhee.org

洪兔雜記
TypeScript
2
star
72

fedify-postgres

PostgreSQL drivers for Fedify
TypeScript
1
star
73

naver-premium-contents-feed

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

jld

JSON-LD CLI tools
TypeScript
1
star
75

python-1.5.2-docker

Run Python 1.5.2 using Docker
1
star
76

misc

Nothing special
1
star
77

opensearch-descs

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

foss-license-texts-esm

F/OSS License Texts as ESM
JavaScript
1
star
79

lazylist

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

dotfiles

Hong Minhee's dotfiles
Shell
1
star
81

html-charset

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

markdown-it-hashtag

A markdown-it plugin that parses and renders Mastodon-style #hashtags
TypeScript
1
star
83

fedify-queue-benchmarks

Benchmarks for Fedify's outbox queue
TypeScript
1
star