@@ -13,7 +13,7 @@ module Hledger.Web.Widget.AddForm
13
13
14
14
import Control.Monad.State.Strict (evalStateT )
15
15
import Data.Bifunctor (first )
16
- import Data.List (dropWhileEnd , nub , sort , unfoldr )
16
+ import Data.List (dropWhileEnd , intercalate , nub , sort , unfoldr )
17
17
import Data.Maybe (isJust )
18
18
#if !(MIN_VERSION_base(4,13,0))
19
19
import Data.Semigroup ((<>) )
@@ -73,10 +73,6 @@ addForm j today = identifyForm "add" $ \extra -> do
73
73
-- bindings used in add-form.hamlet
74
74
let descriptions = sort $ nub $ tdescription <$> jtxns j
75
75
journals = fst <$> jfiles j
76
- listToJsonArray :: [Text ] -> Markup
77
- listToJsonArray = preEscapedString . escapeJSSpecialChars . show . toJSON
78
- where
79
- escapeJSSpecialChars = regexReplaceCI " </script>" " <\\ /script>" -- #236
80
76
81
77
pure (validateTransaction dateRes descRes postRes, $ (widgetFile " add-form" ))
82
78
@@ -98,6 +94,28 @@ addForm j today = identifyForm "add" $ \extra -> do
98
94
, fieldEnctype = UrlEncoded
99
95
}
100
96
97
+ -- Used in add-form.hamlet
98
+ toBloodhoundJson :: [Text ] -> Markup
99
+ toBloodhoundJson ts =
100
+ -- This used to work, but since 1.16, it seems like something changed.
101
+ -- toJSON ("a"::Text) gives String "a" instead of "a", etc.
102
+ -- preEscapedString . escapeJSSpecialChars . show . toJSON
103
+ preEscapedString $ concat [
104
+ " [" ,
105
+ intercalate " ," $ map (
106
+ (" {\" value\" :" ++ ).
107
+ (++ " }" ).
108
+ escapeJSSpecialChars .
109
+ drop 7 . -- "String "
110
+ show .
111
+ toJSON
112
+ ) ts,
113
+ " ]"
114
+ ]
115
+ where
116
+ -- avoid https://github.com/simonmichael/hledger/issues/236
117
+ escapeJSSpecialChars = regexReplaceCI " </script>" " <\\ /script>"
118
+
101
119
validateTransaction ::
102
120
FormResult Day
103
121
-> FormResult Text
0 commit comments