mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
html string option
This commit is contained in:
@@ -545,6 +545,7 @@ stringOpOptions = [
|
|||||||
("lexcode","code-like lexer"),
|
("lexcode","code-like lexer"),
|
||||||
("lexmixed","mixture of text and code (code between $...$)"),
|
("lexmixed","mixture of text and code (code between $...$)"),
|
||||||
("to_devanagari","from GF Devanagari transliteration to unicode"),
|
("to_devanagari","from GF Devanagari transliteration to unicode"),
|
||||||
|
("to_html","wrap in a html file with linebreaks"),
|
||||||
("to_thai","from GF Thai transliteration to unicode"),
|
("to_thai","from GF Thai transliteration to unicode"),
|
||||||
("to_utf8","encode to utf8"),
|
("to_utf8","encode to utf8"),
|
||||||
("unlextext","text-like unlexer"),
|
("unlextext","text-like unlexer"),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import GF.Text.Transliterations
|
|||||||
import GF.Text.UTF8
|
import GF.Text.UTF8
|
||||||
|
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
import Data.List (intersperse)
|
||||||
|
|
||||||
-- lexers and unlexers - they work on space-separated word strings
|
-- lexers and unlexers - they work on space-separated word strings
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ stringOp name = case name of
|
|||||||
"unlexcode" -> Just $ appUnlexer unlexCode
|
"unlexcode" -> Just $ appUnlexer unlexCode
|
||||||
"unlexmixed" -> Just $ appUnlexer unlexMixed
|
"unlexmixed" -> Just $ appUnlexer unlexMixed
|
||||||
"unwords" -> Just $ appUnlexer unwords
|
"unwords" -> Just $ appUnlexer unwords
|
||||||
|
"to_html" -> Just wrapHTML
|
||||||
"to_utf8" -> Just encodeUTF8
|
"to_utf8" -> Just encodeUTF8
|
||||||
"from_utf8" -> Just decodeUTF8
|
"from_utf8" -> Just decodeUTF8
|
||||||
_ -> transliterate name
|
_ -> transliterate name
|
||||||
@@ -30,6 +32,10 @@ appLexer f = unwords . filter (not . null) . f
|
|||||||
appUnlexer :: ([String] -> String) -> String -> String
|
appUnlexer :: ([String] -> String) -> String -> String
|
||||||
appUnlexer f = unlines . map (f . words) . lines
|
appUnlexer f = unlines . map (f . words) . lines
|
||||||
|
|
||||||
|
wrapHTML :: String -> String
|
||||||
|
wrapHTML = unlines . tag . intersperse "<br>" . lines where
|
||||||
|
tag ss = "<html>":"<body>" : ss ++ ["</body>","</html>"]
|
||||||
|
|
||||||
lexText :: String -> [String]
|
lexText :: String -> [String]
|
||||||
lexText s = case s of
|
lexText s = case s of
|
||||||
c:cs | isPunct c -> [c] : lexText cs
|
c:cs | isPunct c -> [c] : lexText cs
|
||||||
|
|||||||
Reference in New Issue
Block a user