Skip to content

Commit

Permalink
Add Typography module
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirlogachev committed May 4, 2024
1 parent a29d260 commit 514be92
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 12 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ Heavily borrows from [culori](https://culorijs.org/).

## Release Plan:

- rename repo

- Modules:

- Typography
- review code
- write docstrings
- check typos with grammarly
- demonstrate in the example app
- any tests
- InlineStyle
- review code
- write docstrings
- check typos with grammarly
- demonstrate in the example app
- any tests
- ExtraColor
- review code
- write docstrings
- check typos with grammarly
- demonstrate in the example app
- add cool palettes
- deal with negative css values, display the output
- maybe add Element.Color to the ADT?
- definite write a lot of test cases, and render the string output
- Culori (not exposed)
- review code
- consider splitting to modules as in the original
- Find more reusable code in the old apps

- Each Module:

- review code
- write docstrings
- check typos with grammarly
- demonstrate in the example app
- any tests

- Module
125 changes: 125 additions & 0 deletions src/Typography.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
module Typography exposing (nbsp, preparedText)

import Element exposing (..)
import Set exposing (Set)


{-| A helper to avoid typographic mistakes.
1. Split string into lines
2. Glue last 2 words in a line together (if line consists of 3 and more)
3. Replace spaces after specific words with nbsp
4. Glue lines back together
Note: Ideally it should be stored in both clean and processed forms in database.
Note: We may even come up with a separate elm package, carefully ported from js.
-}
preparedText : String -> Element msg
preparedText x =
String.lines x
|> List.map processLine
|> String.join "\n"
|> text


processLine : String -> String
processLine =
String.words
>> List.foldr
(\word tail ->
if Set.member (String.toLower word) dictionary then
word ++ nbsp ++ tail

else if tail == "" then
word

else
word ++ " " ++ tail
)
""


nbsp : String
nbsp =
"\u{00A0}"


dictionary : Set String
dictionary =
[ -- punctuation
"-"
, ""
, "+"

-- english
, "a"
, "about"
, "an"
, "and"
, "any"
, "are"
, "as"
, "at"
, "au"
, "be"
, "bi"
, "but"
, "by"
, "can"
, "de"
, "do"
, "et"
, "fit"
, "for"
, "from"
, "give"
, "go"
, "going"
, "had"
, "he"
, "i"
, "if"
, "in"
, "is"
, "it"
, "just"
, "know"
, "la"
, "let"
, "made"
, "may"
, "me"
, "my"
, "no"
, "not"
, "of"
, "on"
, "or"
, "part"
, "real"
, "see"
, "seek"
, "sent"
, "so"
, "than"
, "that"
, "the"
, "them"
, "there"
, "this"
, "to"
, "up"
, "upon"
, "watch"
, "wd"
, "we"
, "what"
, "whether"
, "which"
, "who"
, "why"
, "will"
, "with"
]
|> Set.fromList

0 comments on commit 514be92

Please sign in to comment.