Skip to content

Implement encode in PureScript #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions staging/src/TryPureScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ exports.setInnerHTML = function(html) {
};
};

exports.encode = function(text) {
return text
.replace('<', '&lt;')
.replace('>', '&gt;')
.replace('&', '&amp;')
.replace('"', '&quot;');
};

exports.withConsoleImpl = function(f) {
return function() {
var oldLog = console.log;
Expand Down
9 changes: 8 additions & 1 deletion staging/src/TryPureScript.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ module TryPureScript
import Prelude
import Data.Foldable (class Foldable, foldMap)
import Data.String (joinWith)
import Data.String.Common (replace)
import Data.String.Pattern (Pattern(..), Replacement(..))
import Effect (Effect)

foreign import setInnerHTML :: String -> Effect Unit

foreign import encode :: String -> String
encode :: String -> String
encode =
replace (Pattern "<") (Replacement "&lt;")
<<< replace (Pattern ">") (Replacement "&gt;")
<<< replace (Pattern "&") (Replacement "&amp;")
<<< replace (Pattern "\"") (Replacement "&quot;")

foreign import withConsoleImpl
:: forall a
Expand Down