packages feed

seonbi 0.1.0 → 0.1.1

raw patch · 4 files changed

+79/−9 lines, 4 files

Files

CHANGES.md view
@@ -1,6 +1,18 @@ Seonbi changelog ================ +Version 0.1.1+-------------++Released on October 7, 2019.++ -  Added the `embed-dictionary` flag to the Cabal package.+ -  Fixed a bug that *Standard Korean Language Dictionary* had not been+    included in executables if `flag(static)` is turned on.  [[#1]]++[#1]: https://github.com/dahlia/seonbi/issues/1++ Version 0.1.0 ------------- 
README.md view
@@ -3,6 +3,8 @@  [![][releases-badge]][releases] [![][hackage-badge]][hackage] [![][dockerhub-badge]][dockerhub] [![][ci-status-badge]][ci] +(TL;DR: See the [demo web app].)+ Seonbi (선비) is is an HTML preprocessor that makes typographic adjustments to an HTML so that the result uses accurate punctuations according to the modern Korean orthography.@@ -45,6 +47,7 @@ [dockerhub-badge]: https://img.shields.io/microbadger/image-size/dahlia/seonbi [ci]: https://github.com/dahlia/seonbi/actions [ci-status-badge]: https://github.com/dahlia/seonbi/workflows/build/badge.svg+[demo web app]: https://dahlia.github.io/seonbi/ [SmartyPants]: https://daringfireball.net/projects/smartypants/ [Korean mixed script]: https://en.wikipedia.org/wiki/Korean_mixed_script @@ -121,7 +124,7 @@      HTTP/1.1 200 OK     Content-Type: application/json-    Server: Seonbi/0.1.0+    Server: Seonbi/0.1.1      {       "success": true,@@ -133,7 +136,18 @@      seonbi-api -o https://example.com +To learn more parameters interactively, try the [demo web app].+ [CORS]: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS+++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 on [Hackage].   License
seonbi.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: d4a46f2e66dbb5471c1056a03c8d90108abbc383e058d391e679715309b07a2c+-- hash: 8339f3a5d2f79ad22fe631feda924f87bd347414e314cf9e312d062f4c481d92  name:           seonbi-version:        0.1.0+version:        0.1.1 synopsis:       SmartyPants for Korean language description:    Please see the README.md on GitHub at <https://github.com/dahlia/seonbi>. category:       Text@@ -43,6 +43,11 @@     , text     , zip >=1.1 && <1.3 +flag embed-dictionary+  description: Embed dictionary rather than load from file+  manual: True+  default: False+ flag iconv   description: Use iconv   manual: True@@ -92,6 +97,10 @@     ghc-options: -Wall -fprint-explicit-kinds -optP-Wno-nonportable-include-path   else     ghc-options: -Wall -fprint-explicit-kinds+  if flag(static) || flag(embed-dictionary)+    cpp-options: -DEMBED_DICTIONARY+  else+    cpp-options: -DNO_EMBED_DICTIONARY   default-language: Haskell2010  executable seonbi
src/Text/Seonbi/Facade.hs view
@@ -1,7 +1,11 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-}+#ifdef EMBED_DICTIONARY+{-# LANGUAGE TemplateHaskell #-}+#endif -- | Provides higher-level APIs.  Read 'transformHtmlText' function first, -- and then see also 'Configuration' type. module Text.Seonbi.Facade@@ -32,13 +36,23 @@  import Data.ByteString.Lazy import Data.Csv+#ifdef EMBED_DICTIONARY+import Data.FileEmbed+#endif import Data.Map.Strict import Data.Set import Data.Text import qualified Data.Text.Lazy as LT-import System.FilePath ((</>))+import System.FilePath+    ( (</>)+#ifdef EMBED_DICTIONARY+    , takeDirectory+#endif+    ) +#ifndef EMBED_DICTIONARY import Paths_seonbi (getDataDir)+#endif import Text.Seonbi.Hanja import Text.Seonbi.Html import Text.Seonbi.Punctuation@@ -49,7 +63,7 @@ -- -- - 'ko_KR' -- - 'ko_KP'-data Monad m => Configuration m a = Configuration +data Monad m => Configuration m a = Configuration     { -- | An optional debugging logger to print its internal AST.       debugLogger :: Maybe (HtmlEntity -> m a)       -- | Whether to take and result in XHTML instead of HTML.@@ -91,10 +105,10 @@     = CurvedQuotes     -- | East Asian guillemets (@〈@: U+3008, @〉@: U+3009, @《@: U+300A, @》@:     -- U+300B), which are used by North Korean orthography.-    | Guillemets +    | Guillemets     -- | Use English-style curved quotes (@‘@: U+2018, @’@: U+2019) for single     -- quotes, and HTML @\<q\>@ tags for double quotes.-    | CurvedSingleQuotesWithQ +    | CurvedSingleQuotesWithQ     deriving (Enum, Eq, Generic, Read, Show)  -- | An option to transform folk-citing quotes (e.g., @\<\<한겨레\>\>@) into@@ -300,12 +314,20 @@ readDictionaryFile :: FilePath -> IO HanjaDictionary readDictionaryFile path = do     byteString <- Data.ByteString.Lazy.readFile path+    case readDictionaryByteString byteString of+        Right dic -> return dic+        Left err -> fail err++-- | Reads a dictionary from TSV bytes.+readDictionaryByteString :: Data.ByteString.Lazy.ByteString+                         -> Either String HanjaDictionary+readDictionaryByteString byteString =     case decodeWith tsvDecodeOptions NoHeader byteString of-        Right vector -> return $ Prelude.foldl+        Right vector -> Right $ Prelude.foldl             (\ d (DictionaryPair k v) -> Trie.insert k v d)             Trie.empty             (GHC.Exts.toList vector)-        Left err -> fail err+        Left err -> Left err   where     tsvDecodeOptions :: DecodeOptions     tsvDecodeOptions = defaultDecodeOptions@@ -324,9 +346,22 @@ -- | Loads [Standard Korean Language Dictionary](https://stdict.korean.go.kr/) -- (標準國語大辭典) data. southKoreanDictionary :: IO HanjaDictionary+#ifdef EMBED_DICTIONARY+southKoreanDictionary =+    case readDictionaryByteString bytes of+        Right dic -> return dic+        Left err -> fail err+  where+    bytes :: Data.ByteString.Lazy.ByteString+    bytes = Data.ByteString.Lazy.fromStrict $ $(embedFile $+        takeDirectory __FILE__ </> ".." </> ".." </> ".." </> "data" </>+        "ko-kr-stdict.tsv")++#else southKoreanDictionary = do     dataDir <- getDataDir     readDictionaryFile (dataDir </> "ko-kr-stdict.tsv")+#endif  data DictionaryPair = DictionaryPair !Text !Text deriving (Generic, Show)